Set Entity value in expression?
-
I get that, but the power_switch service only has on or off. I am trying to set it from a stored variable, so i don't know if it is on or off to begin, hence my attempt to set it via the SwitchPower1.SetTarget.
@sebby I'm adding
set
topower_switch
as we speak. Will be in the next build.To set from a stored variable, use a substitution in the variable value:
${{ expression-or-variable-name }}
-
I did this exact same thing within Reactor and it became more trouble than it was worth and ultimately removed that rule. A very quick recap of the way I had it was:
Conditions (now triggers):
-- AC is ON
(AND)
-- Motion sensor tripped
Activity (now Reaction):
IF TRUE:
-- GetLoadState of device (entity) and set that to a non-defined variable.
-- Turn the fan on to XX%.
IF FALSE:
-- Turn fan to {variable}%Now how it became more trouble than it was worth probably could have been solved my adding an additional condition/trigger. If I walked into a room and then back out, but the AC was on, the fan would turn on. No sense in having the fan on if nobody was in the room. Thinking back, I would add that Motion has been detected and needs to remain detected/tripped for 120 seconds. (Assuming that your motion sensors reset in less than 120 seconds)
-
-
The
x_vera_device.set_variable
action is the same asluup.variable_set()
on Vera -- it sets the value of a state variable on the device. The service would be a Vera service ID. This is not what you want for turning a switch on or off. You cannot, in MSR or on Vera/Luup, turn a switch on or off by setting a state variable. You have to use an on/off action.I just uploaded the new build to latest (21218). This has a
power_switch.set
action that takes a boolean, as you are trying to do here. Update to the new latest build, then in your screen shot above, where you havex_vera_device.set_variable
, you will selectpower_switch.set
. It will give you a single parameter in which you can specify a boolean value (e.g. true or false), or use a variable substitution as I posted earlier. -
-
Hi Rigpapa, I updated the build, the variable is a drop-down with only the true/false option and not a variable that can be substituted. do i need to do something else to make it a string entry?
-
@sebby said... (see above screenshot)
Based on your screenshot, it kinda looks like you can't (yet) override the two preset drop-down choices in that menu, in order to insert your own
${{ }}
expression? (I'm not using 'Latest' so haven't tested myself.) -
Whoops! Forgot about that (booleans use a fixed list rather than the generic multi-value path/datalist control)... fix coming...
-
no rush, i was able to work around it by inserting the status of the fans as a number:
{ "Livingroom Fan" : getEntity("vera>Livingroom Fan").attributes.power_switch.state == false ? 0 : 1, "Loft Fan" : getEntity("vera>Loft Fan").attributes.power_switch.state == false ? 0 : 1, "Office Fan" : getEntity("vera>Office Fan").attributes.power_switch.state == false ? 0 : 1 }
then used the SetTarget entity action to turn them on or off.
-
OK. Build 21219 is up, allows expression substitution in boolean.
A couple of other things...
...attributes.power_switch.state == false ? 0 : 1
can be more succinctly written asattributes.power_switch.state ? 1 : 0
- The
performAction()
expression function will perform an action from an expression. If you have an object stored in a variableold_status
that contains data like this:[ { id: "vera>Livingroom Fan", status: true }, { id: "vera>Loft Fan", status: false }, { id: "vera>Office Fan", status: true } ]
, then you can set those statuses in one expression:each d in old_status: performAction( d.id, "power_switch.set", d.status )
-
OK. Build 21219 is up, allows expression substitution in boolean.
A couple of other things...
...attributes.power_switch.state == false ? 0 : 1
can be more succinctly written asattributes.power_switch.state ? 1 : 0
- The
performAction()
expression function will perform an action from an expression. If you have an object stored in a variableold_status
that contains data like this:[ { id: "vera>Livingroom Fan", status: true }, { id: "vera>Loft Fan", status: false }, { id: "vera>Office Fan", status: true } ]
, then you can set those statuses in one expression:each d in old_status: performAction( d.id, "power_switch.set", d.status )
- The
performAction()
expression function will perform an action from an expression. If you have an object stored in a variableold_status
that contains data like this:[ { id: "vera>Livingroom Fan", status: true }, { id: "vera>Loft Fan", status: false }, { id: "vera>Office Fan", status: true } ]
, then you can set those statuses in one expression:each d in old_status: performAction( d.id, "power_switch.set", d.status )
This is exactly what i was looking for! thank you!!!!!! i was looking at the docs and completely glossed over that section...
-
T toggledbits locked this topic on