Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save KrzysztofHajdamowicz/662a2ef02d54251dda665f8371c2e7d2 to your computer and use it in GitHub Desktop.
Save KrzysztofHajdamowicz/662a2ef02d54251dda665f8371c2e7d2 to your computer and use it in GitHub Desktop.
# binary sensor:
- platform: template
sensors:
people_at_home:
value_template: >-
{{ is_state('group.household', 'home')
or is_state('group.family', 'home') }}
should_i_ventilate_home:
friendly_name: "Czy wietrzyć w domu?"
value_template: >-
{% if states('sensor.airly_pm2_5')|float > 15 -%}
False
{%- else -%}
{{ states('sensor.air_purifier_salon_temp')|float > states('sensor.airly_temperature')|float }}
{%- endif %}
# automations
- &window_template
alias: When back home- Open Window, it's chilly outside
trigger:
platform: state
entity_id: binary_sensor.people_at_home
from: "off"
to: "on"
condition:
condition: and
conditions:
- condition: state
entity_id: group.sypialnia_windows
state: "off"
- condition: state
entity_id: binary_sensor.should_i_ventilate_home
state: "on"
action:
- &notify_template_open_window
service: notify.mobile_app_clt_l29
data:
title: Otwórz okno
message: 'Na dworze jest chłodno, można wietrzyć w domu'
data:
tag: 'home-ventillation'
-
<<: *notify_template_open_window
service: notify.mobile_app_oneplus_7pro
-
<<: *window_template
alias: Close Window, it's hot outside
trigger:
platform: state
entity_id: binary_sensor.should_i_ventilate_home
from: "on"
to: "off"
condition:
condition: and
conditions:
- condition: state
entity_id: binary_sensor.people_at_home
state: "on"
- condition: state
entity_id: group.sypialnia_windows
state: "on"
action:
- &notify_template_close_window
service: notify.mobile_app_clt_l29
data:
title: Zamknij okno
message: 'Na dworze jest gorąco, szkoda nagrzewać mury'
data:
tag: 'home-ventillation'
-
<<: *notify_template_close_window
service: notify.mobile_app_oneplus_7pro
- alias: Close Window, air quality is bad
trigger:
platform: numeric_state
entity_id: sensor.airly_pm2_5
above: 20
for:
minutes: 5
condition:
condition: and
conditions:
- condition: state
entity_id: binary_sensor.people_at_home
state: "on"
- condition: state
entity_id: group.sypialnia_windows
state: "on"
action:
- &notify_template_close_window_bad_air
service: notify.mobile_app_clt_l29
data:
title: Zamknij okno
message: 'Zła jakość powietrza na dworze'
data:
tag: 'home-ventillation'
-
<<: *notify_template_close_window_bad_air
service: notify.mobile_app_oneplus_7pro
-
<<: *window_template
alias: Empty flat with open windows
trigger:
platform: state
entity_id: binary_sensor.people_at_home
from: "on"
to: "off"
condition:
condition: and
conditions:
- condition: state
entity_id: group.sypialnia_windows
state: "on"
action:
- &notify_template_close_window_empty_flat
service: notify.mobile_app_clt_l29
data:
title: Zamknij okno
message: 'Mieszkanie jest puste a okno jest otwarte. Czy to bezpieczne?'
data:
tag: 'home-ventillation'
-
<<: *notify_template_close_window_empty_flat
service: notify.mobile_app_oneplus_7pro
# Automations- manage air purifier speed
# Try to automatically adjust fan speed
- alias: Turn off air purifier salon
trigger:
- platform: numeric_state
entity_id: sensor.airly_pm2_5
below: 15
for:
minutes: 10
- platform: state
entity_id: binary_sensor.people_at_home
to: "off"
condition:
condition: and
conditions:
- condition: state
entity_id: "fan.air_purifier_salon"
state: "on"
- condition: state
entity_id: "input_boolean.manage_air_purifier"
state: "on"
action:
service: fan.turn_off
entity_id: fan.air_purifier_salon
- alias: Turn on air purifier salon when somebody is back home
trigger:
platform: state
entity_id: binary_sensor.people_at_home
to: "on"
condition:
condition: and
conditions:
- condition: numeric_state
entity_id: sensor.airly_pm2_5
above: 15
- condition: state
entity_id: "input_boolean.manage_air_purifier"
state: "on"
action:
- service: fan.turn_on
entity_id: fan.air_purifier_salon
- alias: Turn on air purifier salon
trigger:
platform: numeric_state
entity_id: sensor.airly_pm2_5
above: 15
for:
minutes: 10
condition:
condition: and
conditions:
- condition: state
entity_id: "fan.air_purifier_salon"
state: "off"
- condition: state
entity_id: binary_sensor.people_at_home
state: "on"
- condition: state
entity_id: "input_boolean.manage_air_purifier"
state: "on"
action:
- service: fan.turn_on
entity_id: fan.air_purifier_salon
- service: input_select.select_option
entity_id: input_select.air_purifier_salon_mode
data:
option: Favorite
- alias: Autoadjust fan level in Salon during day
trigger:
platform: time_pattern
minutes: "/5"
condition:
condition: and
conditions:
- condition: time
after: "8:00"
before: "22:00"
- condition: state
entity_id: "fan.air_purifier_salon"
state: "on"
- condition: state
entity_id: "input_boolean.manage_air_purifier"
state: "on"
action:
- service: fan.set_speed
entity_id: fan.air_purifier_salon
data:
speed: favorite
- service: input_number.set_value
data_template:
entity_id: input_number.air_purifier_salon_favorite_level
value: >
{% if states("sensor.airly_pm2_5") | int > 60 %}
10
{% elif states("sensor.airly_pm2_5") | int > 30 %}
8
{% elif states("sensor.airly_pm2_5") | int > 20 %}
6
{% elif states("sensor.airly_pm2_5") | int > 15 %}
4
{% else %}
2
{% endif %}
- alias: Autoadjust fan level in Salon during night
trigger:
platform: time_pattern
minutes: "/5"
condition:
condition: and
conditions:
- condition: time
after: "22:00"
before: "8:00"
- condition: state
entity_id: "fan.air_purifier_salon"
state: "on"
- condition: state
entity_id: "input_boolean.manage_air_purifier"
state: "on"
action:
- service: fan.set_speed
entity_id: fan.air_purifier_salon
data:
speed: favorite
- service: input_number.set_value
data_template:
entity_id: input_number.air_purifier_salon_favorite_level
value: >
{% if states("sensor.airly_pm2_5") | int > 60 %}
6
{% elif states("sensor.airly_pm2_5") | int > 30 %}
5
{% elif states("sensor.airly_pm2_5") | int > 20 %}
4
{% elif states("sensor.airly_pm2_5") | int > 15 %}
3
{% else %}
2
{% endif %}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment