Set Entity value in expression?
-
I can't see anything in the screen shot, it's too low res.
You have to run an action to set the state of a device. Attributes are generally echoes of device state, but you don't modify them directly, just like on Vera (setting a state variable on Vera doesn't change the device, running an action changes the device and updates the state variable).
@toggledbits said in Set Entity value in expression?:
I can't see anything in the screen shot, it's too low res.
You have to run an action to set the state of a device. Attributes are generally echoes of device state, but you don't modify them directly, just like on Vera (setting a state variable on Vera doesn't change the device, running an action changes the device and updates the state variable).
Gotcha, and thanks for the explanation. I guess the question would be, is there a way to trigger an action from an expression? Also, kind of related, but what service would i use in set_variable in order to act on x_vera_svc_upnp_org_SwitchPower1.SetTarget? i've tried x_vera_svc_upnp_org_SwitchPower1, vera_svc_upnp_org_SwitcPower1, svc_upnp_org_SwitchPower1 and all combinations i could think of.
-
Generally speaking, you should use the
power_switch
service instead of thex_vera_svc...
extension service whenever possible. The extension services are meant to be used only when the general services don't provide the function you need.I still can't read your screen shot. When you make the screen shots, try copying only the area with the data fields on the left, and leave off the buttons on the right. This will exclude a lot of unnecessary pixels from the screen shot and improve the overall resolution (reduce downsampling), and make is smaller to post, which is friendlier for the forums as well.
-
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