From 42337b9fb57bdc2d0083b426385e9e55198121af Mon Sep 17 00:00:00 2001 From: CCOSTAN Date: Thu, 10 Nov 2016 18:26:44 +0000 Subject: [PATCH] Combiine a bunch of Automations. --- automation/detect_and_adjust_lights.yaml | 115 ++++++++++++++++++ ...urnon.yaml => sunrise_turnon_and_off.yaml} | 0 automation/time_5am_8am.yaml | 31 ----- automation/time_8am_8pm.yaml | 29 ----- automation/time_8pm_5am.yaml | 38 ------ automation/tv_time_off.yaml | 21 ---- .../{tv_time.yaml => tv_time_on_and_off.yaml} | 26 ++++ 7 files changed, 141 insertions(+), 119 deletions(-) create mode 100755 automation/detect_and_adjust_lights.yaml rename automation/{sunrise_turnon.yaml => sunrise_turnon_and_off.yaml} (100%) delete mode 100755 automation/time_5am_8am.yaml delete mode 100755 automation/time_8am_8pm.yaml delete mode 100755 automation/time_8pm_5am.yaml delete mode 100755 automation/tv_time_off.yaml rename automation/{tv_time.yaml => tv_time_on_and_off.yaml} (57%) diff --git a/automation/detect_and_adjust_lights.yaml b/automation/detect_and_adjust_lights.yaml new file mode 100755 index 00000000..4453273e --- /dev/null +++ b/automation/detect_and_adjust_lights.yaml @@ -0,0 +1,115 @@ +############################################################################## +### Detect when lights are turned on and adjust them accordingly based on time. +### Here is 5am to 8am +############################################################################## + +- alias: detect_light_between 5am and 8am + trigger: + - platform: event + event_type: state_changed + condition: + - condition: state + entity_id: group.family + state: home + - condition: time + after: '05:00:00' + - condition: time + before: '7:59:00' + - condition: template + value_template: "{{ trigger.event.data.entity_id.split('.')[0] == 'light' }}" + - condition: template + value_template: "{{ trigger.event.data.entity_id.split('_')[0] != 'light.tv' }}" + - condition: template + value_template: "{{ trigger.event.data.entity_id.split('_')[0] != 'light.couch' }}" + - condition: template + value_template: "{{ trigger.event.data.entity_id.split('_')[0] != 'light.outdoor' }}" + - condition: template + value_template: "{{ trigger.event.data.new_state.state == 'on' }}" + - condition: template + value_template: "{{ trigger.event.data.old_state.state == 'off' }}" +# - condition: template +# value_template: "{{ trigger.event.data.new_state.attributes.brightness|default(0)|int > 50 }}" + action: + - service: light.turn_on + data_template: + entity_id: "{{ trigger.event.data.entity_id }}" + brightness: 50 + +############################################################################## +### Detect when lights are turned on and adjust them accordingly based on time. +### Here is 8am to 8pm +############################################################################## + +- alias: detect_light_between 8am and 8pm + trigger: + - platform: event + event_type: state_changed + condition: + - condition: state + entity_id: group.family + state: home + - condition: time + after: '08:00:00' + - condition: time + before: '20:00:00' + - condition: template + value_template: "{{ trigger.event.data.entity_id.split('.')[0] == 'light' }}" + - condition: template + value_template: "{{ trigger.event.data.entity_id.split('_')[0] != 'light.tv' }}" + - condition: template + value_template: "{{ trigger.event.data.entity_id.split('_')[0] != 'light.couch' }}" + - condition: template + value_template: "{{ trigger.event.data.entity_id.split('_')[0] != 'light.outdoor' }}" + - condition: template + value_template: "{{ trigger.event.data.new_state.state == 'on' }}" + - condition: template + value_template: "{{ trigger.event.data.old_state.state == 'off' }}" + action: + - service: light.turn_on + data_template: + entity_id: "{{ trigger.event.data.entity_id }}" + brightness: 255 + +############################################################################## +### Detect when lights are turned on and adjust them accordingly based on time. +### Here is 8pm to 5am +############################################################################## + +- alias: detect_light_between 8pm and 5am + trigger: + - platform: event + event_type: state_changed + condition: + condition: and + conditions: + - condition: or + conditions: + - condition: time + after: '20:00:00' + - condition: time + before: '12:00:00' + - condition: state + entity_id: sun.sun + state: 'below_horizon' + - condition: state + entity_id: group.family + state: home + - condition: template + value_template: "{{ trigger.event.data.entity_id.split('.')[0] == 'light' }}" + - condition: template + value_template: "{{ trigger.event.data.entity_id.split('_')[0] != 'light.tv' }}" + - condition: template + value_template: "{{ trigger.event.data.entity_id.split('_')[0] != 'light.couch' }}" + - condition: template + value_template: "{{ trigger.event.data.entity_id.split('_')[0] != 'light.outdoor' }}" + - condition: template + value_template: "{{ trigger.event.data.new_state.state == 'on' }}" + - condition: template + value_template: "{{ trigger.event.data.old_state.state == 'off' }}" +# - condition: template +# value_template: "{{ trigger.event.data.new_state.attributes.brightness|default(0)|int > 20 }}" + action: + - service: light.turn_on + data_template: + entity_id: "{{ trigger.event.data.entity_id }}" + brightness: 20 \ No newline at end of file diff --git a/automation/sunrise_turnon.yaml b/automation/sunrise_turnon_and_off.yaml similarity index 100% rename from automation/sunrise_turnon.yaml rename to automation/sunrise_turnon_and_off.yaml diff --git a/automation/time_5am_8am.yaml b/automation/time_5am_8am.yaml deleted file mode 100755 index 90ed9b67..00000000 --- a/automation/time_5am_8am.yaml +++ /dev/null @@ -1,31 +0,0 @@ -- alias: detect_light_between 5am and 8am - trigger: - - platform: event - event_type: state_changed - condition: - - condition: state - entity_id: group.family - state: home - - condition: time - after: '05:00:00' - - condition: time - before: '7:59:00' - - condition: template - value_template: "{{ trigger.event.data.entity_id.split('.')[0] == 'light' }}" - - condition: template - value_template: "{{ trigger.event.data.entity_id.split('_')[0] != 'light.tv' }}" - - condition: template - value_template: "{{ trigger.event.data.entity_id.split('_')[0] != 'light.couch' }}" - - condition: template - value_template: "{{ trigger.event.data.entity_id.split('_')[0] != 'light.outdoor' }}" - - condition: template - value_template: "{{ trigger.event.data.new_state.state == 'on' }}" - - condition: template - value_template: "{{ trigger.event.data.old_state.state == 'off' }}" -# - condition: template -# value_template: "{{ trigger.event.data.new_state.attributes.brightness|default(0)|int > 50 }}" - action: - - service: light.turn_on - data_template: - entity_id: "{{ trigger.event.data.entity_id }}" - brightness: 50 \ No newline at end of file diff --git a/automation/time_8am_8pm.yaml b/automation/time_8am_8pm.yaml deleted file mode 100755 index 41875678..00000000 --- a/automation/time_8am_8pm.yaml +++ /dev/null @@ -1,29 +0,0 @@ -- alias: detect_light_between 8am and 8pm - trigger: - - platform: event - event_type: state_changed - condition: - - condition: state - entity_id: group.family - state: home - - condition: time - after: '08:00:00' - - condition: time - before: '20:00:00' - - condition: template - value_template: "{{ trigger.event.data.entity_id.split('.')[0] == 'light' }}" - - condition: template - value_template: "{{ trigger.event.data.entity_id.split('_')[0] != 'light.tv' }}" - - condition: template - value_template: "{{ trigger.event.data.entity_id.split('_')[0] != 'light.couch' }}" - - condition: template - value_template: "{{ trigger.event.data.entity_id.split('_')[0] != 'light.outdoor' }}" - - condition: template - value_template: "{{ trigger.event.data.new_state.state == 'on' }}" - - condition: template - value_template: "{{ trigger.event.data.old_state.state == 'off' }}" - action: - - service: light.turn_on - data_template: - entity_id: "{{ trigger.event.data.entity_id }}" - brightness: 255 \ No newline at end of file diff --git a/automation/time_8pm_5am.yaml b/automation/time_8pm_5am.yaml deleted file mode 100755 index f497985a..00000000 --- a/automation/time_8pm_5am.yaml +++ /dev/null @@ -1,38 +0,0 @@ -- alias: detect_light_between 8pm and 5am - trigger: - - platform: event - event_type: state_changed - condition: - condition: and - conditions: - - condition: or - conditions: - - condition: time - after: '20:00:00' - - condition: time - before: '12:00:00' - - condition: state - entity_id: sun.sun - state: 'below_horizon' - - condition: state - entity_id: group.family - state: home - - condition: template - value_template: "{{ trigger.event.data.entity_id.split('.')[0] == 'light' }}" - - condition: template - value_template: "{{ trigger.event.data.entity_id.split('_')[0] != 'light.tv' }}" - - condition: template - value_template: "{{ trigger.event.data.entity_id.split('_')[0] != 'light.couch' }}" - - condition: template - value_template: "{{ trigger.event.data.entity_id.split('_')[0] != 'light.outdoor' }}" - - condition: template - value_template: "{{ trigger.event.data.new_state.state == 'on' }}" - - condition: template - value_template: "{{ trigger.event.data.old_state.state == 'off' }}" -# - condition: template -# value_template: "{{ trigger.event.data.new_state.attributes.brightness|default(0)|int > 20 }}" - action: - - service: light.turn_on - data_template: - entity_id: "{{ trigger.event.data.entity_id }}" - brightness: 20 \ No newline at end of file diff --git a/automation/tv_time_off.yaml b/automation/tv_time_off.yaml deleted file mode 100755 index a5d93949..00000000 --- a/automation/tv_time_off.yaml +++ /dev/null @@ -1,21 +0,0 @@ -- alias: TV Time off - trigger: - - platform: state - entity_id: sensor.samsungtv - state: offline - - condition: - condition: and - conditions: - - condition: state - entity_id: sun.sun - state: 'below_horizon' - - condition: state - entity_id: input_boolean.guest_mode - state: 'off' - - action: - service: light.turn_off - entity_id: - - group.living_room - - group.living_room_accents \ No newline at end of file diff --git a/automation/tv_time.yaml b/automation/tv_time_on_and_off.yaml similarity index 57% rename from automation/tv_time.yaml rename to automation/tv_time_on_and_off.yaml index 41ab96bf..892c8d86 100755 --- a/automation/tv_time.yaml +++ b/automation/tv_time_on_and_off.yaml @@ -36,3 +36,29 @@ action: service: scene.turn_on entity_id: scene.living_room_tv_time + +###################################################################### +## Turn off the Living room lights when the TV is turned off. +###################################################################### + +- alias: TV Time off + trigger: + - platform: state + entity_id: sensor.samsungtv + state: offline + + condition: + condition: and + conditions: + - condition: state + entity_id: sun.sun + state: 'below_horizon' + - condition: state + entity_id: input_boolean.guest_mode + state: 'off' + + action: + service: light.turn_off + entity_id: + - group.living_room + - group.living_room_accents \ No newline at end of file