Dynamically add Devices to a Global Variable


#1

It would be nice to be able to assign devices to a variable using an API call (i.e. https://api.smartthings.com/v1/devices?capability=battery)

then use devicelist = $device.items.label which produces this result

image

Now when I try to create a device it does this

image

There has to be an easier way to load devices into a device variable so you can select specific devices dynamically to a Global Variable and can run nightly to pickup any new devices so you do not have to add them manually to all your pistons. If you had 50 pistons you would have to add a new device to every one of them

If there is a way to do this already please let me know -


#2

A piston “subscribes” to devices during the save process. You can’t slip a new one in undetected and expect it to be utilized.


#3

yes, also pause / resume cause subscriptions to be re-evaluated.

if you know that you are updating a global variable, you should be able to programmatically issue pause/resume (except on yourself as a piston)


#4

This is correct, however there is a semi-automated workaround.

Say you have a global device variable called @allDevices, containing the list of all your devices, and you have a piston that subscribes to @allDevices, when you hit save, the piston pulls the device list from the global and subscribes to each device. If you subsequently edit @allDevices, the piston wont be updated with new subscription until it is opened and re-saved.

But, if you use a second piston to pause and then resume your piston, this also forces a re-subscribe.

  1. So put your regular device groups into global variables
  2. Build a master piston, that loops through every other piston, (pause, wait, resume).
  3. When you add a new device to ST, add it to webCoRE, add it to relevant globals, then run the master piston.

The above still needs some manual input, but better than updating 50 pistons one-by-one.


#5

Beat me to it lol… I need to type faster / less


#6

I really don’t want to ever have to add any devices ever again accept when I add new devices. I just need to know how to parse through alldevices global variable and pull out devices with a capability to set those devices in another global variable so I can then use it in all kinds of pistons dynamically. The pause resume will work great once I know they will be added as individual devices and not a string.


#7


#8

Wow! That solved my problem. Thank you so much.

Jared