Pass device list as arguments?


#1

1) Give a description of the problem
I can not figure out how to pass a device list as an argument from piston A into piston B and have piston B be able to act on those devices as devices, and not have the device list passed as a string. Can anyone share a working example of passing devices as argument from one piston to another and doing operations with that device list (e.g. more than just printing out piston state info with the device list in piston B)?

2) What is the expected behavior?
Device list passed as argument from piston A to piston B and piston B treats the argument as a device list and not a string.

3) What is happening/not happening?

4) Post a Green Snapshot of the pistonimage
n/a

5) Attach any logs (From ST IDE and by turning logging level to Full)
Some sample problems in various methods I’ve tried:

An error has occurred while subscribing: groovy.lang.MissingMethodException: No signature of method: java.util.ArrayList.startsWith() is applicable for argument types: (java.lang.String) values: [@])

or

+300ms ║║Comparison (error) Device '[:18b776bbd6f14aac8ea57f2fb8e43b53:, :bd35efa8dfd2b841c6965dc8e5286f61:, :cacaf821c48932d6b93929d10a47c705:]' not found is (string) off = false (1ms)


Echo Speaks piston with variables
#2

What are you trying to accomplish here in the end? If you could give us more details on what you are trying to accomplish then there might be other ways to get where you are going.

I don’t think you can pass a list of devices to another piston and have that piston act on it. @bangali can you confirm?


#3

confirming. no can pass devices to another piston.


#4

Thanks for the help @c1arkbar and @bangali . Passing devices between pistons would be a nice feature to have if technically possible. Or is it too complicated? I’ll open up a feature request if it’s possible, I would love to see this added.

What I am trying to accomplish is: I have 15 different pistons for lights in individual rooms. The pistons are all pretty complicated, yet they all share about 90% of the same code. The developer in me hates that I’m duplicating so much code and when I want to make a change to the templated piston structure I have to change 15 pistons. So I’m trying to create a single piston that is basically a ‘light runner’ that I can pass in a bunch of variables about light devices, on/off state, level, temperature, color, how long to keep on, modes and times to turn on/off in, etc. and then convert each of the 15 individual room pistons into much smaller pistons that simply detect motion events for the room, set some argument variables based on mode/time/etc, and pass those arguments to this ‘light runner’ piston.

I guess as a workaround in the ‘light runner’ piston I can set up an arbitrary list of room names and associated light devices as an associative array (if I can figure out how to do that) and then use a switch statement or for each loop to compare against a string argument to figure out which room I’m working with, but, I’d rather interact with the devices directly and avoid that intermediary step of maintaining an arbitrary list of room names that needs to be updated every time i add lights to a new room in my house.

Does that make sense?


#5

It is making sense. Gonna bounce some ideas.

If your rooms pistons are only needing to say who is calling then you could do the switch case statement. Just have the rooms send a number instead of a full name.


#6

define all the devices to act on only in the light runner piston as different group names. then from each of the caller pistons pass in the group name and other variables as arguments to the light runner piston. in the light runner piston use the group name to decide which devices to act on and act on them as needed based on the remaining arguments.

you will also be creating a SPOF thats likely to choke depending on the number of callers. but thats a second order problem. :wink:

or check this out:

https://community.webcore.co/t/rooms-manager-smartapps-and-rooms-occupancy-dth-now-with-support-for-rules/1813/


#7

Thx @bangali. That’s a really good point on the singular point of failure, so I’m abandoning this direction since it’s not architecturally the best. The single light runner also caused other tricky issues and unneeded complications for me with things like trying to track state of switches, like remembering whether an individual switch was turned on programmatically or physically. So, meh.

I’ve finally implemented your Room Manager and Occupancy DTH, which I had avoided for awhile since it’s actively updated so often, but am keeping my light routines in webcore because of their complexity. I am in process of changing all my light routines to be based on occupancy events.

Thx for the help!


#8

makes sense. the way i look at it most common actions should be supported in rooms manager. for one of things wC is best.


#9

TLDR; Do I need to open a PR to get this in?

I was trying to use a similar approach for managing multi room assignments for a single device. We have a new modern-ish open layout home and we have some blurred lines between some rooms. I am then using a given rooms device status to determine the entire room for a separate switch.

Device A and B are in the kitchen
Device B and C are in the Dinning room

If someone turns on device B it shows kitchen and dinning room in use.

I want to create a reusable piston(use as a common method/class) to then set status of a given room based on a list of devices I have assigned in that group.

Ill go about doing it via a PR if needed, just couldnt tell by where things left off if anyone was still interested in this functionality?

I’m a recovering java developer, please forgive me father for I have sinned :frowning: but I love me some good util methods/pistons


#10

I would give an arm and a leg for this feature. When I try to send device variables now (as a list,) it just processes them as the UID of the device, and there’s no function to convert back into actual devices. That’s the missing piece here. The data is being sent, but not parsed.

Just like OP, I have 20+ lighting automations that are far too complex for general community templates/apps. Every time I want to make an improvement, I have to modify each of them. I made this SLIGHTLY easier by using local variables, but it’s still a nightmare.

If I could just build 20 caller pistons that trigger their own instance of a runtime piston, all my problems would be gone.

Here’s an example of all the data my pistons need right now to function properly.


#11

This can be done:

webCoRE main app needs have been given permissions for the devices

This example a sender piston sends the device as an argument to the receiver piston.

sender:

and receiver:

15%E2%80%AFAM