Possibly Basic - Rotating through a list of devices for control via a remote?


#1

1) Give a description of the problem
What I would like to do seems basic to me but I’m having syntax issues. I’d like to define an array of physical devices (device variable?) and then access the array values through their placement (e.g., devicearray[0]. device array[1], etc.) by incrementing or decrementing another variable that’s used to drive what array element is used to determine what device is actually used to execute an event.

I can do what I want to with a switch setup, but it’s more cumbersome and less optimized than just cycling through an array, from my perspective.

The final setup is to have an Ikea Tradfri remote cycle through 5-6 lights in my basement and control each individually.

2) What is the issue/need?
I’m having trouble determining how to:

  • Pull the value of a specific item from a device array using a variable (eg., how to do ActiveDevice = DeviceArray[{VARIABLE HERE}]).

#2

I have never done an array in Webcore but maybe a for each loop would do what you want?

You can assign multiple devices to a device variable and then a For each loop will execute the same command for each device in that list.

It sounds like maybe you already know this but just in case.


#3

I use the following syntax:

Device deviceList=dev1, dev2, dev3
Device activeDevice
integer myIndex

set activeDevice=arrayItem(myIndex, deviceList)
with activeDevice
   do stuff
end with

#4

Thanks all for the ideas!

So…see the image for what I’m doing. It’s not done - the second array of names is to have the Echo in my basement announce what light you switched to.

Some of the issues I’m having though are:

  • There’s now way to order a device list it seems. So it’s the order you get…which kind of stinks.
  • I’d like to have a few scenes intermixed (e.g., TV Lighting, Movie Lighting, All Off) but I can’t figure out (yet) how to have that work directly with a scene - doing a virtual button I can do. But, again, this is suboptimal without being able to order the device list so all the scenes are ‘adjacent’ to each other.

#5

@necromancyr

First look, your piston looks pretty good.

If you use an expression, you can enter the devices in any order you wish separated by commas.

The key when entering is start with the ‘[’ and then select from the pop-up list. It will insert a ‘:’ which you just delete and add the ‘]’. You can use this to create your device list in any order.


#6

@guxdude

Thanks! This seems to work but I’m having some odd issues - the last two items in a list always seem to merge into one item. So…

  • [Basement TV Lighting],[Basement Movie Lighting],[Basement - Recessed Lights],[Basement - TV Area Lights],[Basement - Sconce Lights],[Basement - Pool Table],[Basement - Bar]

Merges the Pool Table and Bar lights into one statement with an AND ([Basement - Pool Table] AND [Basement - Bar]) when I pull that element from the array to set another variable. And the count is only 6 items. Not sure what’s going on there.

And when I try to pull the name from a pulled off single device (which I need to do to announce it) it’s not working either. Getting the following oddity - note the device I’m pulling has a space at the begining and:
device ActiveDevice: { Basement - Recessed Lights}
string ActiveDeviceName: Device ’ Basement - Recessed Lights’ not found

The first item in the dynamic list works fine. Everyone after that first one has a space at the front that seems to screw things up. I’ve tried it with and without the colon left in (so [Device :] and [Device]). Same issue both ways.


#7

Very strange. I just did a quick test and don’t see either issue. I put 7 devices in a list and when I log to console, it does put an ‘and’ between the last two but when I do count(deviceList) I get 7. Also, when I convert to string (I just tried item 1 which is the second element) I don’t get a space. Perhaps post your latest piston and I will take a look.