like my topic says, the workday binary sensor is state changing at 11am, not midnight (note: i may be reading the history incorrect)
the binary sensor was was working correctly in 0.96.1
but since i’ve upgraded to 0.102.3 this midday switching is seen
note: all my events based on a time e.g. alarms, sunset etc are still working as expected
That was my initial assessment too, but all logs when something is triggered manually is accurate.
E.G. If I activate one of my Lifx lights at 9am, the history in HA shows that I activated that light at 9am.
I believe there is a bug in this code (that has been there since it was first written.)
First, it’s not just updating at midnight, it updates periodically (every 30 seconds) for some reason. Second, and more importantly, it’s calling datetime.today() to get the date, but it should be calling homeassistant.util.dt.now().today(). The former uses the environment’s time zone setting (OS, docker container, etc.), whereas the latter uses HA’s time zone configuration.
To see if this is why your workday binary sensor is updating at the wrong time, enter the following into the Template Editor and let me know what you get.
I suspect the problem didn’t start because of upgrading from 0.96.1 to 0.102.3, but rather when you made some change to the environment in which HA runs. E.g., did you maybe start using hass.io?
I realise that it would require people to include sensor.date (no bad thing in my book along with all the associated ancillaries) but this would trigger only on a new local day ?
What have I missed ?
Sorry, I was aiming at what I would use if I was doing it within HA.
Your homeassistant.util.dt.now().today() is the Unix request to get the current day, I assume ?
And when would this be updated ? (frequency)
I was kindof aiming at something that would need fewer requests and “IF”
was part of the standard configuration, then all those requests and updates would be done and just part of overhead.
The date part would update once per day and at the right time for any (local) ‘day’ sensor
I realise that the workday is probably written with direct access to the OS but why does it need to be (probably along the lines you are suggesting using the homeassistant.util.dt ‘thang’ but my ignorance of the distinction is probably meaning that I’'m at a slight tangent to reality (normal for me )
I think you misunderstand. workday is an integration in HA which creates a binary_sensor that indicates whether or not it is a workday based on the configuration of the entity. homeassistant.util.dt.now().today() is Python code (which is part of HA) that I’m suggesting should be used within the implementation of the workday binary sensor code instead of what it currently uses.
To be clear, I’m not talking about templates or scripts or automations, I’m talking about Python implementation code.
@culloden_spectre, you’re leaving us hanging here. Can you try entering what I showed above in the Template Editor and telling us what you get? I’d like some verification that an incorrect time zone setting in the environment is causing the problem before I consider trying to fix it.
Ok so, with the help of the fine People above me I have worked out where I have gone wrong.
On my latest Docker install (0.102.3HA) i didnt set the TZ environment variable, but i had done it on the previous version (0.96.1).
so i have made the changes to the new Docker container with the environment vairable TZ=Australia/Melbourne, and im sure this will solve the workday sensor switching
@pnbruckner seems you were spot on the money, appears the workday sensor is not using the HA configured TZ.