Hello enveryone.
Im trying to config a sensor that count the number of hours my pool purifier in 24hours.
Its important to me that count the hours since 3:00 am to 2:59 am of the next day.
Not the typical 24 hours from 00:00 to 23:59
The typical case (24 hours from 00:00 to 23:59) its easy and the sensor works with this code:
That’s because before 3:00, the start time is in the future. You’ll have to subtract a day off of it. Something like this (but I haven’t tested it):
That code still suffers from the same root problem: The re-calculation of the time window occurs at midnight (00:00), not at 03:00. You’d still need an if-then statement.
For example:
Jan 2 at 01:00 - your code says window is Jan 1 03:00 to Jan 2 03:00. That is what is desired.
Jan 2 at 04:00 - your code says window is Jan 1 03:00 to Jan 2 03:00. That is NOT what is desired.
hello.
before the july update, the if solution works perfect.
But i dont know what happend, but not works? do you have problems with history_stats sensors???
There is nothing wrong with that portion of the code; it will work the same as today_at(). You may have an error in the other part of the definition.
You didn’t specify what was not working; if it’s calculating incorrectly it would be helpful to know what it is doing. If it’s not working at all it would be helpful to know what is in the error logs.
I dont understand what is the problem. But is strange. Not fails all the days.
This is not a crĂtica sensor in my setup, its interesting to optimize the use of the pool but not critical.
But i have a lot of curious with situation jejeje
Hello again.
The problem is not only with the sensor from 3 to 3.
I notice today that the problem its the same with the normal “natural day” sensor.
This is the sensor: