#Debugging "Times of the Day" automation

1 messages Β· Page 1 of 1 (latest)

untold shadow
#

Hi all, I have a binary sensor "Dark outside" which is defined using the the tod integration:

binary_sensor:
  - platform: tod
    name: Dark Outside
    after: sunset
    before: sunrise
    unique_id: dark_outside

I'm using this sensor to turn some outdoor lights on or off, and it works great for turning the lights on, but very regularly (multiple times per week) the lights don't turn off...

I think this sensor might be misbehaving (see the screenshot). Somehow the "Dark Outside" has turned off at 1:31 (which is not supposed to happen, because I'm pretty sure that's not sunrise), but also this doesn't show up in the Activity log (see screenshot) and also didn't trigger the linked automations πŸ˜•
If I look at the scheduled updates (see screenshot) I see that those values are correct...

How to debug this?

exotic ermine
#

Have you restarted HA at that time?

#

In that case the sensor is started on the new day and it only turns on again on the next sunset.

#

To make it more reliable I created two TOD sensors. One from sunset to midnight and one from midnight to sunrise.
Those two sensors can be combined in a group helper and that one survives restarts between midnight and sunrise.

plucky surge
#

I didn't know about the TOD sensor, I'm using a binary template sensor which works well for me. The benefit is that I can tweak really well what I consider to be dark by changing the last number:
{{ state_attr('sun.sun', 'elevation') | float < -1 }}

untold shadow
#

That's it! I thought I didn't (because I was asleep), but checking the logs it's the auto update that causes this 🀭

2025-12-20 01:30:31.553 INFO (MainThread) [supervisor.homeassistant.core] Updating Home Assistant to version 2025.12.4

Will try your suggestion!

plucky surge
#

Automatically updating home assistant is ballsy

untold shadow
#

@plucky surge
It's patches only (see screenshot), I do it primarily because I got a bit tired with the contant esphome updates that take a long time to apply to all the different esp devices.

plucky surge
#

It still can cause unexpected behavior as demonstrated by my you creating this post πŸ˜‰

#

I'm not that brave 😁

untold shadow
exotic ermine
#

By adjusting the elevation angle in the template you could create an offset as well. Just not by time but by sun elevation.

#

Many ways to skin a cat.

untold shadow
#

Yes, I used that before as well!

plucky surge
#

I'm not sure if the "darkness offset" is static around the year πŸ€”
I might be wrong but at least it feels like sunset is quicker in winter than in summer.
But agreed, as long as it works pick whatever solution suits your needs

exotic ermine
#

In the end you have to be comfortable with the result.

untold shadow
#

@plucky surge I'm inclined to agree with you there, seems more logical from a physics perspective πŸ™‚

#

Thanks both for your help!