Notification for changed state of door lock conditional to what state the lock was in before the change

Rule Machine newb here... I tried to search for what I am trying to do but I must be using the wrong keywords to search. This has to be covered in a thread somewhere on here...

I want to create a notification rule that triggers on my door lock changing state. But I want my notification to say "Kitchen Door Locked" when the state changes from Unlocked to Locked. Then I want a notification to say "Kitchen Door Unlocked" when the state changes from Locked to Locked.

In Rule Machine 4.0 I tried to create two rules with the lock state change as trigger and applied a condition to only do the action of the lock state is locked for one rule and unlocked for the other rule. When I test it, I get both "locked" and "unlocked" notifications no matter what direction the state is changing. I am missing something here. I am sure it is simple.

Can you post screenshots of your rules?

How do I view the entire rule code? I only know how to go through the rule manager wizard.

I just accomplished what I wanted to do using the "notifications" built-in app. But it would be good experience for me to see how this is done in rule manager and/or in logic statements.

The rule posted by @Carl is perfect for your needs.

1 Like

I guess I am barking up the wrong tree with using the lock state change as a "trigger"

Actually I think I see. I still have to figure out how to get to the IF statement

Go it. I think. Conditional action. I was jumping a step ahead to the send message action too soon.

If you're totally new to Rule Machine, the UI can be a bit awkward. To figure out how to get the IFs, I see you've already done so, but maybe watching the videos would help:

The docs are also good. I know they sound boring, but they're full of good examples. :slight_smile: Here is my preferred location for those (though you can also find this in the docs site): [Released] Rule 4.0

Finally, to give you even more ideas, locks generally only report a "locked" or "unlocked" state (some can do "unknown" and "unlocked with timeout" is apparently also an option that I'm not sure I've ever seen). Rule Machine also includes a few built-in variables you can use. Combining these facts, the following rule should work about the same:

Triggers:

Kitchen Door Lock *changed*

Actions:

Notify Pixel 3 XL: '%device% is %value'

Here, this relies on the fact that %device% is a string variable with the display name of the last triggering device (always going to be your lock here, since that's all there is) and %value% is a variable containing the value of the attribute ("lock," in this case, with likely values "locked" or "unlocked"--see "Current States" on the device page for what yours does) of the device that matched your trigger.

That being said, I'd just use the Notifications app for this myself. :slight_smile:

2 Likes

Got it working in Rule manager. Thanks for your help. My logic brain needed a kick start. There was a time when I could write many lines of logical code in programs like MatLab, Maple, Excel. But it has been decades since college...

I needed this jolt to my thought processes.This will be my segway into automating my ceiling fans based on temperature thresholds, HVAC on/off state, and pre-existing conditions like if the fans were already turned on manually.

3 Likes

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.