Rule Machine Global Variables

Hello, in future releases will there be functionality added to allow for expressions to set the global variable values along with ability to use expressions in comparisons to drive specific actions. An example I'm currently looking at...quick departure and return lets say to grocery store to grab something:
When leaving the house you capture the current state of multiple switches along with the date, time, and of the capture. Your usual departure actions then trigger to lock down the house and setup your normal configuration for the time of day and mode. You return 45 minutes later and would like the house to return to the state it was when you left.
With global variable and a few compares could be done to make this happen. Maybe your threshold is if you exit and return in less than an hour and the mode hasn't changed return house to state it was on departure using captured states. If greater than an hour or mode changed follow normal arrival flow for the time of day and mode.
I live alone so don't need to take too many variables into consideration accounting for other people.
Just started looking into the capturing functionality and the ability to make something along these lines happen. hit the breaks when not being able to figure out how to set and then compare the variables.
I'm very new to Hubitat and maybe this is something another App should be used for. I'm trying to stick with the built in apps and haven't found anything I can use to make this happen yet. I'm sure someone is probably doing this already somehow but wanted to ask about expressions and comparisons of global variables. As others have stated Global Variables are still in beta so just seeing if this may be in consideration for future functionality. Thank You!

1 Like

Messed around with this long enough and figure out how to make this happen Groups & Scenes, a virtual switch, and several rules. Would like to leave the question about expressions and evaluation of variables open. Thank You.

I would like to do something similar but with speakers, so how did you manage it?

Adding expressions of global variables is not planned for now.

How do you create a Global Variable? I've looked in Rule Machine, but I don't see the option. I'm running Hubitat version 2.0.4.118 on my hub and there aren't any updates available. Are GV's available in the software version that is running on my hub? Thanks.

Bruce, I take it the gv fix didn't make it on 2.0.6?

If you mean triggers, that was fixed.

1 Like

@BorrisTheCat,
I spoke a little too soon on this. It works on the room I tested with but have two issue that i haven't been able to resolve yet...it will set the devices back to the state they were when departing but have the to problems listed below.

  • Hue lights turned on or off with The Hue Dimmer Remote are not registering changes in Hubitat. If turned on with the remote the status in Hubitat remains as off. No actions initiated with the remote are registering.
  • When the scene is activated the log is showing contuse and repetitive activity from the affected devices and am only able to stop it by rebooting the hub.

This is what i've done:

  1. Created a virtual switch with three rules.
    • Trigger turns the switch on when Presence is changed to "not present"
    • Trigger turns switch off 60 minutes after it is turned on
    • Trigger turns switch off on mode change
  2. Created a Scene with devices to control / capture when departing
    • Scene name is "Capture at Time of Departure"
    • Selected color and color temperature bulbs, dimmers, and switches
    • Click to set: "Select button to push upon scene activation"
      • This is initially left with no selection. After creating the scene went back in and updated this option selecting the button named the same as the scene "Capture at Time of Departure". Button number then set to "1".
    • Set scene transition time to 5 seconds
    • "Ignore activate switch off?" is left Off
    • "Create capture device" is turned On
  3. Action created to push the capture button that is created by the scene: device name defaulted to "Capture at Time of Departure Capture". Device type shows as "Scene Activator" and the DNI is shown as "Capture_298". I left these exactly as they defaulted when created.
  4. Two Triggers run when departing.
    • The first runs with its action running item #3 above.
    • The second runs with a 15 second delay running my normal departure actions based on mode and time of day. 15 second delay is to give the actions in the first trigger time to complete.
  5. Trigger Rule created for Presence change to "present"
    • If the virtual switch in item #1 is "On" the button created in item #2 "Capture at Time of Departure" is pushed to activate the scene.
    • If the virtual switch in item #1 is "Off" the normal arrival process is followed for the mode and time of day.

I haven't found anything on why the hue dimmer changes are not registering in Hubitat. I hand't notice this issue until working on trying to make this process work. Regardless of making this rule happen I need to figure that one out.

Also have no idea what is causing the looping action, or what looks to be a looping problem, and haven't been able to find anything in the log to start narrowing the problem down. I've taken it down to a single device to capture and test with and only see the continual log update with the action that occurs with the selected device. IE. "Living Room Cans was turned off". Not sure if this is happening due to options I have setup wrong in one of the Rules / Triggers / Actions or if something needs to be turned off in the process and I'm missing it. The devices return back to the state they were in when departing and capturing, so seems like the process is close to working but am missing something to stop the looping / repetition.

