Does the following condition ensure that whatever automation it is attached to will only run if binary_sensor.allow_automation
is true and the time is between 5am and midnight?
condition:
- condition: state
entity_id: 'binary_sensor.allow_automation'
state: 'on'
- condition: time
after: '05:00:00'
before: '00:00:00'
What happens if you want to have a time period that is between 5am and 4am? That is, run 23 hours a day except 4am-5am.
Well, technically it should bridge the midnight but you’ll find many threads on here where it doesn’t, so to be sure you would use an or condition, after 5 or before 4
condition:
- condition: state
entity_id: 'binary_sensor.allow_automation'
state: 'on'
- condition: or
conditions:
- platform: time
after: '05:00:00'
- platform: time
before: '04:00:00'
Actually, if you want a condition that is between 05:00:00 and midnight, then just use after
(i.e., remove the before
option.) “After 5” means “between 5 and midnight.”
Are you sure about that? The code definitely has support for times spanning midnight (i.e., before
is before after
, or to put it another way, after
is after before
.) In theory the following should work:
condition: time
after: '05:00:00'
before: '04:00:00'
If it doesn’t then that’s a bug.