From d241edf0442145828c45415c265b4d5cec302582 Mon Sep 17 00:00:00 2001 From: pgrondek Date: Sat, 20 Feb 2021 03:20:06 +0100 Subject: [PATCH] Add automations for air purifier --- .../air-purifier/automations.yaml.j2 | 63 +++++++++++++++++-- .../air-purifier/input_select.yaml.j2 | 1 + automations/vars/main.yaml | 4 +- 3 files changed, 62 insertions(+), 6 deletions(-) diff --git a/automations/templates/air-purifier/automations.yaml.j2 b/automations/templates/air-purifier/automations.yaml.j2 index 73cadc1..d2876ed 100644 --- a/automations/templates/air-purifier/automations.yaml.j2 +++ b/automations/templates/air-purifier/automations.yaml.j2 @@ -1,6 +1,7 @@ {% for airPurifier in airPurifiers %} # {{ airPurifier.name }} - alias: '[{{ airPurifier.name }} Air Purifier] mode change' + id: {{ airPurifier.componentId }}_mode_change trigger: entity_id: input_select.{{ airPurifier.componentId }}_mode platform: state @@ -9,8 +10,8 @@ data_template: entity_id: {{ airPurifier.entityId }} speed: {{ '\'{{ states.input_select.' + airPurifier.componentId + '_mode.state }}\'' }} - id: {{ airPurifier.componentId }}_mode_change - alias: '[{{ airPurifier.name }} Air Purifier] mode changed' + id: {{ airPurifier.componentId }}_mode_changed trigger: platform: state entity_id: {{ airPurifier.entityId }} @@ -19,8 +20,8 @@ entity_id: input_select.{{ airPurifier.componentId }}_mode data_template: option: {{ '\'{{ states.' + airPurifier.entityId + '.attributes.speed }}\'' }} - id: {{ airPurifier.componentId }}_mode_changed - alias: '[{{ airPurifier.name }} Air Purifier] favorite level change' + id: {{ airPurifier.entityId }}_favorite_level trigger: entity_id: input_number.{{ airPurifier.componentId }}_favorite_level platform: state @@ -29,8 +30,8 @@ data_template: entity_id: {{ airPurifier.entityId }} level: {{ '\'{{ states.input_number.' + airPurifier.componentId + '_favorite_level.state | int }}\'' }} - id: {{ airPurifier.entityId }}_favorite_level - alias: '[{{ airPurifier.name }} Air Purifier] favorite level changed' + id: {{ airPurifier.entityId }}_favorite_level_changed trigger: platform: state entity_id: {{ airPurifier.entityId }} @@ -39,6 +40,58 @@ entity_id: input_number.{{ airPurifier.componentId }}_favorite_level data_template: value: {{ '\'{{ states.' + airPurifier.entityId + '.attributes.favorite_level }}\'' }} - id: {{ airPurifier.entityId }}_favorite_level_changed - +{% if airPurifier.supports_fan_level %} +- alias: '[{{ airPurifier.name }} Air Purifier] fan level changed' + id: {{ airPurifier.entityId }}_fan_level_changed + trigger: + platform: state + entity_id: {{ airPurifier.entityId }} + action: + service: input_number.set_value + entity_id: input_number.{{ airPurifier.componentId }}_fan_level + data_template: + value: {{ '\'{{ states.' + airPurifier.entityId + '.attributes.fan_level }}\'' }} +- alias: '[{{ airPurifier.name }} Air Purifier] fan level change' + id: {{ airPurifier.entityId }}_fan_level_change + trigger: + entity_id: input_number.{{ airPurifier.componentId }}_fan_level + platform: state + action: + service: xiaomi_miio.fan_set_fan_level + data_template: + entity_id: {{ airPurifier.entityId }} + level: {{ '\'{{ states.input_number.' + airPurifier.componentId + '_fan_level.state | int }}\'' }} +{% endif %} +- alias: '[{{ airPurifier.name }} Purifier] increase fan speed' + id: {{ airPurifier.entityId }}_fan_speed_increase + trigger: + - platform: numeric_state + entity_id: sensor.{{ airPurifier.componentId }}_air_quality_pm25 + above: '15' + for: 1m + action: + - service: fan.set_speed + data: + speed: Favorite + entity_id: fan.{{ airPurifier.componentId }} + - service: xiaomi_miio.fan_set_favorite_level + data_template: + entity_id: {{ airPurifier.entityId }} + level: {{ '\'{{ states.input_number.' + airPurifier.componentId + '_favorite_level.state | int + 1 }}\'' }} +- alias: '[{{ airPurifier.name }} Purifier] decrease fan speed' + id: {{ airPurifier.entityId }}_fan_speed_decrease + trigger: + - platform: numeric_state + entity_id: sensor.{{ airPurifier.componentId }}_air_quality_pm25 + below: '10' + for: 1m + action: + - service: fan.set_speed + data: + speed: Favorite + entity_id: fan.{{ airPurifier.componentId }} + - service: xiaomi_miio.fan_set_favorite_level + data_template: + entity_id: {{ airPurifier.entityId }} + level: {{ '\'{{ states.input_number.' + airPurifier.componentId + '_favorite_level.state | int - 1 }}\'' }} {% endfor %} \ No newline at end of file diff --git a/automations/templates/air-purifier/input_select.yaml.j2 b/automations/templates/air-purifier/input_select.yaml.j2 index f512534..98ed0eb 100644 --- a/automations/templates/air-purifier/input_select.yaml.j2 +++ b/automations/templates/air-purifier/input_select.yaml.j2 @@ -6,5 +6,6 @@ - Auto - Silent - Favorite + - Fan icon: "mdi:animation-outline" {% endfor %} \ No newline at end of file diff --git a/automations/vars/main.yaml b/automations/vars/main.yaml index 7ffeea5..e3a4b77 100644 --- a/automations/vars/main.yaml +++ b/automations/vars/main.yaml @@ -47,8 +47,10 @@ airPurifiers: name: Living Room ip: 192.168.60.6 token: 66e56ff414f359b371b2d0b86e3d37d4 + supports_fan_level: true - entityId: fan.bedroom_air_purifier componentId: bedroom_air_purifier name: Bedroom ip: 192.168.60.5 - token: a32c6e74647ac03ad79afaa590b5203c \ No newline at end of file + token: a32c6e74647ac03ad79afaa590b5203c + supports_fan_level: false