jriker1
(John)
1
I have the below automation, after 7:00PM light never turns on and input_boolean.vacation_mode shows “on”.
alias: Spare Room Lights Toggle
trigger:
- platform: homeassistant
event: start
- platform: time
at: '19:00:00'
- platform: time
at: '21:00:00'
condition:
- condition: state
entity_id: input_boolean.vacation_mode
state: "on"
action:
- service_template: >
{% if now().hour > 21 or now().hour < 19 %}
light.turn_off
{% else %}
light.turn_on
{% endif %}
entity_id: light.spare_room_light_switch_dimmer
NathanCu
(Nathan Curtis)
2
What happens to your logic if it’s triggering at exactly 7p? (which is exactly what the trigger would do)
The way I read it nothing happens because now.hour is currently equal to 19 and not greater than 21 or less than 19.
Change your operators to greater than or equal to 21 and less than or equal to 19
1 Like
tom_l
3
Agreed that is an issue, however I would expect that to always turn the light on (the else case) not off.
Still worth trying this:
action:
- service_template: >
{% if 19 >= now().hour >= 21 %}
light.turn_off
{% else %}
light.turn_on
{% endif %}
1 Like
123
(Taras)
4
alias: Spare Room Lights Toggle
trigger:
- platform: homeassistant
event: start
- platform: time
at:
- '19:00:00'
- '21:00:00'
condition:
- condition: state
entity_id: input_boolean.vacation_mode
state: "on"
action:
- service: "light.turn_{{ 'on' if now().hour in [19, 20] else 'off' }}"
target:
entity_id: light.spare_room_light_switch_dimmer
EDIT
Correction. Added missing period
2 Likes
jriker1
(John)
5
Thanks all. Liked this one. That said didn’t work but added in a period between “light” and turn" and that fixed it.
1 Like