This object is in archive! 

Help with rule: count how much time a device is ON during each day

Pablo shared this question 3 years ago
Answered

Hello,


I would like to know how much time a certain device is ON during each day. Idea is at the end of the day a message is sent with this information.


My problem is that this device is switching ON and OFF several times during the day. So I need to do additions to a cumulative time variable for the periods it is ON and don't know how.


Any of you have done something similar?


I want to apply this for my heating boiler.


Thanks!!

Comments (6)

photo
1

Quite interesting: I didn´t try it out because I don´t have the pro package and can´s send a variable via mail but I would try it this way: First rule to look every minute if the consumption is above idle and then increase a variable or virtual meter. The second to send a mail every 24h and reset the variable. That won´t work of course if the on-period of the device is only seconds.... but with a boiler I would give it a try.


/a+FgbEVKzm0AAAAASUVORK5CYII=

photo
1

Indeed this is a good one, specially because there is no way using the puzzles to separate integers from decimals. However after thinking for a while I came up with this solution, I made a test, will let you know how it worked.

photo
1

Alberto, could you please explain the need for the join command to me? I think you could skip that because the rule is quite quick and even if the boiler switches off within the timespan of the rule runnning, I would expect the rule to fire again and execute the second part of your If/else rule.


Your solution is great, it´s the first time I noticed the "part of" tile and what you can do with it.

photo
1

Klaus,


In this particular example you can forget about JOIN, however it is now a habit to me to use JOIN on rules to avoid double triggering (I have seen and some others on this forum, that if you use rules without JOIN and/or delays rules run two times) for example if you do a rule to receive a push alert of any sensor without JOIN and/or delays to send the message you will receive two push notifications instead of one. In this case I just wanted to avoid double triggers.


In theory JOIN is only required if you want the rule to be able to be restarted (While waiting for something) if the status of the sensor you are checking changes status.

photo
photo
1

Wow! Thanks guys!


I love the simplicty of Klaus' solution. Do you know if having a rule executing every minute for this purspose, is the optimum from the performance point of view?


I was trying something similar to Alberto's. But I have an error and not able to find it... Anyhow, Alberto, you have to take in account what happens if device was switch ON one day and OFF next day to do properly the operations.


Regarding the virtual meters, I don't understand why you use them instead of variables. Could you explain Alberto? Thanks!


It's a pitty rules don't allow operations with time, don't you think? This feature should be developed in my opinion.

photo
1

Pablo,


I also thought about doing it like Klaus, the only issue I see is the fact that if your controller reboots you will miss that time. Accuracy I think you will get very similar from both solutions, both resolutions are minutely. Klaus' solution doesn't care about which day you started and finished counting, that is a plus.


Yes indeed, that is a problem I was thinking about it but cannot find a way to solve it that I like, I will keep thinking about it.


Variables reside in the controller and their values get wipped out when you reboot or power off the controller, virtual devices are created in the controller but they are connected to Zipato Server, so, in the event of a reboot, Zipato controller will read values from the server, so technically you won't loose data (unless you experience an internet outage while storing data to virtual meters). If this is important to you I would use virtual meters instead of VAR1 and VAR2 that way if your controller reboots you still would get good calculations, I didn't do it because those are the only placeholders (value5 and value 16) available from the virtual meter I use for these purposes and didn't feel like creating another one.


Yes, I also agree, even though Zipato's rule creator is superior to competitor's there is still room for improvements, like time operations, a way to separate or make operations with integers, integer random numbers, etc. That's were some other controllers use Lua or some other languaje to acomplish those complicated tasks.

photo
1

Alberto, thanks for the clarifications on the virtual meter vs variable.


I am checking and saving on a variable the day in which switch was ON and the day it is OFF. And then I check:


If (dayON = dayOFF) then

AccumulatedHours = difference of hours

Else

If dayOFF > day OFF then

AccumulatedHours = 24 - hourON + hourOFF

else

same, but I use this for monthly accumulated

end if

end if


Hope it is understandable. It is not optimum, but I guess is the best achivable with the options we have.

photo
1

No problem, glad I could help. I will try that seems like a good option. Take care.

photo
photo
1

Alberto, I agree puzzles are great, but expert users should be able to use lua or equivalent.

photo
1

Thanks to Alberto for the tip with virtual meter, thats really a point as some users complain about many reboots. Perhaps one should really switch to virtual meters in most cases.


The real advantage of a variable is that it is resetted to zero after a reboot so you can use it to monitor reboots ;-)