"Device List" Variable Type

variables

#1

Variable type “Device” exists and works. Why no “Device List” type?

For example, I’d like to create a list of Thermostat devices that I can index through and set using a list of setpoints.


#2

You can choose an array of devices under as a Device variable, and then index through them doing something like this. There may be more efficient ways (probably is) but this is what I’ve been able to come up with and it works reliably:

Green snapshot if you want to import it rather than building from scratch:


#3

There’s also a system variable named $device. So you could say something like:

Define
device SensorList sensor1, sensor2, sensor3, sensor4
end define;

for each $device in SensorList
do


#4

I forgot about that one. Here’s a sample with the loop @Mike1616 is referring to (you can eliminate the ActiveDevice variable in this one):

The only benefit I can think of to the $index loop is you could set the temperatures to an array of temperatures, too. I’d have to mess around with the loop above to see what it uses as a counter. If it uses $index, then both loops would offer the same features.


#5

I don’t have thermostats so I used my dimmers to test this and can confirm the 3 devices listed in DeviceList were set to 72, 71, and 75 respectively:

Import code:


#6

Perfect. And I did want the $index so thanks for this example.


#7

You can also select multiple devices under a device variable. Let’s call the variable thermostatList

You can then call one of them using:

thermostatList[0] - for the first device
thermostatList[3] - for the fourth device

But a for each loop with $device and $index seems to be best for your needs


#8

Yah, I get it. So “Device” behaves like “Device List”. Kinda.


#9

Yes… I’ve never found a use for any of the ‘list’ type variables… especially as they can’t be pre-populated.


#10

I’ve looked at this a couple of times, most recently for a piston where a device list variable would simplify some of my code. But I’ve tried a number of variations and can’t make this work. Am I missing something here?


#11

@bthrock

Sorry, I was wrong in that post above… the name[n] syntax has a different use, not entirely sure what that is now…

Anyway, Try:

arrayItem(0,thermostatList) - for the first device
arrayitem(3,thermostatList) - for the fourth device


#12

@Robin Okay, that’s what I’ve generally been doing. This was just a unique use case where a device list variable would have been a little cleaner and saved me a step or two, but no big deal. Thanks.


#13

I don’t understand…

arrayItem(0,thermostatList) uses a device list variable called thermostatList


#14

@Robin I know, strange case. Here’s a partial and somewhat clumsy effort to explain: Devices in a device variable are generally listed in alphabetic order, but if you want to use them in a different order within, say, a For Loop, you have to either have populate the device variable in a different way or do some other gymnastics to call the devices in the proper order. Hardly impossible, and there are several reasonable ways to approach this, but a device[list] variable would have been a fraction easier and cleaner, especially when creating a piston you might want others to be able to follow and modify easily. Again, not a big deal but when I saw your comment I thought maybe I’d missed something with ThermostatList[n].


#15

Looking about, I thing variableName[n] is used for setting a variable whereas arrayItem(n , variableName) is used for reading it:


#16

In the end, the solution was really quite simple:

define
device deviceList = DeviceA,DeviceB,DeviceC,DeviceD
string deviceOrder = ‘4,3,1,2’;
device currentDevice =
end define

for ($index = 0 to 3 step 1)
Set variable {currentDevice} = {arrayItem(integer(arrayItem($index,deviceOrder)-1),deviceList)};
with {currentDevice}
do (whatever)
end