[MSR] Feature request: For Each action on arrays/groups
-
I have a couple of situation where I'm using code to iterate over an array (ie: climate entities, lights) to operate them in group, and repeat until every one has done what it needs to do.
It will be very cool to have a For Each command that could iterate visually on the array, so I could continue to define it visually. Pseudo UI, so it's easier to explain:
I'm ok with devices being of type
Entity[], loaded via a script block, or with Dynamic Groups (but, in my specific case, this list is know at runtime only).I know it's not trivial, but one may dream
Thanks @toggledbits ! -
DynamicGroupController has the ability to enable actions on the group that pass through to the device in the group (i.e. if you have a group of dimmers, you can set them all at once by sending
dimming.setto the group). Does not that fully address your need? -
yes. I know about DynamicGroupsController and I'm using it in other situations (dead zwave devices, battery low, etc). Problem is that this list is dynamic, ie based on other external conditions (are guest over? is christmas? etc). I tried, but I'm back at code, unfortunately.
EDIT: anyway, if I want to send the command, let's say, only to on devices in a group, I have to use code. Correct me if I'm wrong, unless I create two separated groups (one with on and one with off devices), but this seems messy.
-
yes. I know about DynamicGroupsController and I'm using it in other situations (dead zwave devices, battery low, etc). Problem is that this list is dynamic, ie based on other external conditions (are guest over? is christmas? etc). I tried, but I'm back at code, unfortunately.
EDIT: anyway, if I want to send the command, let's say, only to on devices in a group, I have to use code. Correct me if I'm wrong, unless I create two separated groups (one with on and one with off devices), but this seems messy.
@therealdb said in [MSR] Feature request: For Each action on arrays/groups:
Correct me if I'm wrong, unless I create two separated groups (one with on and one with off devices), but this seems messy.
You can send
power_switch.onandpower_switch.offto the same group, you don't need two groups.Help me understand the problem more fully. Let's get into detail here. How are you creating the groups now?
-
That's one case:
I want to send the ON/OFF command again, until every device in the group is ON/OFF. I have a count just to avoid an infinite loop.
It works, but it's not ideal to send a command to a device already on (or off) - because I want to avoid unnecessary traffic. There's no way to filter the group devices. I know I could write a script and do it, but the point here is to avoid a script if possible.
devices_status = false, counter = counter + 1, finalStatus = true, each id in getEntity('groups>ac_casa1').attributes.sys_group.members: do v = bool(getEntity( id )?.attributes?.power_switch?.state), #print("!!!!!!DEBUG" + getEntity( id ).name + " - " + v + " - " + devices_status + " - " + finalStatus), devices_status = (v == finalStatus) && devices_status doneEDIT: also, there's no way to delay in code, so I need 2 scripts anyway, to send on/off and then set the mode. Thanks.
-
That's one case:
I want to send the ON/OFF command again, until every device in the group is ON/OFF. I have a count just to avoid an infinite loop.
It works, but it's not ideal to send a command to a device already on (or off) - because I want to avoid unnecessary traffic. There's no way to filter the group devices. I know I could write a script and do it, but the point here is to avoid a script if possible.
devices_status = false, counter = counter + 1, finalStatus = true, each id in getEntity('groups>ac_casa1').attributes.sys_group.members: do v = bool(getEntity( id )?.attributes?.power_switch?.state), #print("!!!!!!DEBUG" + getEntity( id ).name + " - " + v + " - " + devices_status + " - " + finalStatus), devices_status = (v == finalStatus) && devices_status doneEDIT: also, there's no way to delay in code, so I need 2 scripts anyway, to send on/off and then set the mode. Thanks.
@therealdb said in [MSR] Feature request: For Each action on arrays/groups:
There's no way to filter the group devices.
This is a comment I'm curious about, because there actually is a way to filter a group. But that may not be much help on its own without a couple of additional changes. I am working on parameters for reactions. I think that will address the need for different scripts. Delays in scripts also came to mind when I did the
alarm()function, so that's a distinct possibility in the near future. I'm bookmarking this thread so that the work I'm doing on reactions trends toward making this easier. Thanks for the detail!










