From c3777c971afb8a6a0c90042b393d2d2c55b36676 Mon Sep 17 00:00:00 2001 From: pgrondek Date: Wed, 4 Nov 2020 01:31:46 +0100 Subject: [PATCH] Add air purifiers --- automations/files/air-purifier.yaml | 41 -------------------- automations/tasks/main.yaml | 6 ++- automations/templates/air-purifier.yaml.j2 | 44 ++++++++++++++++++++++ automations/vars/main.yaml | 9 ++++- 4 files changed, 57 insertions(+), 43 deletions(-) delete mode 100644 automations/files/air-purifier.yaml create mode 100644 automations/templates/air-purifier.yaml.j2 diff --git a/automations/files/air-purifier.yaml b/automations/files/air-purifier.yaml deleted file mode 100644 index f7df76c..0000000 --- a/automations/files/air-purifier.yaml +++ /dev/null @@ -1,41 +0,0 @@ -- alias: '[Living Room Air Purifier] mode change' - trigger: - entity_id: input_select.xiaomi_airpurifier_mode - platform: state - action: - service: fan.set_speed - data_template: - entity_id: fan.xiaomi_miio_device - speed: '{{ states.input_select.xiaomi_airpurifier_mode.state }}' - id: xiaomi_airpurifier_mode_change -- alias: '[Living Room Air Purifier] mode changed' - trigger: - platform: state - entity_id: fan.xiaomi_miio_device - action: - service: input_select.select_option - entity_id: input_select.xiaomi_airpurifier_mode - data_template: - option: '{{ states.fan.xiaomi_miio_device.attributes.speed }}' - id: xiaomi_airpurifier_mode_changed -- alias: '[Living Room Air Purifier] favorite level change' - trigger: - entity_id: input_number.xiaomi_airpurifier_favorite_level - platform: state - action: - service: xiaomi_miio.fan_set_favorite_level - data_template: - entity_id: fan.xiaomi_miio_device - level: '{{ states.input_number.xiaomi_airpurifier_favorite_level.state | int - }}' - id: xiaomi_airpurifier_favorite_level -- alias: '[Living Room Air Purifier] favorite level changed' - trigger: - platform: state - entity_id: fan.xiaomi_miio_device - action: - service: input_number.set_value - entity_id: input_number.xiaomi_airpurifier_favorite_level - data_template: - value: '{{ states.fan.xiaomi_miio_device.attributes.favorite_level }}' - id: xiaomi_airpurifier_favorite_level_changed \ No newline at end of file diff --git a/automations/tasks/main.yaml b/automations/tasks/main.yaml index e228c0b..df4b8dd 100644 --- a/automations/tasks/main.yaml +++ b/automations/tasks/main.yaml @@ -2,4 +2,8 @@ - name: Build lights automations template: src: lights.yaml.j2 - dest: build/lights.yaml \ No newline at end of file + dest: build/lights.yaml +- name: Build air purifiers automations + template: + src: air-purifier.yaml.j2 + dest: build/air-purifier.yaml \ No newline at end of file diff --git a/automations/templates/air-purifier.yaml.j2 b/automations/templates/air-purifier.yaml.j2 new file mode 100644 index 0000000..73cadc1 --- /dev/null +++ b/automations/templates/air-purifier.yaml.j2 @@ -0,0 +1,44 @@ +{% for airPurifier in airPurifiers %} +# {{ airPurifier.name }} +- alias: '[{{ airPurifier.name }} Air Purifier] mode change' + trigger: + entity_id: input_select.{{ airPurifier.componentId }}_mode + platform: state + action: + service: fan.set_speed + 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' + trigger: + platform: state + entity_id: {{ airPurifier.entityId }} + action: + service: input_select.select_option + 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' + trigger: + entity_id: input_number.{{ airPurifier.componentId }}_favorite_level + platform: state + action: + service: xiaomi_miio.fan_set_favorite_level + 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' + trigger: + platform: state + entity_id: {{ airPurifier.entityId }} + action: + service: input_number.set_value + entity_id: input_number.{{ airPurifier.componentId }}_favorite_level + data_template: + value: {{ '\'{{ states.' + airPurifier.entityId + '.attributes.favorite_level }}\'' }} + id: {{ airPurifier.entityId }}_favorite_level_changed + +{% endfor %} \ No newline at end of file diff --git a/automations/vars/main.yaml b/automations/vars/main.yaml index 365ec9f..e368d6a 100644 --- a/automations/vars/main.yaml +++ b/automations/vars/main.yaml @@ -35,4 +35,11 @@ lights: - entityId: light.kitchen_13 name: Kitchen 13 - entityId: light.kitchen_14 - name: Kitchen 14 \ No newline at end of file + name: Kitchen 14 +airPurifiers: + - entityId: fan.xiaomi_miio_device + componentId: xiaomi_miio_device + name: Living Room + - entityId: fan.bedroom_air_purifier + componentId: bedroom_air_purifier + name: Bedroom \ No newline at end of file