From b6a2fe33a57d5d04a9a9c870895061e0d5f68de0 Mon Sep 17 00:00:00 2001 From: pgrondek Date: Wed, 4 Nov 2020 00:55:41 +0100 Subject: [PATCH] Import automations to ansible --- automations/files/air-purifier.yaml | 41 ++++++++++++++++++++ automations/files/alarm-clock.yaml | 46 ++++++++++++++++++++++ automations/files/modes.yaml | 24 ++++++++++++ automations/tasks/main.yaml | 5 +++ automations/templates/lights.yaml.j2 | 58 ++++++++++++++++++++++++++++ automations/vars/main.yaml | 38 ++++++++++++++++++ home-assistant.yml | 4 ++ 7 files changed, 216 insertions(+) create mode 100644 automations/files/air-purifier.yaml create mode 100644 automations/files/alarm-clock.yaml create mode 100644 automations/files/modes.yaml create mode 100644 automations/tasks/main.yaml create mode 100644 automations/templates/lights.yaml.j2 create mode 100644 automations/vars/main.yaml create mode 100644 home-assistant.yml diff --git a/automations/files/air-purifier.yaml b/automations/files/air-purifier.yaml new file mode 100644 index 0000000..f7df76c --- /dev/null +++ b/automations/files/air-purifier.yaml @@ -0,0 +1,41 @@ +- 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/files/alarm-clock.yaml b/automations/files/alarm-clock.yaml new file mode 100644 index 0000000..b8882da --- /dev/null +++ b/automations/files/alarm-clock.yaml @@ -0,0 +1,46 @@ +- id: wakeup + alias: Wakeup automation + description: '' + trigger: + - platform: time + at: input_datetime.alarm + condition: + - condition: time + weekday: + - mon + - tue + - wed + - thu + - fri + action: + - service: light.turn_on + data: + kelvin: 2000 + brightness: 1 + entity_id: + - light.bedroom_1 + - light.bedroom_2 + - service: light.turn_on + data: + kelvin: 5300 + transition: 1800 + brightness: 255 + entity_id: + - light.bedroom_1 + - light.bedroom_2 + - delay: '10' + - service: media_player.volume_set + data: + volume_level: 0.1 + entity_id: media_player.bedroom_speaker + - delay: 0:30:00 + - service: media_player.volume_set + data: + volume_level: 0.6 + entity_id: media_player.bedroom_speaker + - service: media_player.play_media + data: + media_content_id: media-source://media_source/local/wake-the-f-up-samurai-we-have-a-city-to-burn.mp3 + media_content_type: music + entity_id: media_player.bedroom_speaker + mode: single \ No newline at end of file diff --git a/automations/files/modes.yaml b/automations/files/modes.yaml new file mode 100644 index 0000000..e13c456 --- /dev/null +++ b/automations/files/modes.yaml @@ -0,0 +1,24 @@ +- id: sleep_on + alias: Turn on sleep time + description: '' + trigger: + - platform: time + at: input_datetime.sleep_mode + condition: [] + action: + - service: input_boolean.turn_on + data: {} + entity_id: input_boolean.sleep_mode + mode: single +- id: sleep_off + alias: Turn off sleep time + description: '' + trigger: + - platform: time + at: input_datetime.day_mode + condition: [] + action: + - service: input_boolean.turn_off + data: {} + entity_id: input_boolean.sleep_mode + mode: single diff --git a/automations/tasks/main.yaml b/automations/tasks/main.yaml new file mode 100644 index 0000000..e228c0b --- /dev/null +++ b/automations/tasks/main.yaml @@ -0,0 +1,5 @@ +--- +- name: Build lights automations + template: + src: lights.yaml.j2 + dest: build/lights.yaml \ No newline at end of file diff --git a/automations/templates/lights.yaml.j2 b/automations/templates/lights.yaml.j2 new file mode 100644 index 0000000..b6cdd9b --- /dev/null +++ b/automations/templates/lights.yaml.j2 @@ -0,0 +1,58 @@ +{% for light in lights %} +# {{ light.name }} +- id: sleep_mode_{{ light.entityId }} + alias: '[Sleep-Mode] {{ light.name }}' + trigger: + - platform: state + entity_id: {{ light.entityId }} + to: 'on' + condition: + - condition: state + entity_id: input_boolean.sleep_mode + state: 'on' + action: + - service: light.turn_on + data: + kelvin: 2000 + entity_id: {{ light.entityId }} + mode: single +- id: sleep_on_{{ light.entityId }} + alias: '[Sleep-On] {{ light.name }}' + trigger: + - platform: time + at: input_datetime.sleep_mode + action: + - service: light.turn_on + data: + kelvin: 2000 + entity_id: {{ light.entityId }} + mode: single +- id: day_mode_{{ light.entityId }} + alias: '[Day-Mode] {{ light.name }}' + trigger: + - platform: time + at: input_datetime.day_mode + action: + - service: light.turn_on + data: + kelvin: 3200 + entity_id: {{ light.entityId }} + mode: single +- id: day_on_{{ light.entityId }} + alias: '[Day-On] {{ light.name }}' + trigger: + - platform: state + entity_id: {{ light.entityId }} + to: 'on' + condition: + - condition: state + entity_id: input_boolean.sleep_mode + state: 'off' + action: + - service: light.turn_on + data: + kelvin: 3200 + entity_id: {{ light.entityId }} + mode: single + +{% endfor %} diff --git a/automations/vars/main.yaml b/automations/vars/main.yaml new file mode 100644 index 0000000..365ec9f --- /dev/null +++ b/automations/vars/main.yaml @@ -0,0 +1,38 @@ +--- +# vars file for automations + +lights: + - entityId: light.tv_left + name: TV Left + - entityId: light.tv_middle + name: TV Middle + - entityId: light.tv_right + name: TV Right + - entityId: light.kitchen_01 + name: Kitchen 01 + - entityId: light.kitchen_02 + name: Kitchen 02 + - entityId: light.kitchen_03 + name: Kitchen 03 + - entityId: light.kitchen_04 + name: Kitchen 04 + - entityId: light.kitchen_05 + name: Kitchen 05 + - entityId: light.kitchen_06 + name: Kitchen 06 + - entityId: light.kitchen_07 + name: Kitchen 07 + - entityId: light.kitchen_08 + name: Kitchen 08 + - entityId: light.kitchen_09 + name: Kitchen 09 + - entityId: light.kitchen_10 + name: Kitchen 10 + - entityId: light.kitchen_11 + name: Kitchen 11 + - entityId: light.kitchen_12 + name: Kitchen 12 + - entityId: light.kitchen_13 + name: Kitchen 13 + - entityId: light.kitchen_14 + name: Kitchen 14 \ No newline at end of file diff --git a/home-assistant.yml b/home-assistant.yml new file mode 100644 index 0000000..91e3acf --- /dev/null +++ b/home-assistant.yml @@ -0,0 +1,4 @@ +--- +- hosts: localhost + roles: + - automations \ No newline at end of file