I have a Schlage Camelot lock and it works OK from the front end, but I cannot figure out how to see which user codes unlocked a door. If I input user code 1 and let the door unlock, for example, the states screen shows “unlocked” but then in the attributes it shows “ock_status: Locked with Keypad by user 0.”
I found a template to use the sensors to determine method of lock/unlock and report the state to a sensor template, but in this same example, it also shows “Locked - Outside Keypad.”
The code came from this topic:
Anyone know how to get user codes so I can use them in automation?
Did you ever figure it out? I’m looking to set up some automation’s based on the user codes. I have my lock paired via my Wink Hub and able to lock/unlock and see the attributes of the lock. Just can’t figure out yet how to determine which code was used to unlock the door.
Think I know the answer, but does anything change to be indicative of a user code when you enter one? Not sure you will be able to do that with Home Assistant via Wink from what I’m seeing.
I think I figured it out, while looking at the states more I noticed there are binary created for each user code. I didn’t noticed them before. Thanks for your help! I’m still learning everything, this will be my first automation.
My Schlage Connect works wonderfully with that setup. You just have to create an automation for each of those code binary sensors changing states to do whatever you want.
Thanks @lmamakos for the post. I left a comment there as well but felt the need to post in here as well since it is in regard to User Codes.
I found with my Schlage Connect BE469WK that there was different meaning for alarm type. The lock I have uses 18, 19, 21, 22, and 27. You can see my automations below.
- alias: Front Door Locked By Outside Button Notification
trigger:
- platform: state
entity_id: sensor.schlage_be469nxcen_touchscreen_deadbolt_alarm_type
to: '18'
action:
- service: notify.notify
data:
message: "Front door locked by outside button"
- alias: Front Door Unlocked By User Notification
trigger:
- platform: state
entity_id: sensor.schlage_be469nxcen_touchscreen_deadbolt_alarm_type
to: '19'
action:
- service: notify.notify
data_template:
message: !secret frontdoorunlockedbyusers
- alias: Front Door Locked From Inside Notification
trigger:
- platform: state
entity_id: sensor.schlage_be469nxcen_touchscreen_deadbolt_alarm_type
to: '21'
action:
- service: notify.notify
data:
message: "Front door locked from inside"
- alias: Front Door Unlocked From Inside Notification
trigger:
- platform: state
entity_id: sensor.schlage_be469nxcen_touchscreen_deadbolt_alarm_type
to: '22'
action:
- service: notify.notify
data:
message: "Front door unlocked from inside"
- alias: Front Door AutoLock Notification
trigger:
- platform: state
entity_id: sensor.schlage_be469nxcen_touchscreen_deadbolt_alarm_type
to: '27'
action:
- service: notify.notify
data:
message: "Front door was auto-locked"
As for the message !secret frontdoorunlockedbyusers, I wanted to protect the names of the users I have. You can put the whole data_template message in a secret. Here is an example of what I used:
frontdoorunlockedbyusers: "Front door unlocked by {{[ 'Unknown', 'User 1', 'User2', 'User3'][states('sensor.schlage_be469nxcen_touchscreen_deadbolt_alarm_level')|int]}}"
The alarm level returns a string with the number corresponding to the user “id”. The id is in the order you added a new user code. If there is no user id then 0 is returned which I am using Unknown. This almost never happens. It happened once when I restarted home assistant. If the first user code was entered it would return 1 and use the name User1 and so on.
Nice work @rmendoza3! I also have the same ‘camelot’ lockset and your code snippet is brilliant. I’m now getting instant push notifications on my Apple watch whenever someone manipulates the door lock. I also liked your idea of hiding user names in the secret.yaml file!
One note though that may help other users: For some reason, after copying and pasting the data_template message into my secret.yaml file, I found that that the template was always evaluating to ‘0’, so it always returned user ‘unknown.’ Strangely enough, when testing the code snippet in the Developer Tools->Templates panel it worked flawlessly. Long story short, after much troubleshooting I found that the reference to the sensor had to be put in double quotes rather than single quotes:
frontdoorunlockedbyusers: "Front door unlocked by {{[ 'Unknown', 'User 1', 'User2', 'User3'][states("sensor.schlage_be469nxcen_touchscreen_deadbolt_alarm_level")|int]}}"
Not sure why, but once I made that change it worked flawlessly.
I am glad it helped you. As for the Apple watch notifications, I do not have one or know why it wouldn’t work, sorry.
The double quote solutions seems odd, but very interesting. I am running on Hass.io and it worked. I am curious to the setup you have. Do you use a raspberry pi and hassbian or maybe just a linux or windows install. I do not see how that works with double quotes being inside double quotes. Maybe who knows a thing or two about yaml could shed some light on this.
Hi @rmendoza3. I’m running a Raspberry Pi 3 with Raspbian and a plain jane install of HA on it. I used the All-In-One installer when I set it up.
But, I stand corrected, changing to double quotes didn’t solve anything. I’ve changed it back. My testing method was flawed which is why I thought the double quotes fixed it.
After a couple more hours of trouble-shooting, I found I had to add a delay to my action script. From what I can tell, the action calling the notify service was firing so quickly it was reading the alarm_type sensor before the state was updated. After adding a 300 ms delay, the problem was resolved and now I’m getting accurate notifications.
As for the Apple watch notifications, I was saying it works flawlessly. It’s super cool. When the notify services fires a push notification to iOS, the phone also pushes it to the watch.
My code formatting looks a bit differently than yours because I’ve been using the front end Automation builder tool.
- action:
- delay:
milliseconds: 300
- data_template:
message: !secret frontdoorunlockedbyusers
service: notify.notify
alias: Front Door Unlocked By User Notification
condition: []
id: '1511486862041'
trigger:
- entity_id: sensor.frontdoorlock_alarm_type
platform: state
to: '19'