I’m trying to get together a state machine that will update based on time of day AND sunset/sunrise.
The idea being this will account for changes in when I actually want lights etc to come on in the evenings/mornings, but also allow for dimmer lights in the middle of the night.
Have tried a few templates, and some of my own coding and not had anything that works.
Seems it should be straightforward but I can’t figure out how to do it!
The hope is a single channel that can then be used in automations to mask light behaviour throughout the day, as well as controlling speaker volumes etc.
Have you looked at the built-in Times of Day sensor? If you set up the TOD binary sensors, you could then use a triggered template sensor to give your ordinal value based on which one is on.
binary_sensor:
- platform: tod
name: Night
before: sunrise
before_offset: "-01:00"
after: "00:00"
- platform: tod
name: Morning
before: sunrise
before_offset: "+02:00"
after: sunrise
after_offset: "-1:00"
- platform: tod
name: Daytime
before: sunset
before_offset: "-1:00"
after: sunrise
after_offset: "+02:00"
- platform: tod
name: Evening
after: sunset
after_offset: "-1:00"
before: "22:00"
- platform: tod
name: Bedtime
after: "22:00"
before: "00:00"
group:
times_of_day:
name: Times of Day
entities:
- binary_sensor.night
- binary_sensor.morning
- binary_sensor.daytime
- binary_sensor.evening
- binary_sensor.bedtime