In configuration.yaml, this works great and it changes properly thru the day.
binary_sensor:
- platform: tod
name: Morning
after: sunrise
before: "11:00"
- platform: tod
name: Afternoon
after: "11:01"
before: sunset
before_offset: "-01:00"
- platform: tod
name: Evening
after: sunset
after_offset: "-01:00"
before: "23:00"
- platform: tod
name: Goodnight
after: "23:01"
before: sunrise
I put this next code into my sensors.yaml to create a sensor based on this and it doesn’t show up. What’s weird is i finally got it to work then couple hours later I looked at nope no sensor again. Restarted, readded, etc and it just won’t show up again. Why did it work once, then not again??
- platform: template
sensors:
time_of_day:
friendly_name: "Time of Day"
value_template: >-
{% if is_state('binary_sensor.morning','on') %}
Morning
{% elif is_state('binary_sensor.afternoon','on') %}
Afternoon
{% elif is_state('binary_sensor.evening','on') %}
Evening
{% elif is_state('binary_sensor.goodnight','on') %}
Goodnight
{% endif %}