Just started with C-7 on 2.2.4.158 and am trying to work in RM with variables to capture the front porch light level setting, change it to 100 for 2 minutes after the door is opened, and then reset it to the original value for the rest of the evening. Can't seem to find any description or examples of how this might be done. Hints, anyone, as to where I should be looking?
First, click the "Create, Delete, or Set Local Variables" button/link in your rule (the rule you created or will create to do the rest of your actions, since it's a local variable specific to this rule). Create a variable here, and call it whatever you want--e.g., oldVal
. Because the value you need to store is usually a whole number from 0-100, the "Number" type should work. If you have an odd device that reports fractional level values too (or still want to for some reason, though this may not work with all devices when setting the value), you can use "Decimal" instead. It should look something like this when you're done:
Then, proceed with creating the rest of your rule. Something like this should work for what you described:
That first action might be a bit difficult to figure out if you've never done something like that before. What you want to do is set your local variable to the the value of a device attribute--in this case, the "level" attribute for your dimmer or bulb. Here's what creating that action looks like:
Finally, for the last action, you can just type %oldVal%
(or, generally %yourVariableName%
as Rule Machine tells you that you can do) for the level--or anywhere that most free inputs are accepted in the UI. The final screenshot looks abit different, but creating this action would look like this:
Finally, something else you may want to consider: what of the bulb was off before you started? Do you want it to turn back off? If so, you'll want to look at the switch
attribute, too. This can have two (string) values, "on" or "off". It is independent of level
, which will generally show the last know level of the device when it was on, regardless of whether it is currently on or off. So, if this is something you care about, you'll have to handle that somehow, too. One way is to use another local variable and a conditional action to either turn it off or set the level based on the value of that variable instead of the current action that just sets it to the saved level. I'll leave that as an exercise for the reader but will be happy to help if you want it.
Hope this helps!
Many thanks. Works great. I was close with my fooling around, but as you say "That first action might be a bit difficult....." Indeed, it was. Always learning with Hubitat!
I know this is an old thread, but I have a related question and did not want to start a new one. Isn't this what Capture and Restore are for? I am seeing some reliability issues with capture/restore, but it seems a lot easier than setting variables for the 20 lights I am manipulating.
Please advise if Capture/Restore is known not to be reliable, and I will go the local variable route.
Capture and restore should work; off the top of my head, I can't think of why I wouldn't have suggested that above, aside from the fact that the poster came looking for help on variables specifically.
The only thing that does throw people off from time to time with capture and restore is that the end state will be the same as the start state, but any changes you make in the meantime may not be accounted for. For example, if you have a color bulb and started with it off, then turn it on and change it to red, a restore will just turn it back off. It will not "prestage" the fact that it may not have been red before, so if you just use "On" to turn it on again later, it won't (necessarily) come back to whatever color you had then. Similar with level, and really anything if the bulb was off before. There are workarounds for that, too, but it probably isn't what you came here for.
Where can I find this Capture and Restore? I don't see it on the Apps.
"Capture and Restore" is not an app. It is the name of two actions in Rule Machine:
https://docs.hubitat.com/index.php?title=Rule-5.1#List_of_Actions