Hi,
I’d like to know if there’s a better way (using a template) to amalgamate the following code into a single automation (using a data template?). Apologies if this is really easy - i’ve read through the templating docs but im struggling to understand because im thick
- alias: 'Downstairs lights on when motion detected (Day)'
initial_state: true
trigger:
- platform: state
entity_id: binary_sensor.downstairs_motion
to: 'on'
condition:
- condition: time
after: '06:00:00'
before: '17:00:00'
action:
- service: scene.turn_on
entity_id: scene.day__downstairs
- alias: 'Downstairs lights on when motion detected (Evening)'
initial_state: true
trigger:
- platform: state
entity_id: binary_sensor.downstairs_motion
to: 'on'
condition:
- condition: time
after: '17:00:00'
before: '22:00:00'
action:
- service: scene.turn_on
entity_id: scene.evening__downstairs
- alias: 'Downstairs lights on when motion detected (Night)'
initial_state: true
trigger:
- platform: state
entity_id: binary_sensor.downstairs_motion
to: 'on'
condition:
- condition: time
after: '22:00:00'
before: '06:00:00'
action:
- service: scene.turn_on
entity_id: scene.night__downstairs
Good catch! I didn’t think about the lack of overlap. Seeing that I also noticed that the condition for time = 06:00 wouldn’t work either.
I should have made the ‘>’ into ‘>=’:
{% if now().hour >= 6 and now().hour < 17 %}
scene.day__downstairs
{% elif now().hour >= 17 and now().hour < 22 %}
scene.evening__downstairs
{% else %}
scene.night__downstairs
{% endif %}
It will now start at 0600 (instead of 0700) for the “day” scene and it should do the same thing as your template for the 1700-1759 time frame but it makes the logic easier to read in my opinion.
it now better matches the original automations conditions.