diff --git a/automations/templates/air-purifier/automations.yaml.j2 b/automations/templates/air-purifier/automations.yaml.j2 index d2876ed..b8477b4 100644 --- a/automations/templates/air-purifier/automations.yaml.j2 +++ b/automations/templates/air-purifier/automations.yaml.j2 @@ -62,36 +62,58 @@ entity_id: {{ airPurifier.entityId }} level: {{ '\'{{ states.input_number.' + airPurifier.componentId + '_fan_level.state | int }}\'' }} {% endif %} -- alias: '[{{ airPurifier.name }} Purifier] increase fan speed' +- alias: '[{{ airPurifier.name }} Air 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 + above: '12' 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' + - repeat: + while: + - condition: numeric_state + entity_id: sensor.{{ airPurifier.componentId }}_air_quality_pm25 + above: '12' + sequence: + - service: xiaomi_miio.fan_set_favorite_level + data_template: + entity_id: {{ airPurifier.entityId }} + level: {{ '\"{{ state_attr(\'' + airPurifier.entityId + '\', \'favorite_level\') | int + 1 }}\"' }} + - service: input_number.set_value + entity_id: input_number.{{ airPurifier.componentId }}_favorite_level + data_template: + value: {{ '\'{{ states.' + airPurifier.entityId + '.attributes.favorite_level }}\'' }} + - delay: + minutes: 1 +- alias: '[{{ airPurifier.name }} Air 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 }}\'' }} + - repeat: + while: + - condition: numeric_state + entity_id: sensor.{{ airPurifier.componentId }}_air_quality_pm25 + below: '10' + sequence: + - service: xiaomi_miio.fan_set_favorite_level + data_template: + entity_id: {{ airPurifier.entityId }} + level: {{ '\"{{ state_attr(\'' + airPurifier.entityId + '\', \'favorite_level\') | int - 1 }}\"' }} + - service: input_number.set_value + entity_id: input_number.{{ airPurifier.componentId }}_favorite_level + data_template: + value: {{ '\'{{ states.' + airPurifier.entityId + '.attributes.favorite_level }}\'' }} + - delay: + minutes: 1 {% endfor %} \ No newline at end of file diff --git a/automations/vars/main.yaml b/automations/vars/main.yaml index 01ed5eb..0d137a8 100644 --- a/automations/vars/main.yaml +++ b/automations/vars/main.yaml @@ -17,7 +17,7 @@ lights: name: Couch lamp airPurifiers: - entityId: fan.xiaomi_miio_device - componentId: xiaomi_miio_device + componentId: xiaomi_airpurifier name: Living Room ip: 192.168.60.6 token: 66e56ff414f359b371b2d0b86e3d37d4