As an input for some automations I want to have a sensor that gives the average time of day I go to bed and when waking up. I have an awake and sleep modus input boolean and these are triggered switched on and off based upon certain events automatically. But now I want to know the average time of day these input booleans are turned on. I’ve looked at the statistics sensor but don’t know if this provides what I want. Does someone of you have an idea how to achieve this?
1 Like
You’d have to query the database for the time the event happened, convert the time strings into seconds. Subtract midnight (in seconds) from each time in seconds. Average that value and convert it back into a time. It’s doable but not easy.
I put this together last week for a short-term average … it’s not pretty, but it seems to work so far.
You might be able to rig something using:
If you create an input helper that turns on at 00:00 and off when you go to bed, a history stats sensor can calculate how long that took (a duration, resembling the time). Something similar can be done for the time you wake up.
Then you might be able to use a statictics sensor to calculate averages on that. Provided they can do so with durations.