# Loads default set of integrations. Do not remove.
default_config:

# Load frontend themes from the themes folder
frontend:
themes: !include_dir_merge_named themes

# Text to speech
tts:
- platform: google_translate

# Includes
automation: !include automations.yaml
script: !include scripts.yaml
scene: !include scenes.yaml
group: !include groups.yaml
climate: !include climate.yaml #Uses HACS intigation

# Networking
http:
server_host: 172.24.2.4
ip_ban_enabled: true
login_attempts_threshold: 5
use_x_forwarded_for: true
cors_allowed_origins:
- https://nextcloud.urmel.duckdns.org
trusted_proxies:
- 172.24.2.5

# Google Home intigration
google_assistant:
project_id: home-assistant-94153
service_account: !include SERVICE_ACCOUNT.json
report_state: true
expose_by_default: false # Nach https://community.home-assistant.io/t/exclude-entities-from-google-assistant-home/290325
entity_config:
cover.sys_niklas_cover_1_warper:
expose: true
name: Rolladen Garten
cover.niklas_cover_2:
expose: true
name: Rolladen Hof
climate.niklas_thermostat_group:
expose: true
name: Heizung Niklas
climate.kichen_thermostat_1:
expose: true
name: Küche Heizung
climate.livingroom_thermostat_group:
expose: true
name: Wohnzimmer Heizung
cover.storage_cover_1:
expose: true
name: Rolladen altes Schlafzimmer
input_boolean.sys_niklas_pc_power:
expose: true
name: Niklas Pc

# Sensors
binary_sensor:
- platform: tod
name: sys_morning_sensor
after: "06:00"
before: "13:00"
- platform: template
sensors:
sys_niklas_pc_power_threshold:
friendly_name: "Niklas Pc power threshold"
value_template: "{{ states.sensor.niklas_plug_1_pc_power.state | replace(',','') | float < 80 }}"

sensor:
- platform: template
sensors:
sys_niklas_alarm_clock_future:
friendly_name: "Wecker zukunft"
value_template: >
{# Unix Date [+1d] + (clock h + clock min in unix) - unix now > in H and min #}
{% if as_timestamp(now().date()) +
(state_attr('input_datetime.sys_niklas_alarm_time', "hour")*60 +
state_attr('input_datetime.sys_niklas_alarm_time', "minute"))*60
>= as_timestamp(now().date()) + (now().hour*60 + now().minute)*60 %}
{# Today #}
{{ (((as_timestamp(now().date())+(state_attr('input_datetime.sys_niklas_alarm_time', "hour")*60 +
state_attr('input_datetime.sys_niklas_alarm_time', "minute"))*60)-as_timestamp(now()))//3600) | round}} Stunden {{ ((((as_timestamp(now().date() + timedelta(days=1))+(state_attr('input_datetime.sys_niklas_alarm_time', "hour")*60 +
state_attr('input_datetime.sys_niklas_alarm_time', "minute"))*60)-as_timestamp(now()))%3600)//60) | round}} Minuten
{% else %}
{# Next Day #}
{{ (((as_timestamp(now().date() + timedelta(days=1))+(state_attr('input_datetime.sys_niklas_alarm_time', "hour")*60 +
state_attr('input_datetime.sys_niklas_alarm_time', "minute"))*60)-as_timestamp(now()))//3600) | round}} Stunden {{ ((((as_timestamp(now().date() + timedelta(days=1))+(state_attr('input_datetime.sys_niklas_alarm_time', "hour")*60 +
state_attr('input_datetime.sys_niklas_alarm_time', "minute"))*60)-as_timestamp(now()))%3600)//60) | round}} Minuten
{% endif %}

shell_command:
ap_wintergarden_light_on: ssh -i /config/ssh/ap_one -o 'StrictHostKeyChecking=no' someone@172.24.0.4 "sed -i 's/mgmt\.led_enabled=false/mgmt.led_enabled=true/' /etc/persistent/cfg/mgmt"
ap_wintergarden_light_off: ssh -i /config/ssh/ap_one -o 'StrictHostKeyChecking=no' someone@172.24.0.4 "sed -i 's/mgmt\.led_enabled=true/mgmt.led_enabled=false/' /etc/persistent/cfg/mgmt"
ap_hallway_light_on: ssh -i /config/ssh/ap_one -o 'StrictHostKeyChecking=no' someone@172.24.0.4 "sed -i 's/mgmt\.led_enabled=false/mgmt.led_enabled=true/' /etc/persistent/cfg/mgmt"
ap_hallway_light_off: ssh -i /config/ssh/ap_one -o 'StrictHostKeyChecking=no' someone@172.24.0.4 "sed -i 's/mgmt\.led_enabled=true/mgmt.led_enabled=false/' /etc/persistent/cfg/mgmt"

light:
- platform: template
lights:
hallway_ap_light:
turn_on:
action: shell_command.ap_hallway_light_on
turn_off:
action: shell_command.ap_hallway_light_off
winergarden_ap_light:
turn_on:
action: shell_command.ap_wintergarden_light_on
turn_off:
action: shell_command.ap_wintergarden_light_off

# Covers with scripts
cover:
- platform: template
covers:
sys_niklas_cover_1_warper:
unique_id: sys_niklas_cover_1_warper
position_template: "{{states.cover.niklas_cover_1.attributes.current_position}}"
close_cover:
- condition: state
entity_id: binary_sensor.niklas_window_1_contact
state: "off"
- service: cover.close_cover
target:
entity_id: cover.niklas_cover_1
open_cover:
- service: cover.open_cover
target:
entity_id: cover.niklas_cover_1
stop_cover:
service: cover.stop_cover
target:
entity_id: cover.niklas_cover_1
set_cover_position:
- condition: or
conditions:
- condition: template
value_template: >
{% set current_position = state_attr('cover.niklas_cover_1', 'current_position') %}
{{ position | float > current_position | float }}
- condition: state
entity_id: binary_sensor.niklas_window_1_contact
state: "off"
- service: cover.set_cover_position
target:
entity_id: cover.niklas_cover_1
data:
position: "{{position}}"

#Spotcast HACS intigration
spotcast:
sp_dc: !secret sp_dc
sp_key: !secret sp_key
country: DE #optional, added in 3.6.24