Retentive or Cumulative Timer

I am trying to find an app or write a rule that will count the total time a device has been on. Once the device equals a set time I would like to turn on a switch. Then I would reset the timer and start again. I can also see that just having a timer that counts up with a device is on for a cumulative count of time in operation could be handy. The device may go on and off several times before the set or run time would equal the timer time.

In Allen Bradley PLC world I would create a rung with the device I am monitoring and have a retentive timer counting when it is on. When the set or run time equals the device on time we turn on a switch and reset the timer. This is pretty easy in a plc, but in Hubitat I am struggling,

Any help would be appreciated.

Do you actually need to know/see the time yourself, or do you just want something to happen when it's been long enough? The latter is easy with Rule Machine--just use the "and stays?" option on your trigger (also called a "sticky trigger"), and the rule won't trigger until the device has been in the resultant state for the specified amount of time following the event.

It would be interesting to know the time, but that isn't a requirement.

I want to turn on a switch after the device I am monitoring has been on for a specified amount of time. The specified amount of time may be 10 hrs, but the device I am monitoring will only be on for 45 minutes to 2 hours at a time. So it will take a number of operations for it to get to the set time to trigger the switch to turn on.

With the "and stays" option will it retain the timer count over a few weeks time? That is not how I interpreted this option. Clarification would be great.

I have been testing the sticky trigger and cannot get it to be retentive over multiple triggers.

If I knew to accumulated time I could do some math and update the sticky trigger. The next issue is it does not appear I can use a variable to for the trigger device event.

OK, I see your total time may span multiple on/off cycles, and you'd want to reset the time according to some other unspecified event/trigger. A sticky trigger will indeed not do that -- it resets on its own every time.

This should still be more or less possible with a rule, but it would get tricky to write if you still want it to do something in the middle of an on/off cycle rather than just seeing what the total computed time is at the end (i.e., after the "off" event). In that case, a local or hub variable plus a rule that triggers with the switch on, waits for the switch to turn off, and adds the elapsed time to the variable, and does whatever may be needed based on that would work in general -- but I don't have a specific example.

I wonder if anyone has a custom app that might do what you want, where all these calculations (assuming you might care about the "middle" of such a cycle, too) seem like they'd be easier to me...

See if App: Device Tracker, Multiple Device On/Off Times, On Counts, Notifier, Battery Levels, Switches, Contacts, Temperatures, Power, etc.. With variables access works for what @evanandmaryanne wants to do.

1 Like

Oh, thank you so much! I reprogrammed so much of this over time... I guess I forgot to check if it already existed. That's gold!

1 Like

You may find the following device driver creates a perfect device to track this situation:

2 Likes

Thank you all for your help! I think I have it will all of your help. Much appreciated.

3 Likes