I'm still very new to Hubitat so wouldn't doubt i'm missing something how Rules Machine and Scenes work. Hope this helps you and if you have any ideas or are able to get this working I'd appreciate any advice.

Thank You!

Update:
Was able to get the Hue Dimmers working with updating Hubitat correctly. Turned down logging on everything but a single light used in the capture process to so the log would have very little information other than records pertaining to the departure / capture / arrival processing. Found the button to activate the scene the captured device states are saved in his repeatedly pushed by the Trigger Rule for some reason. Not sure why this is happening yet but the culprit of the problem seem to reside in how the Trigger Rule when arriving back home is processing or it is in the action the Trigger Rule is running.

@bravenel
Thank you for the response!

@bravenel, Are GV like rules - the more the merrier? Or are GV as per webcore, keep them limited?

I want to know if I can remove my virtual switches and convert them to GV's. Not dozens, but maybe 10.

1 Like

There are no significant performance issues with RM global variables. You can create as many as you need.

1 Like

Can you only use GV in conditions and triggers? I was going to use a number GV that was set depending on the mode. Then I was going to use this as the dimmer level or kelvin level of my lights. The idea being I could have a value and implement this in all the rules rather than repeating the same values. So if you want to change the kelvin you currently have for all your lights in a mode you only need to change one rule.

1 Like

This is not possible at present. There has been another request to be able to use GVs for any numeric input. This idea, while it has some merit, is somewhat challenging in the implementation. I'm considering it...

2 Likes

Theoretically you could send the variable value in a web request that's pointed at the Maker API cloud endpoint of your device. It's not local but I think it is doable.

1 Like

I figure I'd pass this along. At least with sharptools, ran into a work around to display a GV. I currently don't use the built in dashboard, so am not 100% sure if can display a chosen attribute for it to work here

then josh came up with a "cleaner" device to use here:

This solution also gave me a means of passing a GV from RM to ST

3 Likes

@bravenel could the global be made with a default value? IE bool already be true? Or a way to set them to value.

I have a trigger rule that have them as a condition of "true" and for true set it to false and false set to true.

So i then needed to do a temp rule to set them to a value.

There was a DTH for WebCoRE that Robin developed for a Value tile. Basically, all it did was stored data for display other places. You should be able to use an attribute tile and an HTTP request to the Maker API to set the attributes in the device. Haven't tried it yet but it should work, unless I'm missing something.

metadata {
 	definition (name: "webCoRE Value Ties", namespace: "SmartThings", author: "Robin Winbourne") {
 	capability "Actuator"
 	capability "Switch"
    attribute "Value1","string"
    attribute "Value2","string"
    attribute "Value3","string"
    attribute "Value4","string"
    attribute "Value5","string"
    command "changeValue1"
    command "changeValue2"
    command "changeValue3"
    command "changeValue4"
    command "changeValue5"
     }
 	tiles {
 		valueTile("Value1", "device.Value1", width: 3, height: 1, canChangeBackground: true) {
 			state "default", label:'${currentValue}'
 		}
 		valueTile("Value2", "device.Value2", width: 3, height: 1) {
 			state "default", label:'${currentValue}'
 		}
 		valueTile("Value3", "device.Value3", width: 3, height: 1) {
 			state "default", label:'${currentValue}'
 		}
 		valueTile("Value4", "device.Value4", width: 3, height: 1) {
 			state "default", label:'${currentValue}'
 		}
 		valueTile("Value5", "device.Value5", width: 3, height: 1) {
 			state "default", label:'${currentValue}'
 		}
 		main(["Value1"])
 		details(["Value1","Value2","Value3","Value4","Value5"])
 	}
 }
 def changeValue1 (param1) {
    sendEvent("name":"Value1", "value":param1)
}
 def changeValue2 (param2) {
    sendEvent("name":"Value2", "value":param2)
}
 def changeValue3 (param3) {
    sendEvent("name":"Value3", "value":param3)
}
 def changeValue4 (param4) {
    sendEvent("name":"Value4", "value":param4)
}
 def changeValue5 (param5) {
    sendEvent("name":"Value5", "value":param5)
}

EDIT: Never mind...you can't send an HTTP request to yourself. DUH! Sorry.
If we had the ability to set parameters for custom commands within the rule itself instead of just when defining the command, that might solve a lot of problems too. Just a thought.

@bravene i think there is a bug in global as conditions.

this seems to work fine and i can see the bool changing correctly

but it doesn't seem to actually update this rule.

so then only true happens to fire this

if i use switches instead it works so must be the globals not passing state.

Sorry, I'm not following what is wrong. Which is failing, setting the variable, or testing the variable in the rule?