Rule Machine - Custom attribute - Increased by x amount

hi all,

Is there a way to have an IF condition be something like this:
Device A = number value
Number value could go from 1.2 to 1.4

Condition:
If Device A increased by .2
THEN
DO SOMETHING

From what i can tell the only conditions are if >= etc or "Increased" but the value can't be set as to how much it increased by .

has anyone worked out how to do this by any chance?

thank you

Store the "previous" (then-current--so really, saving it for the next execution) value to a local variable of the appropriate type. This should probably trigger off of any time the sensor value changes, not just any time it increases. In your actions (before this--so you still are dealing with the "old" value from the variable and haven't yet overwritten that with the current value), make a comparison with that variable and the current sensor value as part of a conditional.

This is what that would look like:

If you've never written a conditional with a comparison like that before, you may be wondering how to construct one. Here is what it looks like when I was editing it after choosing the appropriate options:

Similarly, that last action is setting the local variable (which I defined before starting the rule--see that bottom section in the final view, the first screenshot) to the value of a sensor, like this:

Setting 'oldValue' variable to temperature sensor value

Finally, because Rule Machine as of hub firmware 2.2.4 gives us the ability to export/back up/share rules, I'm not sure if anyone will actually find this format helpful for sharing, but here it is if it actually works. :slight_smile:

Rule Machine JSON export (expand to view)

{"deviceReplacements":{"2051":{"deviceName":"TEST Virtual Temperature Sensor","deviceLabel":null,"deviceTypeName":"Virtual Temperature Sensor","deviceTypeNamespace":"hubitat"}},"appReplacements":{"2025":{"appTypeName":"Rule-4.0","appTypeNamespace":"hubitat","appName":"Rule-4.0","appLabel":"Rule - Increase By TEST","parentAppTypeName":"Rule Machine","parentAppLabel":"Rule Machine","singleInstance":false}},"appData":{"2025":{"state":{"actionListMain":["1","2","3","4"],"connectors":{},"parens":{"1":0},"actionDone":true,"hasRuleAct":false,"selectActionsParams":{"thisStr":"Main","label":"Rule - Increase By TEST"},"editCondIf":null,"lvt.oldValue":"Decimal","usesTime":false,"inIf":null,"trigCustoms":[],"repeating":[],"capabDone":true,"lv.oldValue":65.0,"locationBlocked":[],"inRepIf":null,"ndx.false":4,"lvList":["oldValue"],"ruleNdx":2,"firstR":{"1":false},"timeTriggers":[],"allVarsO":["gvarStringTest","gvarTest","oldValue"],"actLabelIndent":"","howManyT":3,"subscribedVariables":[],"certainTimes":[],"prevState":{"PB":"true","2051":72},"eval":{"1":[1]},"capabstrue":{"1.true":"Temperature of TEST Virtual Temperature Sensor(<span style='color:black'>72</span>) *changed* ","2.true":{}},"lastEvtDate":"19-Nov-2020","actionsMain":{"1":{"wait":null,"delay":"","modes":{},"method":"getIfThen","indent":"","rule":1,"label":"IF (Temperature of TEST Virtual Temperature Sensor(<span style='color:black'>72</span>) is >= oldValue(<span style='color:black'>65</span>) +0.2<span style='color:green'>(T)</span><span style='color:green'> [TRUE]</span>) THEN\\n","cond":0},"2":{"wait":null,"delay":"","modes":{},"method":"getLogMsg","indent":"\\t","rule":0,"label":"\\tLog: 'Do something here instead of logging!'\\n","cond":0},"3":{"wait":null,"delay":"","modes":{},"method":"getEndIf","indent":"","rule":0,"label":"END-IF\\n","cond":0},"4":{"wait":null,"delay":"","modes":{},"method":"getSetVariable","indent":"","rule":0,"label":"Set oldValue to TEST Virtual Temperature Sensor Temperature\\n","cond":0}},"nestedInIf":[],"actNdx":5,"installed":true,"lastEvtValue":0,"waitEvents":[],"private":"true","gvList":["gvarStringTest","gvarTest"],"hasDevice":null,"ndx.true":2,"editingRule":0,"allVars":{"gvarStringTest":{"val":"My new value","type":"String"},"oldValue":{"val":65.0,"type":"Decimal"},"gvarTest":{"val":null,"type":null}},"simpleCond":false,"nestedRepIf":[],"lastEvtTime":"10:10 PM","condOper":"cond","cutAction":[],"nestedLabel":[],"paramNdx":1,"varUseList":{},"waitCondNdx":1,"token":1,"capabsfalse":{"1.false":"Temperature of TEST Virtual Temperature Sensor(<span style='color:black'>72</span>) is >= oldValue(<span style='color:black'>0</span>) +0.2"},"timeTriggersW":{},"timeFormat":"hh:mm a","waitConds":[]},"appSettings":[{"deviceList":null,"multiple":false,"name":"tCapab1","type":"enum","value":"Temperature"},{"deviceList":null,"multiple":false,"name":"tCapab2","type":"enum","value":""},{"deviceList":null,"multiple":false,"name":"actionDone","type":"button","value":""},{"deviceList":null,"multiple":false,"name":"valCapabMain.4oldValue","type":"enum","value":"Temperature"},{"deviceList":null,"multiple":false,"name":"actSubTypeMain.3","type":"enum","value":"END-IF"},{"deviceList":null,"multiple":false,"name":"pausRule","type":"button","value":""},{"deviceList":null,"multiple":false,"name":"actSubTypeMain.4","type":"enum","value":"Set Variable"},{"deviceList":null,"multiple":false,"name":"actSubTypeMain.1","type":"enum","value":"IF (conditions) THEN"},{"deviceList":null,"multiple":false,"name":"actSubTypeMain.2","type":"enum","value":"Log a Message"},{"deviceList":null,"multiple":false,"name":"cancelLv","type":"button","value":""},{"deviceList":null,"multiple":false,"name":"cond","type":"enum","value":null},{"deviceList":null,"multiple":false,"name":"insertAct","type":"enum","value":""},{"deviceList":null,"multiple":false,"name":"not1","type":"bool","value":"false"},{"deviceList":null,"multiple":false,"name":"state1","type":"decimal","value":"0.2"},{"deviceList":null,"multiple":false,"name":"goof","type":"button","value":""},{"deviceList":null,"multiple":false,"name":"varType","type":"enum","value":""},{"deviceList":null,"multiple":false,"name":"editLv:oldValue","type":"button","value":""},{"deviceList":null,"multiple":false,"name":"tstate1","type":"text","value":"*changed*"},{"deviceList":null,"multiple":false,"name":"isVar1","type":"bool","value":"true"},{"deviceList":null,"multiple":false,"name":"refreshActions","type":"button","value":""},{"deviceList":null,"multiple":false,"name":"myVarsMain.4","type":"enum","value":"oldValue"},{"deviceList":null,"multiple":false,"name":"hasAll","type":"button","value":""},{"deviceList":null,"multiple":false,"name":"cancelCapab","type":"button","value":""},{"deviceList":null,"multiple":false,"name":"editToken","type":"button","value":""},{"deviceList":null,"multiple":false,"name":"isDev1","type":"bool","value":"false"},{"deviceList":{"2051":null},"multiple":true,"name":"rDev1","type":"capability.temperatureMeasurement","value":null},{"deviceList":null,"multiple":false,"name":"updateV","type":"button","value":""},{"deviceList":null,"multiple":false,"name":"numOpMain.4oldValue","type":"enum","value":"sensor value"},{"deviceList":null,"multiple":false,"name":"deleteLv:oldValue","type":"button","value":""},{"deviceList":null,"multiple":false,"name":"origLabel","type":"text","value":"Rule - Increase By TEST"},{"deviceList":null,"multiple":false,"name":"ReltDev1","type":"enum","value":"*changed*"},{"deviceList":null,"multiple":false,"name":"eraseRule","type":"button","value":""},{"deviceList":null,"multiple":false,"name":"varV","type":"decimal","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":"runAction","type":"button","value":""},{"deviceList":null,"multiple":false,"name":"delete","type":"enum","value":""},{"deviceList":null,"multiple":false,"name":"valOffsetMain.4oldValue","type":"decimal","value":"0"},{"deviceList":null,"multiple":false,"name":"locVar","type":"text","value":""},{"deviceList":{"2051":null},"multiple":true,"name":"tDev1","type":"capability.temperatureMeasurement","value":null},{"deviceList":null,"multiple":false,"name":"rCapab1","type":"enum","value":"Temperature"},{"deviceList":null,"multiple":false,"name":"actionCancel","type":"button","value":""},{"deviceList":null,"multiple":false,"name":"relVar1","type":"enum","value":"oldValue"},{"deviceList":null,"multiple":false,"name":"logmsgMain.2","type":"textarea","value":"Do something here instead of logging!"},{"deviceList":null,"multiple":false,"name":"RelrDev1","type":"enum","value":">="},{"deviceList":null,"multiple":false,"name":"editAct","type":"enum","value":""},{"deviceList":null,"multiple":false,"name":"comments","type":"textarea","value":""},{"deviceList":null,"multiple":false,"name":"cutAct","type":"enum","value":""},{"deviceList":null,"multiple":false,"name":"createCon:oldValue","type":"button","value":""},{"deviceList":null,"multiple":false,"name":"varValue","type":"decimal","value":""},{"deviceList":null,"multiple":false,"name":"moreVar","type":"button","value":""},{"deviceList":{"2051":null},"multiple":false,"name":"valDevMain.4oldValue","type":"capability.temperatureMeasurement","value":null},{"deviceList":null,"multiple":false,"name":"delayActMain.2","type":"bool","value":""},{"deviceList":null,"multiple":false,"name":"delayActMain.4","type":"bool","value":""},{"deviceList":null,"multiple":false,"name":"actTypeMain.2","type":"enum","value":"Send, Speak or Log a Message, Send HTTP Request"},{"deviceList":null,"multiple":false,"name":"actTypeMain.1","type":"enum","value":"Conditional Actions"},{"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":"actTypeMain.4","type":"enum","value":"Set Mode, Variables or File, Run Custom Action"},{"deviceList":null,"multiple":false,"name":"actTypeMain.3","type":"enum","value":"Conditional Actions"},{"deviceList":null,"multiple":false,"name":"actTypeMain.5","type":"enum","value":""}],"subscriptions":[{"handler":"allHandler","name":"temperature","type":"DEVICE","typeId":2051,"typeName":"TEST Virtual Temperature Sensor","filter":"true"}]}}}

Hope this helps!

4 Likes

Thank you will give it a go. Really appreciate the detail