I have setup where outdoor lights turn on at sunset and stay on unconditionally to 11pm. After 11pm, but before sunrise I want them to turn on only, if motion sensors report occupancy. Unfortunally, the following automation does not work, probably due to a collision in the condition statement.
alias: motion lights after permanent lights
trigger:
- platform: state
entity_id: binary_sensor.motion_sensor
from: 'off'
to: 'on'
condition:
- condition: sun
before: sunrise
- condition: time
after: '23:00:00'
action:
- service: light.turn_on
data: {}
entity_id: light.grp_outdoor_lights
mode: single
I guess - for HA - the time of triggering cannot be between 11pm and before sunrise, what could I do instead?
Guess I need to go that extra mile for the time from 11pm to midnight.
condition:
- condition: or
conditions:
- condition: time
after: '23:00:00'
# https://www.home-assistant.io/docs/scripts/conditions/#time-condition
# "If only after key is used, the condition will be true from the specified time until midnight."
- condition: and
conditions:
- condition: time
after: '00:00:00'
- condition: sun
before: sunrise
Note that if only before key is used, the condition will be truefrom midnight until sunrise/sunset. If only after key is used, the condition will be true from sunset/sunrise until midnight . Therefore, to cover time between sunset and sunrise one need to use after: sunset and before: sunrise as 2 separate conditions and combine them using or .