Set Reaction > Script Action
-
Hi
Use case: possibility of using a script instead of setting up an action in this way.
If I have a variable that contains the device IDs within the array, could I use a script to execute the powe_switch.on command for the devices in this list?
I tried to understand in the manual (https://reactor.toggledbits.com/docs/Script-Action/) how to use this script feature, but I was unsuccessful. Are there any examples here in the forum of how to use it so I can continue my development?
Thanks.
-
If you already have them i a dynamic group you could perform
power_switch.on
on that group as an Entity action. Or if the devices should do different actions on/dimming etc, you could create a Global Reaction that does what you specify and simply run that as Set Reaction.Edit: I confused Script action with Shell command and have not tried Script action but my guess would be
performAction(entity_id, action, args)
if you really want to do it in a script rather than directly on the group Entity. -
If you already have them i a dynamic group you could perform
power_switch.on
on that group as an Entity action. Or if the devices should do different actions on/dimming etc, you could create a Global Reaction that does what you specify and simply run that as Set Reaction.Edit: I confused Script action with Shell command and have not tried Script action but my guess would be
performAction(entity_id, action, args)
if you really want to do it in a script rather than directly on the group Entity.Thank you for your comment, but I need this to be executed by an action already within the routines I program in Reactor.
So using it within the configuration would not help me.
The selection of devices is indeed within the Dynamic Group, which is perfect, but I was wondering if I could do something like a script, which would require a routine like the one I have today, where I send a list of devices to be turned on, even if they are already on, so I don't have to create a group to analyze the status of each one.
I want to do something smarter.
Anyway, thank you, and let's see if we have any other recommendations.
-
Thank you for your comment, but I need this to be executed by an action already within the routines I program in Reactor.
So using it within the configuration would not help me.
The selection of devices is indeed within the Dynamic Group, which is perfect, but I was wondering if I could do something like a script, which would require a routine like the one I have today, where I send a list of devices to be turned on, even if they are already on, so I don't have to create a group to analyze the status of each one.
I want to do something smarter.
Anyway, thank you, and let's see if we have any other recommendations.
@wmarcolin said in Set Reaction > Script Action:
Thank you for your comment, but I need this to be executed by an action already within the routines I program in Reactor.
@crille is spot on. That's exactly what his suggestion does. Here's a trivial example of what he's saying:
In this case, I'm not using the contents of a dynamic group, I'm just building a list on the fly using
matchEntities()
, but the effect is the same. At midnight every night, this rule turns all things that have thepower_switch
capability off.If your listed switches are in a group, either created using DynamicGroupController, or an expression of some grouping the underlying controller has (Vera and Hubitat have groups and Reactor expresses those as group entities you can use), then you can easily modify this example.
And in fact, you don't even need to do that, because Reactor understands how to do actions on groups, so you can just do one action on the group entity (in a regular Entity Action or by calling
performOnEntity()
in a Script Action) and Reactor will perform that action on all members of the group (so, you don't even need theeach
expression construction).