How to get a device name inside a rule

So I want to check which door is open after going into away mode.

But %device% doesn't contain the device name but the hub name.
It appears to be set in the Triger event. The trigger event test for AWAY

How can I get the device name in a conditional statement. I know I could test each door separately which I guess I will have to do.. But is there a way on a conditional statement testing lots of devices to get the device name of the one that's open?

try putting the trigger being the door device and a required expression being (mode) away home etc.. or the mode in an if instead of the rule body.

then %device% should work as expected

There's an app for that. :slight_smile:

@anon47916022 has a device grouping app that lets you group like devices together and then get a list of which of them are open, for contact sensors, for example.

Search HPM for sensor groups +


There may be an easier way to do this directly within rule machine. I'll leave that approach for others to help you out with that angle.

As mentioned above, the device variable refers to the trigger event. A conditional will never affect the value of this variable. Further, if the trigger is not a device, the value may not be very useful or set at all (in your case, it's a location/hub event, not a device event, and the value is apparently your hub name).

I haven't checked out the app mentioned above, but I also wrote an app to solve this problem for me. It is possible to do in a rule if you want to do it that way, too--it's just a lot of work and manual string concatenation. I have an example of a rule (from Rule 4.x, but it would still work more or less the same now) that this app replaced in the thread where I announced the app in case you want to explore either option: