#sarah come home turn on rear lights
- alias: 'Sarah is home'
trigger:
platform: state
entity_id: group.all_devices
from: 'not_home'
to: 'home'
for:
minutes: 15
condition:
condition: or
conditions:
- condition: time
after: '17:00:00'
- condition: time
before: '08:00:00'
action:
service: switch.turn_on
entity_id: switch.outside
Midnight is the change point, so a time can’t be both after ‘17:00:00’ and before ‘08:00:00’.
For similar automations I’ve switched to using the sun condition, so that it tracks sunset and sunrise.
# sarah come home turn on rear lights
- alias: 'Sarah is home'
trigger:
platform: state
entity_id: group.all_devices
from: 'not_home'
to: 'home'
for:
minutes: 15
condition:
condition: sun
after: sunset
# Optional offset value
after_offset: "-1:00:00"
action:
service: switch.turn_on
entity_id: switch.outside
That will turn on switch.outside when the first member of group.all_devices has been home for 15 minutes, between an hour before sunset, to midnight. Unless you have another automation to turn it off, it’ll stay on until you manually turn it off.
I’m on mobile so I can’t give you the source code, but I would use the suns altitude angle in a template as the condition. Sunangle less than 0 degrees should do it.