Store multiple devices in variable

Is it possible to store more than 1 device in a variable, for instance $context.event.deviceName?
What I want to do is set a variable to store the names of all doors that are open

Current rule
Door A open/close
Door B open/close
Door C open/close
door A is open
door B is open
door C is open
Set $doorOpen to $context.event.deviceName (only saves the most recent door open)

I’d love to be able to do that. Maybe add a feature request if it’s not presently doable.

I use this considerably in webCore, for example, to aggregate devices meeting a certain criteria for notifications. For example, I have a webCore piston that runs once a day and provides a notification of all devices that are offline.

@James Can you tell me if this is possible or if it needs to be a feature request please?


You can not store a device reference in a variable currently, but as you noted, you can store text about a device (eg. deviceName).

Using the Set Variable (Manual Input) action, you can build a string that mixes multiple values together. And by referencing the existing variable value, you can concatenate strings together:

That means you could, in theory, have a set of IF Conditions that check each device and concatenate additional values into a single variable.

I think the reality is that it would be quite a bit of nested IF/THEN logic to get the string formatting correctly (but it does seem possible!).

I suspect that what @Bry is referring to is two things that would make this much easier to use in a rule. These do not exist presently and would need to be a feature request:

  1. The ability to store device references
    $myDoorContacts = ['Front Door', 'Back Door', 'Garage Door']
  2. The ability to filter devices references by conditions
    $openDoors = filterDevices($myDoorContacts, {["contact", "is", "open"]})

Again, both of these are just concepts. I haven’t spent a lot of time thinking about how a `Filter Devices’ type of action would actually work, but I wanted to illustrate how I was interpreting things.


Yep. Just to be clear, here is what I’m doing in webCore. The piston determines which devices are offline and populates the variable with the names of those devices. That makes it easy for the notification to contain the name(s) of those devices. While determining offline status might be difficult outside of webCore, there are other applications, such as checking which garage doors are open and notifying accordingly.

1 Like