From 0524519a2b08a53a2802067ffa0d08bba89d3232 Mon Sep 17 00:00:00 2001 From: Przemek Grondek Date: Fri, 12 Nov 2021 02:56:26 +0100 Subject: [PATCH] Move bedroom lights automation logic to scripts --- .../automations/bedroom-bed-button.yaml | 35 +----- configuration/automations/bedroom-button.yaml | 8 +- configuration/automations/bedroom-motion.yaml | 25 +---- scripts/91.lights-bedroom.yaml | 102 ++++++++++++++++++ 4 files changed, 107 insertions(+), 63 deletions(-) create mode 100644 scripts/91.lights-bedroom.yaml diff --git a/configuration/automations/bedroom-bed-button.yaml b/configuration/automations/bedroom-bed-button.yaml index c71c23e..bd8321d 100644 --- a/configuration/automations/bedroom-bed-button.yaml +++ b/configuration/automations/bedroom-bed-button.yaml @@ -7,40 +7,7 @@ type: remote_button_short_press subtype: turn_off action: - - choose: - - conditions: - - condition: state - entity_id: light.bed_lamp - state: 'on' - sequence: - - service: light.turn_off - entity_id: light.bed_lamp - - service: light.turn_off - entity_id: light.bed_lightstrip - - service: light.turn_off - entity_id: light.bedroom_lights - - conditions: - - condition: state - entity_id: light.bed_lamp - state: 'off' - sequence: - - choose: - - conditions: - - condition: state - entity_id: input_select.home_mode - state: Night - sequence: - - service: light.turn_on - entity_id: light.bed_lamp - data: - brightness_pct: 10 - kelvin: 2000 - default: - - service: light.turn_on - entity_id: light.bed_lamp - data: - brightness_pct: 30 - kelvin: 3200 + - service: script.bedroom_bed_lamp_toggle - id: bedroom-bed-sleep alias: '[Bedroom] Bed Sleep' diff --git a/configuration/automations/bedroom-button.yaml b/configuration/automations/bedroom-button.yaml index 8255118..ca6fb33 100644 --- a/configuration/automations/bedroom-button.yaml +++ b/configuration/automations/bedroom-button.yaml @@ -8,9 +8,7 @@ type: remote_button_short_press subtype: turn_on action: - - service: light.turn_on - data: - entity_id: light.bedroom_lights + - service: script.bedroom_lights_on mode: single - id: bedroom-button-turn-off @@ -22,9 +20,7 @@ type: remote_button_short_press subtype: turn_off action: - - service: light.turn_off - data: - entity_id: light.bedroom_lights + - service: script.bedroom_all_lights_off mode: single - id: bedroom-button-dim-up diff --git a/configuration/automations/bedroom-motion.yaml b/configuration/automations/bedroom-motion.yaml index 7f8f591..37376c4 100644 --- a/configuration/automations/bedroom-motion.yaml +++ b/configuration/automations/bedroom-motion.yaml @@ -14,27 +14,7 @@ entity_id: input_select.home_mode state: Day action: - - choose: - - conditions: - - condition: state - entity_id: input_boolean.sleep_mode - state: 'on' - sequence: - - service: light.turn_on - entity_id: light.bedroom_lights - data: - brightness_pct: 60 - kelvin: 2000 - - conditions: - - condition: state - entity_id: input_boolean.sleep_mode - state: 'off' - sequence: - - service: light.turn_on - entity_id: light.bedroom_lights - data: - brightness_pct: 60 - kelvin: 3200 + - service: script.bedroom_lights_on - id: bedroom-motion-off alias: '[Bedroom] Motion Off' @@ -50,5 +30,4 @@ entity_id: alarm_control_panel.ha_alarm state: disarmed action: - - service: light.turn_off - entity_id: light.bedroom_lights + - service: script.bedroom_lights_off diff --git a/scripts/91.lights-bedroom.yaml b/scripts/91.lights-bedroom.yaml new file mode 100644 index 0000000..27359b0 --- /dev/null +++ b/scripts/91.lights-bedroom.yaml @@ -0,0 +1,102 @@ +bedroom_lights_toggle: + alias: '[Bedroom] Lights toggle' + sequence: + - choose: + - conditions: + - condition: state + entity_id: light.bedroom_lights + state: 'on' + sequence: + - service: script.bedroom_lights_off + - conditions: + - condition: state + entity_id: light.bedroom_lights + state: 'off' + sequence: + - service: script.bedroom_lights_on + +bedroom_lights_on: + alias: '[Bedroom] Lights on' + sequence: + - choose: + - conditions: + - condition: state + entity_id: input_boolean.sleep_mode + state: 'on' + sequence: + - service: light.turn_on + entity_id: light.bedroom_lights + data: + brightness_pct: 60 + kelvin: 2000 + - conditions: + - condition: state + entity_id: input_boolean.sleep_mode + state: 'off' + sequence: + - service: light.turn_on + entity_id: light.bedroom_lights + data: + brightness_pct: 60 + kelvin: 3200 + +bedroom_lights_off: + alias: '[Bedroom] Lights off' + sequence: + - service: light.turn_off + entity_id: light.bedroom_lights + +bedroom_all_lights_off: + alias: '[Bedroom] All lights off' + sequence: + - service: light.turn_off + entity_id: light.bedroom_lights + - service: light.turn_off + entity_id: light.bed_lightstrip + - service: light.turn_off + entity_id: light.bed_lamp + +bedroom_bed_lamp_toggle: + alias: '[Bedroom] Bed lamp toggle' + sequence: + - choose: + - conditions: + - condition: state + entity_id: light.bed_lamp + state: 'on' + sequence: + - service: script.bedroom_bed_lamp_off + - conditions: + - condition: state + entity_id: light.bed_lamp + state: 'off' + sequence: + - service: script.bedroom_bed_lamp_on + +bedroom_bed_lamp_on: + alias: '[Bedroom] Bed lamp on' + sequence: + - choose: + - conditions: + - condition: state + entity_id: input_select.home_mode + state: Night + sequence: + - service: light.turn_on + entity_id: light.bed_lamp + data: + brightness_pct: 10 + kelvin: 2000 + default: + - service: light.turn_on + entity_id: light.bed_lamp + data: + brightness_pct: 30 + kelvin: 3200 + +bedroom_bed_lamp_off: + alias: '[Bedroom] Bed lamp off' + sequence: + - condition: state + entity_id: light.bed_lamp + state: 'off'