RM %device% update

Possible bug with %device% notification, not sure if this has been raised already (I did do a quick search) but when I make a notification using the %device% and then change or add additional devices I sometimes have to re-add the whole rule for it to correctly search for the additional or changed devices? Not sure if it is something I am doing wrong or a bug. Just thought I would share.

Could you provide an example? %device% just refers to the last triggering device. Sometimes people think it refers to devices that match a certain state inside a conditional (it doesn't), and it's also worth noting that if you're testing it with "Run Rule Actions," there is no triggering device, so it will be an empty string (or null; I can't remember, but not anything either way...EDIT: actually, it should remember the last value, as stated below, but if you just never have a device/location as a trigger in the first place or do "Run Rule" before one makes something happen, you'll see this).

2 Likes

Easy enough to test. :slight_smile: This is what happens for me when I click "Run Actions":

image

image

I do think you'll get the hub/location name if you have an event like mode or HSM that doesn't directly involve a "device" but was still triggered by something on the hub. Here's %device% when a mode-change trigger matches for me:

image

2 Likes

Ah I think this is probably where I am going wrong. I thought it may be the trigger devices or even the conditional devices?
Will try and give specific example when I am next on the PC :+1:

It is indeed the triggering device, but only if there is a device (so not if you manually run the actions to test from the RM UI). So this would give you "Switch 1" as %device% if the rule runs when triggered naturally:

Trigger events: Switch 1 turns on

Actions:

Log: "Variable is %device%"

(Output: "Variable is Switch 1")

But this is the extent of %device%. Again, a common mistake is to assume that it matches devices used in an enclosing conditional that are in a certain state, but it doesn't. So, the value of %device% here is still "Switch 1," regardless of the state of Switch 2 (or what devices you use in the conditional):

Trigger events: Switch 1 turns on

Actions:

IF (Switch 2 is on) THEN
  Log: "Variable is %device%"
END-IF

(Output: "Variable is Switch 1")

Hope this helps! And as you suggest, if you do think there is a problem (not saying there still couldn't be), then an example would help someone else reproduce it. Good luck!

2 Likes

So, typical that when I try and re-create it it doesn't perform as previously stated however very similar. Picture below, top is the original script which runs fine and as expected, when the trigger events change to a different device (rule below) I then get two notifications on the phone (Bottom picture). I assume it almost 'caches' the data on initial capture maybe?

The only way I have been able to resolve it (and to be honest its not a massive issue just a little annoying) is to remove the trigger completely and the notify action and start again.

That was my misunderstanding too! Thanks for the clarification

Whenever a trigger fires a rule, it captures the following information from the triggering event into state:

device displayName: %device%
event value: %value%
event time: %time%
event date: %date%

Those references, such as %value%, pull the corresponding value from state. State persists.

1 Like

Thought that this may be the case, thanks for the clarification :+1: