Specifying the order of elements in a device array?


#1

Is there a way to define a device array and specify the exact order of the elements?

I’m trying to create two devices arrays such that elements pair up for later use. I want one array to have the front and back door sensors, and the other array to have the front and back landscape light switches.

The problem is the UI for selecting devices and adding them to the variables adds them in alphabetical order, and the names of my devices sort differently:

device doors = Front Door and Sliding Door
device lights = Lights - Back Yard and Lights - Front Yard

I don’t want to have to resort to renaming the devices so they alphabetize the right way.

Thanks!


#2

There is no way to directly rearrange devices in a variable, however I can think of two workarounds that might work:

  1. with {arrayItem(2,doors)} - this will return the second device in the door variable.

  2. bit of a hack this one… rename the devices temporarily, delete and recreate the variable (so they show in the correct order), change names back… When I have done this before, the names change back correctly in the piston but they didn’t re-order.


#3

Your bit of a hack did the trick. I renamed them so they sort properly, then renamed them back. Seems to work!


#4

Or just enter them manually thenin as an expression

Ie.variable device sensors = [door2],[door1],[door3]