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
performAction()
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). -
@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
performAction()
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).I don't know what other words to use to describe Reactor! If I had read the entire manual, I wouldn't have posted about Group Action. Now that I've read everything that DynamicGroupController can do, it's impressive.
I was definitely one of the enthusiasts when this was implemented, and now with this option to take actions, it's wonderful. It's going to simplify a lot of rules for me.
Thank you very much @t. Every day I'm surprised by the things that can be done in Reactor.
-
I use script action a lot with arrays of devices defined in a variable. Very handy for when you want to do it without messing with config files.
This feature is really fantastic. I'm changing a lot of rules for it.
Now you could help me with this one. I need to know if the button is stuck, i.e., if it hasn't returned to zero, and force a refresh.
The selection rule is already correct, but now I can't understand how to define the Group Action to apply x_hubitatRefresh.refresh.
"dgc_PushableButton_N0": name: DGC PushableButton Not 0 select: - include_capability: - x_hubitat_PushableButton - exclude_entity: - "hubitatC8>2672" # Alarm Sirene - "hubitatC8>2100" # Remote Adriane - "hubitatC8>420" # Remote Quad group_actions: x_hubitat_Refresh filter_expression: > entity.attributes.x_hubitat_PushableButton.pushed != 0 and entity.attributes.x_hubitat_PushableButton.pushed != null
Could you help me with your experience?
This is what I want to change.
Only apply refresh, to the button selected by the DynamicGroup.
Or in this case is Script that I need to create?
Thanks.
-
Just send the refresh command to the group.
-
Just send the refresh command to the group.
Sorry, I don't understand, it doesn't work the way it's written below.
What information do I have to assign to grup_actions, or is it something else?
Thanks
Wilson -
I apologize... yes, because that group is fully dynamic (its contents are determined by filter expressions), the range of its actions cannot be determined at startup, so in this instance, you will have to use a Script Action:
each id in getEntity("groups>dgc_PushableButton_N0").attributes.sys_group.members: performAction( id, "x_hubitat_Refresh.refresh", {} )
-
I apologize... yes, because that group is fully dynamic (its contents are determined by filter expressions), the range of its actions cannot be determined at startup, so in this instance, you will have to use a Script Action:
each id in getEntity("groups>dgc_PushableButton_N0").attributes.sys_group.members: performAction( id, "x_hubitat_Refresh.refresh", {} )
@toggledbits said in Set Reaction > Script Action:
each id in getEntity("groups>dgc_PushableButton_N0").attributes.sys_group.members:
performAction( id, "x_hubitat_Refresh.refresh", {} )EXCELLENT, IT WORKED!!! Thank you very much.
I was already working on this script, based on the example at the beginning of this discussion, but I was using performOnEntity.
each id in getEntity('groups>dgc_PushableButton_N0').attributes.sys_group.members: performOnEntity(id, 'x_hubitat_Refresh.refresh')
Thank you very much for your help. Another lesson learned, and I am already putting more optimizations into practice.