From 2fe908e16e817b56496994cc83ececa74a7958f3 Mon Sep 17 00:00:00 2001 From: CCOSTAN Date: Fri, 3 Feb 2017 01:28:54 +0000 Subject: [PATCH] Implimenting new light time code from Code by @JesseWebDotCom --- automation/detect_and_adjust_lights.yaml | 147 ++++--------------- automation/detect_and_adjust_lights.yaml.old | 127 ++++++++++++++++ 2 files changed, 159 insertions(+), 115 deletions(-) create mode 100755 automation/detect_and_adjust_lights.yaml.old diff --git a/automation/detect_and_adjust_lights.yaml b/automation/detect_and_adjust_lights.yaml index e32df041..6b9109ab 100755 --- a/automation/detect_and_adjust_lights.yaml +++ b/automation/detect_and_adjust_lights.yaml @@ -1,127 +1,44 @@ -############################################################################## -### 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 is not none }}" - - condition: template - value_template: "{{ trigger.event.data.entity_id is not none }}" - - 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.office' }}" - - 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 is not none }}" - - condition: template - value_template: "{{ trigger.event.data.entity_id is not none }}" - - 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.office' }}" - - 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 +- alias: detect_light_between 5am and 8am trigger: - platform: event event_type: state_changed + condition: - condition: and - conditions: - - condition: or - conditions: - - condition: time - after: '20:00:01' - - 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 is not none }}" - - condition: template - value_template: "{{ trigger.event.data.entity_id is not none }}" - - 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.office' }}" - - 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 }}" + - condition: state + entity_id: group.family + state: home + - condition: template + value_template: "{{ trigger.event.data is not none }}" + - condition: template + value_template: "{{ trigger.event.data.entity_id is not none }}" + - 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.office' }}" + - 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: 35 \ No newline at end of file + brightness: > + {% set hour=states("sensor.time").split(':')[0] | int %} + {%- if hour >= 5 or hour < 8 -%} + 50 + {%- elif hour >= 8 or hour <20 -%} + 255 + {%- else -%} + 35 + {%- endif %} + \ No newline at end of file diff --git a/automation/detect_and_adjust_lights.yaml.old b/automation/detect_and_adjust_lights.yaml.old new file mode 100755 index 00000000..e32df041 --- /dev/null +++ b/automation/detect_and_adjust_lights.yaml.old @@ -0,0 +1,127 @@ +############################################################################## +### 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 is not none }}" + - condition: template + value_template: "{{ trigger.event.data.entity_id is not none }}" + - 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.office' }}" + - 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 is not none }}" + - condition: template + value_template: "{{ trigger.event.data.entity_id is not none }}" + - 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.office' }}" + - 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:01' + - 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 is not none }}" + - condition: template + value_template: "{{ trigger.event.data.entity_id is not none }}" + - 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.office' }}" + - 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: 35 \ No newline at end of file