Passing expression variables between rules
-
Is there a way to get a variable from a rule into an expression of some other rule?
Just like what Vera Reactor did with the Export button then allowing you to reference that variable in another rule set. I'm guessing there's a function like there was in vera getstate()? Thanks
Hopefully my question is clear, it's late
-
I've found I can see variables from other rule sets within the rules themselves, via the "Variable Value" condition type. Just need to figure out now how to get to this in an expression.
@maddios said in Passing expression variables between rules:
I've found I can see variables from other rule sets within the rules themselves
That's a bug. Rule-based expressions are only in scope within the rule that defines them (just as local variables in almost any language are available in the scope that defines them). For the same reason, you cannot refer to variables in other rules from an expression.
-
Ah, so I can't copy over some of my vera reactor logic.
How do I reference global variables within rules? do they just work like local variables? or is there some sort of global scope object I have to use?
I'm guessing I can pass data between rules by using a global expression
Also, how do you recommend structuring one of your old guides where a bathroom humidity sensor samples humidity into a dictionary then calculates averages and such. then another vera reactor was consuming that average and checking if it's above/below current humidity and turning a fan on off?
Thanks
-
You refer to global variables the same way you refer to local ones, as you would in most computer languages.
-
You refer to global variables the same way you refer to local ones, as you would in most computer languages. You simply refer to it by name. If the name is not in local scope, the parent scope (which is the global scope in Reactor) will be searched for the name.
Ref: https://reactor.toggledbits.com/docs/Expressions-%26-Variables/
-
Not sure if anyone's suggested this, but it would be great if the expressions could be grouped. Like for me I have tons of variables for my thermostats, tracking all sorts of house parameters which all of the thermostats share. Would be great to have an object to contain them all so I don't have all of the expressions mixed up. something like thermostat.first_floor.heat_current_setpoint would be really cool.
-
T toggledbits locked this topic on