Exact cumulative working time of a device - RM

I set on a previous rule a way to measure - every 5 minutes - the working of a device.
Every 5 minutes, if the device was on, I added 5 to a global variable and organized as hours/minutes.
I set 5 because I felt that triggering a measure every minute was too "fast" for a rule.

Maybe I wrong on this. On some devices (not for my geothermal unit, 5 minutes are ok), I need a better precision.

So, is it a better way to count in real time (by the minute) the working of a device that what I did ?
REV C-5, V2.2.3.119

comments welcome :smiley:

I haven't tried it, but should also be possible to organise the rule based on the GeoCool changing as a trigger.
Each time it ran, you would compare the current time to the time it last ran, that would give you precisely the amount of minutes it ran in the previous mode. Then you would reset the last ran variable to current time and so on.
It would be much more precise, but it would mean that if your Geo Status was on the same status for the same time, your stats wouldn't update until it changed.

I do something like this for my sump pump, but that adds the complication that the on/off state is not something Hubitat can track. For that reason, the only way I know of is to put it on a energy monitoring plug and track on/off state with a change of power consumed of 50W or more. The threshold monitoring is done within the ZEN15 plug itself and only these significant changes are reported.

I'm assuming your devices are ones that Hubitat controls and/or report their operating state back to the hub. In that case, I like MrPancake's idea for a trigger.

1 Like

@PPz Here's my thought:

You'll need some local variables:

Midnight was the tricky part of this - there's time math in RM, but no date math. So, when "12:00 AM" is the trigger and the device is on, we add in the time passed between the trigger time and midnight and reset the "on" time to midnight, ready to capture the rest of the "on" time when the next "off" comes. The "1440" line both corrects for that midnight passage and allows for a device that's been on all day.

