Calculate time between variables/events?


#1

I have a humidifier rigged into ST/WebCore. It alerts me when the humidifier is FULL and needs to be emptied. I’d like to know how long it’s been off in the alert. I have set up to only alert me when I’m home or in-between events. I’m storing a variable of the date/time it turns OFF, and now I’m trying to subtract the current time from that

My problem now, is all I can get back is 0 seconds. The text always says " Dehumidifier has been full for 0 seconds! Be sure to empty it soon!"


#2

That’s because every 2 hours you are resetting the variable to local now. So, you will always return zero. You need two functions, one when the reading first drops below the limit you have set to trigger setting the variable. Then you need to have another function to trigger the notification. But i would also use a “while” loop for that function. Take a look at how i have my washing machine notifications set up. This works very well. Of course, it’s a little more complicated than your scenario but you should get the jist of it.

You can also output your duration in Minutes rather than seconds. Might be a little easier to understand. But that won’t be a running clock that will update live in the notification. It is set when the piston runs, that’s all.


#3

Thanks for the reply! I’ll dig into this to see if I can get it to work, I think the while loop is what I’m missing. Will also adjust the variable to set at the right time.


#4

You can do what you want to do without loops or timers, just logic and subscribing to your presence sensor. I also fixed the duration calculation in this and made sure it worked:


#5

Thank you! @michicago - your solution did exactly what I was hoping for. The humidifier turned off and the text message gave me the output of how long it’s been full for. Thanks to you, I’m now more motivated the empty it when it says it’s been+12 hours since it’s been off :slight_smile:


#6

The reason that I have while loops and timers, my presence sensor will sometimes trigger before i walk into the house, which means I won’t be able to hear the announcement, or sometimes after I’ve already walked into the house, at which point it’s too late. By my mode always changes to home well before I actually walk into the house so I wouldn’t be able to hear the announcement until i walk into the house, hence the contact sensor and the waits.