I am controlling my Boiler with sonoff device. I would like to have an item that will show the time the current boiling time (only when the switch is on). I assume I need to use DateTime item and update it. My question, how do I update the item?
Create a periodic timer that will update the DateTime as long as the switch is on
Use rule with cronjob to update the item while the switch is on.
How long the switch has been on? Or when the switch is on, show the current time of day? Perhaps a graph that shows the ON/OFF state and corresponding time?
One way, as you mentioned, is use a rule that evaluates the switch state, if ON, then updates a DateTime proxy item.
How long the switch has been on since it was turned on. The UI shows that the boiler is on, I just want to be able to know how much time it is already on.
BTW, other option that I found is to use the expire binding.
A DateTime item contains an absolute time. That’s not what you want.
Create a number item:
Number BoilerMinutes
Rules:
rule "reset daily usage"
when
Time cron "5 0 0 ? * * *" //5 seconds after midnight
then
BoilerMinutes.postUpdate(0)
end
rule "Increment BoilerMinute"
when
Time cron "1 * * ? * * *" //Every minute 1 second After minute
then
if (Boiler.state == ON) {
BoilerMinute.postUpdate((BoilerMinute.state as Number) + 1)
}
end
Every minute the Boiler minute item will increase by one.
I configured the cron time just after the minutes and hours so as not to conflict with other system jobs.
The counter is reset after midnight.
@vzorglub, actually you answered other question I had. How to count the number of minutes the boiler is on in a day. Is this the way to go or if I use InfluxDB as persistence, there is other way to get this number?
What I am looking in this thread is to have the total heating time currently (from the time I turned on the boiler until I turned it off). I assume that for that purpose cronjob is not the optimal way, am I right?
I know that binding is not for that purpose, but it would be great if there was a binding that implement some basic patterns to simplify rules (as Expire did)
rule "reset daily usage"
when
Time cron "55 59 23 ? * * *" //5s BEFORE midnight
then
DailyBoilerMinutes.persist("influxdb") // Persists the total daily value just BEFORE midnight
BoilerMinutes.postUpdate(0) // Resets daily counter
DailyBoilerMinutes.postUpdate(0) // Resets Total daily counter
end
rule "Increment BoilerMinute"
when
Time cron "1 * * ? * * *" //Every minute 1 second After minute
then
if (Boiler.state == ON) {
BoilerMinute.postUpdate((BoilerMinute.state as Number) + 1)
}
end
rule "Stop counter"
when
Item Boiler changed to OFF
then
// Adds current counter to daily total
DailyBoilerMinutes.postUpdate((DailyBoilerMinutes.state as Number) + (BoilerMinutes.state as Number))
BoilerMinutes.postUpdate(0) // resets current counter
end
Thx, yes I use mapdb as persistence for restoring item state.
Thx for your help. Cron job is good solution and this what I will use, but I somehow I fill that cron job i too much for this as 90% of the day the boiler is off so cron job is running without any need (this is why I’ve raised the question about binding for common patterns)
Don’t worry about that. It will take 10-20ms every minute to run that job.
If you have other things that need to run every minute, you can always put them in the same cron rule