Change "TestSwitch" to whatever your trigger is. Also, you'll probably want "TotalTime" to be an RM Global Variable, to make it easier to access from outside this rule. That's in minutes, of course, so divide by 60 for hours, or 1440 (there's that number again :wink: ) for days.

...and here's something we've never tried before: cut and paste this to a ".json" file, and (I think) you should be able to import it into RM. (EDIT: yup, it worked!)

{"deviceReplacements":{"238":{"deviceName":"Virtual switch","deviceLabel":"TestSwitch","deviceTypeName":"Virtual Switch","deviceTypeNamespace":"hubitat"}},"appReplacements":{"304":{"appTypeName":"Rule-4.0","appTypeNamespace":"hubitat","appName":"Rule-4.0","appLabel":"cumulative time test","parentAppTypeName":"Rule Machine","parentAppLabel":"Rule Machine","singleInstance":false}},"appData":{"304":{"state":{"actionListMain":["1","2","3","4","5","6","10","7","8","9"],"connectors":{},"parens":{"1":0,"2":0},"actionDone":true,"oldConst2":null,"lvt.Trigger":"String","hasRuleAct":false,"selectActionsParams":{"thisStr":"Main","label":"cumulative time test"},"editCondIf":null,"lv.TimePassed":0,"usesTime":false,"inIf":null,"trigCustoms":[],"repeating":[],"capabDone":true,"lastEvtName":"TestSwitch","skippingMain":false,"skipAllMain":null,"locationBlocked":[],"inRepIf":null,"ndx.false":12,"lvList":["TimeOff","TimeOn","TimePassed","TotalTime","Trigger","sdf"],"ruleNdx":4,"firstR":{"1":false,"2":false},"timeTriggers":[],"allVarsO":["ARRIVED","LEFT","sdf","TimeOff","TimeOn","TimePassed","TotalTime","Trigger"],"actLabelIndent":"","howManyT":20,"subscribedVariables":[],"certainTimes":[],"oldConst":null,"prevState":{"PB":"true","Trigger":"off","238":"off","TimePassed":0},"eval":{"1":[3],"2":[6,"OR","2"]},"capabstrue":{"1.true":"TestSwitch(off) turns changed","2.true":"When time is 12:00 AM EST","3.true":{}},"blockIfMain":false,"lastEvtDate":"20-Nov-2020","parenLev":0,"lv.TimeOff":"2020-11-20T00:00:00.000-0500","lv.TotalTime":0,"actionsMain":{"1":{"wait":null,"delay":"","modes":{},"method":"getSetVariable","indent":"","rule":0,"label":"Set Trigger to '%value%'\n","cond":0},"2":{"wait":null,"delay":"","modes":{},"method":"getIfThen","indent":"","rule":1,"label":"IF (Variable Trigger(off) = on(F) [FALSE]) THEN\n","cond":0},"3":{"wait":null,"delay":"","modes":{},"method":"getSetVariable","indent":"\t","rule":0,"label":"\tSet TimeOn to current time\n","cond":0},"4":{"wait":null,"delay":"","modes":{},"method":"getElseIf","indent":"\t","rule":2,"label":"ELSE-IF (Variable Trigger(off) = off(T) OR \n\tTestSwitch(off) is on(F) [TRUE]) THEN\n","cond":0},"5":{"wait":null,"delay":"","modes":{},"method":"getSetVariable","indent":"\t","rule":0,"label":"\tSet TimeOff to current time\n","cond":0},"6":{"wait":null,"delay":"","modes":{},"method":"getSetVariable","indent":"\t","rule":0,"label":"\tset TimePassed to minutes of difference between TimeOn(12:00 AM) and TimeOff(12:00 AM)\n","cond":0},"7":{"wait":null,"delay":"","modes":{},"method":"getSetVariable","indent":"\t","rule":0,"label":"\tSet TotalTime to (TotalTime + TimePassed)\n","cond":0},"8":{"wait":null,"delay":"","modes":{},"method":"getSetVariable","indent":"\t","rule":0,"label":"\tSet TimeOn to current time\n","cond":0},"9":{"wait":null,"delay":"","modes":{},"method":"getEndIf","indent":"","rule":0,"label":"END-IF\n","cond":0},"10":{"wait":null,"delay":"","modes":{},"method":"getSetVariable","indent":"\t","rule":0,"label":"\tIF (Variable TimePassed(0) <= 0 TRUE) Add 1440 to TimePassed\n","cond":9}},"lv.Trigger":"off","nestedInIf":[],"actNdx":12,"installed":true,"lastEvtValue":0,"waitEvents":[],"private":"true","lvt.TotalTime":"Number","lv.TimeOn":"2020-11-20T00:00:00.000-0500","skipTypeMain":"if","gvList":["ARRIVED","LEFT"],"lvt.TimeOff":"Time","hasDevice":null,"ndx.true":3,"editingRule":0,"allVars":{"Trigger":{"val":"off","type":"String"},"LEFT":{"val":"false","type":"Boolean"},"sdf":{"val":null,"type":null},"ARRIVED":{"val":"false","type":"Boolean"},"TimeOff":{"val":"2020-11-20T00:00:00.000-0500","type":"Time"},"TotalTime":{"val":0,"type":"Number"},"TimeOn":{"val":"2020-11-20T00:00:00.000-0500","type":"Time"},"TimePassed":{"val":0,"type":"Number"}},"lvt.TimeOn":"Time","simpleCond":false,"nestedRepIf":[],"nestedBlockMain":[],"lastEvtTime":"10:55 AM","condOper":"cond","formerState":"TimePassed","cutAction":[],"nestedIfMain":[],"nestedLabel":[],"paramNdx":1,"lastEvtDevId":"238","howMany":7,"varUseList":{},"waitCondNdx":2,"token":3,"nestedSkipAllMain":[],"capabsfalse":{"6.false":"Variable Trigger( ) = off","9.false":{},"2.false":"TestSwitch(off) turns changed","10.false":"cond","12.false":{},"3.false":"Variable Trigger( ) = on"},"timeTriggersW":{},"timeFormat":"hh:mm a","waitConds":[],"lvt.TimePassed":"Number"},"appSettings":[{"deviceList":null,"multiple":false,"name":"state9","type":"number","value":"0"},{"deviceList":null,"multiple":false,"name":"valStringOpMain.1Trigger","type":"enum","value":"Set string"},{"deviceList":null,"multiple":false,"name":"state6","type":"text","value":"off"},{"deviceList":null,"multiple":false,"name":"pausRule","type":"button","value":""},{"deviceList":null,"multiple":false,"name":"deleteLv:TimePassed","type":"button","value":""},{"deviceList":null,"multiple":false,"name":"cancelLv","type":"button","value":""},{"deviceList":null,"multiple":false,"name":"state2","type":"string","value":"on"},{"deviceList":null,"multiple":false,"name":"insertAct","type":"enum","value":""},{"deviceList":null,"multiple":false,"name":"cond","type":"enum","value":null},{"deviceList":null,"multiple":false,"name":"state3","type":"text","value":"on"},{"deviceList":null,"multiple":false,"name":"varType","type":"enum","value":""},{"deviceList":null,"multiple":false,"name":"valTimeOpMain.5TimeOff","type":"enum","value":"Now"},{"deviceList":null,"multiple":false,"name":"tstate1","type":"enum","value":"changed"},{"deviceList":null,"multiple":false,"name":"createCon:TimeOff","type":"button","value":""},{"deviceList":null,"multiple":false,"name":"numOpMain.6TimePassed","type":"enum","value":"time difference"},{"deviceList":null,"multiple":false,"name":"valNumberMain.10TimePassed","type":"number","value":"1440"},{"deviceList":null,"multiple":false,"name":"editLv:TotalTime","type":"button","value":""},{"deviceList":null,"multiple":false,"name":"editToken","type":"button","value":""},{"deviceList":null,"multiple":false,"name":"createCon:TotalTime","type":"button","value":""},{"deviceList":{"238":null},"multiple":true,"name":"rDev2","type":"capability","value":null},{"deviceList":null,"multiple":false,"name":"valStringOpMain.11Trigger","type":"enum","value":""},{"deviceList":null,"multiple":false,"name":"createCon:TimePassed","type":"button","value":""},{"deviceList":null,"multiple":false,"name":"valTimeOpMain.8TimeOn","type":"enum","value":"Now"},{"deviceList":null,"multiple":false,"name":"rDev9","type":"enum","value":"TimePassed"},{"deviceList":null,"multiple":false,"name":"rDev6","type":"enum","value":"Trigger"},{"deviceList":null,"multiple":false,"name":"rDev3","type":"enum","value":"Trigger"},{"deviceList":null,"multiple":false,"name":"varV","type":"number","value":""},{"deviceList":null,"multiple":true,"name":"logging","type":"enum","value":null},{"deviceList":null,"multiple":false,"name":"editCond","type":"enum","value":""},{"deviceList":null,"multiple":false,"name":"updateRule","type":"button","value":""},{"deviceList":null,"multiple":false,"name":"hasRule","type":"button","value":""},{"deviceList":null,"multiple":false,"name":"deleteLv:Trigger","type":"button","value":""},{"deviceList":null,"multiple":false,"name":"runAction","type":"button","value":""},{"deviceList":null,"multiple":false,"name":"valVar2Main.7TotalTime","type":"enum","value":"TimePassed"},{"deviceList":null,"multiple":false,"name":"deleteLv:TotalTime","type":"button","value":""},{"deviceList":null,"multiple":false,"name":"locVar","type":"text","value":""},{"deviceList":null,"multiple":false,"name":"rCapab6","type":"enum","value":"Variable"},{"deviceList":null,"multiple":false,"name":"rCapab3","type":"enum","value":"Variable"},{"deviceList":null,"multiple":false,"name":"rCapab2","type":"enum","value":"Switch"},{"deviceList":null,"multiple":false,"name":"numOpMain.10TimePassed","type":"enum","value":"add number"},{"deviceList":null,"multiple":false,"name":"rCapab9","type":"enum","value":"Variable"},{"deviceList":null,"multiple":false,"name":"editAct","type":"enum","value":""},{"deviceList":null,"multiple":false,"name":"cutAct","type":"enum","value":""},{"deviceList":null,"multiple":false,"name":"rCapab12","type":"enum","value":""},{"deviceList":null,"multiple":false,"name":"delayActMain.7","type":"bool","value":""},{"deviceList":null,"multiple":false,"name":"delayActMain.6","type":"bool","value":""},{"deviceList":null,"multiple":false,"name":"delayActMain.8","type":"bool","value":""},{"deviceList":null,"multiple":false,"name":"atTime2","type":"time","value":"00:00"},{"deviceList":null,"multiple":false,"name":"not11","type":"bool","value":""},{"deviceList":null,"multiple":false,"name":"delayActMain.1","type":"bool","value":""},{"deviceList":null,"multiple":false,"name":"valTimeD1Main.6TimePassed","type":"enum","value":"TimeOn"},{"deviceList":null,"multiple":false,"name":"editLv:TimeOn","type":"button","value":""},{"deviceList":null,"multiple":false,"name":"moreVar","type":"button","value":""},{"deviceList":null,"multiple":false,"name":"delayActMain.3","type":"bool","value":""},{"deviceList":null,"multiple":false,"name":"delayActMain.5","type":"bool","value":""},{"deviceList":null,"multiple":false,"name":"not12","type":"bool","value":""},{"deviceList":null,"multiple":true,"name":"deleteAct","type":"enum","value":null},{"deviceList":null,"multiple":false,"name":"oper","type":"enum","value":null},{"deviceList":null,"multiple":false,"name":"tCapab1","type":"enum","value":"Switch"},{"deviceList":null,"multiple":false,"name":"tCapab2","type":"enum","value":"Certain Time"},{"deviceList":null,"multiple":false,"name":"actionDone","type":"button","value":""},{"deviceList":null,"multiple":false,"name":"actSubTypeMain.9","type":"enum","value":"END-IF"},{"deviceList":null,"multiple":false,"name":"actSubTypeMain.7","type":"enum","value":"Set Variable"},{"deviceList":null,"multiple":false,"name":"actSubTypeMain.8","type":"enum","value":"Set Variable"},{"deviceList":null,"multiple":false,"name":"tCapab3","type":"enum","value":""},{"deviceList":null,"multiple":false,"name":"actSubTypeMain.5","type":"enum","value":"Set Variable"},{"deviceList":null,"multiple":false,"name":"actSubTypeMain.6","type":"enum","value":"Set Variable"},{"deviceList":null,"multiple":false,"name":"actSubTypeMain.3","type":"enum","value":"Set Variable"},{"deviceList":null,"multiple":false,"name":"actSubTypeMain.4","type":"enum","value":"ELSE-IF (conditions) THEN"},{"deviceList":null,"multiple":false,"name":"actSubTypeMain.1","type":"enum","value":"Set Variable"},{"deviceList":null,"multiple":false,"name":"actSubTypeMain.2","type":"enum","value":"IF (conditions) THEN"},{"deviceList":null,"multiple":false,"name":"editLv:TimeOff","type":"button","value":""},{"deviceList":null,"multiple":false,"name":"goof","type":"button","value":""},{"deviceList":null,"multiple":false,"name":"valTimeD2Main.6TimePassed","type":"enum","value":"TimeOff"},{"deviceList":null,"multiple":false,"name":"isVar6","type":"bool","value":""},{"deviceList":null,"multiple":false,"name":"deleteLv:TimeOff","type":"button","value":""},{"deviceList":null,"multiple":false,"name":"time2","type":"enum","value":"A specific time"},{"deviceList":null,"multiple":false,"name":"actTypeMain.10","type":"enum","value":"Set Mode, Variables or File, Run Custom Action"},{"deviceList":null,"multiple":false,"name":"myVarsMain.11","type":"enum","value":"TotalTime"},{"deviceList":null,"multiple":false,"name":"isVar9","type":"bool","value":""},{"deviceList":null,"multiple":false,"name":"myVarsMain.10","type":"enum","value":"TimePassed"},{"deviceList":null,"multiple":false,"name":"actTypeMain.12","type":"enum","value":""},{"deviceList":null,"multiple":false,"name":"refreshActions","type":"button","value":""},{"deviceList":null,"multiple":false,"name":"isVar3","type":"bool","value":""},{"deviceList":null,"multiple":false,"name":"myVarsMain.1","type":"enum","value":"Trigger"},{"deviceList":null,"multiple":false,"name":"hasAll","type":"button","value":""},{"deviceList":null,"multiple":false,"name":"myVarsMain.3","type":"enum","value":"TimeOn"},{"deviceList":null,"multiple":false,"name":"cancelCapab","type":"button","value":""},{"deviceList":null,"multiple":false,"name":"updateV","type":"button","value":""},{"deviceList":null,"multiple":false,"name":"myVarsMain.6","type":"enum","value":"TimePassed"},{"deviceList":null,"multiple":false,"name":"myVarsMain.5","type":"enum","value":"TimeOff"},{"deviceList":null,"multiple":false,"name":"myVarsMain.8","type":"enum","value":"TimeOn"},{"deviceList":null,"multiple":false,"name":"myVarsMain.7","type":"enum","value":"TotalTime"},{"deviceList":null,"multiple":false,"name":"delayActMain.10","type":"bool","value":""},{"deviceList":null,"multiple":false,"name":"origLabel","type":"text","value":"cumulative time test"},{"deviceList":null,"multiple":false,"name":"eraseRule","type":"button","value":""},{"deviceList":null,"multiple":false,"name":"numOpMain.11TotalTime","type":"enum","value":""},{"deviceList":null,"multiple":false,"name":"editLv:TimePassed","type":"button","value":""},{"deviceList":null,"multiple":false,"name":"editLv:Trigger","type":"button","value":""},{"deviceList":null,"multiple":false,"name":"delete","type":"enum","value":""},{"deviceList":null,"multiple":false,"name":"numOpMain.7TotalTime","type":"enum","value":"variable math"},{"deviceList":null,"multiple":false,"name":"valStringMain.1Trigger","type":"textarea","value":"%value%"},{"deviceList":null,"multiple":false,"name":"RelrDev6","type":"enum","value":"="},{"deviceList":{"238":null},"multiple":true,"name":"tDev1","type":"capability.switch","value":null},{"deviceList":null,"multiple":false,"name":"RelrDev9","type":"enum","value":"<="},{"deviceList":null,"multiple":false,"name":"actionCancel","type":"button","value":""},{"deviceList":null,"multiple":false,"name":"createCon:Trigger","type":"button","value":""},{"deviceList":null,"multiple":false,"name":"createCon:TimeOn","type":"button","value":""},{"deviceList":null,"multiple":false,"name":"RelrDev3","type":"enum","value":"="},{"deviceList":null,"multiple":false,"name":"valMathOpMain.7TotalTime","type":"enum","value":"+"},{"deviceList":null,"multiple":false,"name":"actTypeMain.9","type":"enum","value":"Conditional Actions"},{"deviceList":null,"multiple":false,"name":"comments","type":"textarea","value":""},{"deviceList":null,"multiple":false,"name":"valVarMain.7TotalTime","type":"enum","value":"TotalTime"},{"deviceList":null,"multiple":false,"name":"actSubTypeMain.10","type":"enum","value":"Set Variable"},{"deviceList":null,"multiple":false,"name":"valTimeOpMain.3TimeOn","type":"enum","value":"Now"},{"deviceList":null,"multiple":false,"name":"not6","type":"bool","value":""},{"deviceList":null,"multiple":false,"name":"varValue","type":"textarea","value":null},{"deviceList":null,"multiple":false,"name":"not3","type":"bool","value":""},{"deviceList":null,"multiple":false,"name":"useCondMain.10","type":"bool","value":""},{"deviceList":null,"multiple":false,"name":"deleteLv:TimeOn","type":"button","value":""},{"deviceList":null,"multiple":false,"name":"not9","type":"bool","value":""},{"deviceList":null,"multiple":false,"name":"actTypeMain.2","type":"enum","value":"Conditional Actions"},{"deviceList":null,"multiple":false,"name":"actTypeMain.1","type":"enum","value":"Set Mode, Variables or File, Run Custom Action"},{"deviceList":null,"multiple":false,"name":"actTypeMain.4","type":"enum","value":"Conditional Actions"},{"deviceList":null,"multiple":false,"name":"actTypeMain.3","type":"enum","value":"Set Mode, Variables or File, Run Custom Action"},{"deviceList":null,"multiple":false,"name":"actTypeMain.6","type":"enum","value":"Set Mode, Variables or File, Run Custom Action"},{"deviceList":null,"multiple":false,"name":"actTypeMain.5","type":"enum","value":"Set Mode, Variables or File, Run Custom Action"},{"deviceList":null,"multiple":false,"name":"actTypeMain.8","type":"enum","value":"Set Mode, Variables or File, Run Custom Action"},{"deviceList":null,"multiple":false,"name":"actTypeMain.7","type":"enum","value":"Set Mode, Variables or File, Run Custom Action"}],"subscriptions":[{"handler":"allHandler","name":"switch","type":"DEVICE","typeId":238,"typeName":"TestSwitch","filter":"true"}]}}}