Help with rule and %device%

Hey Folks,
Could someone explain why my %device% and %value% refers to the Wait and not the actual device?

I took a quick look in the documentation and community hoping to find a post with a definitive answer but I think searhcing for "%device%" doesn't do what I think it does :slight_smile:

I believe %device% and %value% will be the last event recorded/received by the rule, which in this case would be your "wait for event" rather than the trigger event. Would be interesting to change it to "wait for condition" if that would work equally well in the rule, and I believe it probably would. Then the %device% that last triggered would be the device that triggered the rule, not the last event.

Or, as entry actions for the rule, save %device% and %value% in local variables to preserve them.

3 Likes

@brad5 Hmmm, let me have another look as to how this goes. I think you are right in saying it's the last event recorded by the rule is what the rule uses. I just didn't think a wait for event would be a device, and if it was, I would have thought the device would be the one it's waiting for an event from. Not the case.
@672southmain I am a complete noob when it comes to variables. I really need to read up on that.

@chad.andrews maybe changing the rule some will reduce the complexity. ? Trigger on that contact being changed and have an IF its open do your repeat ? Maybe?

@cgmckeever Your right, it will work other ways, I am just trying a new way. Here is my old rule...which works fine (but no notification for it being closed after being open x mins)

first, when did we get else-if ... that snuck by me :wink:

Can you just write what you are trying to do? I feel you might be doing this the harder way, but Im actually not sure what you end-goal is

1 Like

This is what I do. If you use waits your device may not always be what you expect.

@672southmain , man that does look easy. I really have to get on board with variables, I know there is so much more you can do with them.

@cgmckeever Simply put...
Door opens
If it closes within the 2 mins...stop.
if it's still open after 2 mins start notifying my phone every 1 minute, door open
if it closes during the notifications, notify phone, door closed

There is some other stuff i will be adding later on like in the previous example I gave, like the pause notifications and the chime sounds.

Do a delay 2min, and then a repeat every 1 min - you can cancel the delays on a door changed event

For these, my preference is let the rule clean up itself on each next trigger. It makes my brain happier and less things to juggle

trigger -> door change

action:
cancel delays
cancel repeats

if door closed:
  do something
else:
 delay 2
 repeat 1:
   if door closed:
     do something
   else:
     notify
   end 
end 

but thats closer to your original ..

That's not quite the right model. Initially, there was no %device% and %value%. Then, because of feature requests, they were added so that users could know which device triggered the rule (when there were multiple triggers) and what the value of the trigger was (i.e., when the trigger was on changed, etc.).

Then, when wait for event was added with a timeout, users wanted to know whether the wait fell through because of timeout or because the event occurred, so this additional feature request was piggy-backed on the already-existing support structure for %device% and %value%.

It's just a matter of creeping featurism, and implementing new features while still preserving functionality of existing prior Rules. All-in-all, it seems like a reasonable approach to ever-expanding feature requests by users.

Just my observation.

1 Like

@672southmain ahhh, progress. I see it and It makes sense.

So I jimmied up another rule based on my old one and this seems to work. I initially said i want a notification every minute to the phone, but no, it was for my siren. the phone I only wanted once. It looks like a mess in the logs, but it works.