Controlling a device in a device array


#1

I’m writing a piston to monitor all my sensors, The idea is to turn on a matching virtual switch if there is no activity on the sensor for a certain period of time.

I have an array of alert virtual switches, but I’m not sure how to turn one on/off by referencing it within the array of devices.
eg
with failSensor[3]
turn on

Is there a way of achieving this?


#2

I’ve found I can do this by setting a device variable to the array device item, but still wondering if there’s a more element way of doing this, without having to use a work variable?
currentDevice = failSensor[3]
with currentDevice
turn on


#3

I’m guessing the variable has to be specifically set as a device variable first before wc can act on it in a with statement.


#4

The variable does have to be of type device, also the full command to extract it from the array is
currentDevice=arrayitem(3,failSensors)