From 5809849cb2e9d92185be5aea9c360522a8a1bae6 Mon Sep 17 00:00:00 2001 From: Georgi Gardev Date: Sat, 25 Apr 2020 17:29:14 +0300 Subject: [PATCH] Refactor lighting tempearture automations --- .../advanced_dashboard/09_system.yaml | 9 ++- .../modules/lighting/temperature.yaml | 68 +++++++------------ 2 files changed, 30 insertions(+), 47 deletions(-) diff --git a/config/lovelace/advanced_dashboard/09_system.yaml b/config/lovelace/advanced_dashboard/09_system.yaml index 61c1ada..49f467f 100644 --- a/config/lovelace/advanced_dashboard/09_system.yaml +++ b/config/lovelace/advanced_dashboard/09_system.yaml @@ -49,17 +49,20 @@ cards: entities: - automation.lighting_turn_on_ceiling_lights_after_sunset - automation.lighting_turn_off_all_lights_after_sunrise - - automation.lighting_adjust_temperature_on_start - type: divider - - automation.lighting_living_room_adjust_temperature_based_on_time + - automation.lighting_temperature_adjust_on_start + - automation.lighting_temperature_adjust_based_on_time + - type: divider - automation.lighting_master_bedroom_toggle_lights_on_bedside_switch_single_click - - automation.lighting_master_bedroom_adjust_temperature_based_on_time + - type: divider - automation.lighting_kitchen_day_mode_motion_turn_lights_on_after_sunset - automation.lighting_kitchen_day_mode_motion_turn_lights_off - automation.lighting_kitchen_night_mode_motion_turn_lights_on - automation.lighting_kitchen_night_mode_motion_turn_lights_off + - type: divider - automation.lighting_hallway_night_mode_motion_turn_lights_on - automation.lighting_hallway_night_mode_motion_turn_lights_off + - type: divider - automation.lighting_sync_tasmota_states_on_start_up - type: divider diff --git a/config/packages/modules/lighting/temperature.yaml b/config/packages/modules/lighting/temperature.yaml index bc9ff72..03dae10 100644 --- a/config/packages/modules/lighting/temperature.yaml +++ b/config/packages/modules/lighting/temperature.yaml @@ -1,59 +1,39 @@ +script: + lighting_temperature_adjust: + alias: Lighting · Temperature · Adjust + sequence: + - condition: template + value_template: "{{ is_state(entity_id, 'on') }}" + - service: light.turn_on + data_template: + entity_id: "{{ entity_id }}" + color_temp: "{{ 400 if is_state('sun.sun', 'above_horizon') else 500 }}" + automation: - - alias: Lighting · Adjust temperature on start + - alias: Lighting · Temperature · Adjust on start trigger: platform: state entity_id: - light.living_room_main_lights - light.master_bedroom_main_lights + - light.hallway_entrance_lights to: "on" action: - - service: light.turn_on + - service: script.lighting_temperature_adjust data_template: entity_id: "{{ trigger.entity_id }}" - color_temp: >- - {% if is_state('sun.sun', 'above_horizon') %} - 350 - {% else %} - 500 - {% endif %} - - - alias: Lighting · Master bedroom · Adjust temperature based on time + - alias: Lighting · Temperature · Adjust based on time trigger: platform: state entity_id: sun.sun - condition: - condition: state - entity_id: light.master_bedroom_main_lights - state: "on" action: - - service: light.turn_on - entity_id: light.master_bedroom_main_lights - data_template: - color_temp: >- - - {% if is_state('sun.sun', 'above_horizon') %} - 350 - {% else %} - 500 - {% endif %} - - - alias: Lighting · Living room · Adjust temperature based on time - trigger: - platform: state - entity_id: sun.sun - condition: - condition: state - entity_id: light.living_room_main_lights - state: "on" - action: - - service: light.turn_on - entity_id: light.living_room_main_lights - data_template: - color_temp: >- - - {% if is_state('sun.sun', 'above_horizon') %} - 350 - {% else %} - 500 - {% endif %} + - service: script.lighting_temperature_adjust + data: + entity_id: light.master_bedroom_main_lights + - service: script.lighting_temperature_adjust + data: + entity_id: light.living_room_main_lights + - service: script.lighting_temperature_adjust + data: + entity_id: light.hallway_entrance_lights