Conditional and change respective device?

Is there a way to write a conditional and only have it apply to the respective device? I'm not sure if I'm phrasing that correctly, but here's what I'm wondering.

The rule:
If device 1, device 2, device 3 any is unlocked, THEN
lock device 1, device 2, device 3

What I would like to happen is if device 2 is unlocked, then lock device 2 instead of locking 1, 2, and 3. Similar to the "command only switches that are on" command. Otherwise I would have to write the three lines for IF 1, then 1, IF 2, then 2, IF 3, then 3, right?

Rule Machine doesn't have a way to do this as you're proposing, but I think webCoRE does (sort of, I was thinking storing devices matching a state to an array you can use) if you are not opposed to using that.

Otherwise, you can certainly take the alternative approach you mentioned.

That being said, are these locks that would act up if you sent a "lock" command to something that was already locked? Typically, the net effect would be none (nothing on the device and just a little extra network traffic), so it's normally not something to worry about. If you share more details about the problem you're trying to solve, someone might have other ideas you'd find helpful.

I thought RM could get event info... maybe not?

In Webcore, you would just use the system variable $currentEventDevice to see which of the three locks created the event.

You need to use "changes to" in Webcore to create a subscription to the event device

Something like this pseudocode:

if any of device 1 lock, device 2 lock device3 lock changes to "unlocked"
then
      If $currentEventDevice is equal to "device 1" 
           then set device 1 lock to locked
       If $currentEventDevice is equal to "device 2" 
            then set device 2 lock to locked
   ...
...

I thought this would work in RM, using Custom Action > Last Event Device > Lock as shown...

1 Like

For a single device and event, yes; the OP made it sound like they were looking to collect and act on a list of devices matching a certain criterion. I suppose we'll see!

@jaredeaves never got back to us on this question, but I believe due to some recent changes in how the Forum works, only the OP can mark the thread as "Solved". Standing by in case more suggestions needed.

Sorry about that. Yeah, that was basically it. If they match the status, only change them. I've avoided webCoRE for some reason, but I may look into that. Otherwise (ELSE) I can write it per lock which isn't that bad. I only have four so that wouldn't be a lot of workaround.

Thanks everyone!

I'm still curious about this:

Specifically, I'm wondering if something like the built-in Command Retry feature might work for your needs without having to do any of this all. But we'd need to know what those are first. :slight_smile: