Get Lock Pin User

Ok, so I’m using vera alerts, and I’m loving it so far. However, there is one thing I miss over the normal notifications in vera. When I set up a notification for my door lock for when any pin (*) is entered, the vera notifications still tell me what user’s pin was used (the name associated with the pin). I don’t know how hard this would be do, or if it’s even possible.

I entered the following string as the message override to see what would be available for the message:

Name={Name} Description={Description} DeviceID={DeviceID} Service={Service} Variables={Variables}

and I get (split to separate lines for readability)

Name=Code entered to open Front Door
Description= Pin Code #* is entered on Front Door
DeviceID=3
Service= um:micasaverde-com:serviceId:DoorLock1
Variables=sl_UserCode

Is there any way to use the information above to get to the user that entered the pin? For instance, when I add a pin to my door lock, I put a name (“Frank”) and a Pin. I know I could set up separate notifications for each user, but using the * was easier and I just want to make sure that there isn’t a way to handle it globally before I do separate ones.

Ok, so when I use this:

{Device([3].Lock.sl_UserCode)}

I get this:

UserID=“2” UserName=“Sara”

where Sara was the last person to unlock the door by a pin. I’m curious if there is now a way for me to just get the Sara part, so that I could have my alert day

Sara just unlocked the door.

That’s about as far as I got when I tried it that way. You can use the string commands to parse the username out, and then concatenate that into the rest of your alert message. But ever since PLEG came out I refuse to do anything in luup if there is another way.

After RTS pointed me in this direction, I created separate notifications on each lock for each pin code, have Vera Alerts process the notifications, and then hard coded the message I want: Pin 7 on front door lock = “The housecleaner unlocked the front door”.

Now I get an alert letting me know who opened what door and when, and my children know they are going to have to seriously up their game if they want to sneak in after curfew!

I was busy with another project … I do not have a better answer yet … but let me think about it …

@RichardT

Were you able to come up with anything more here? I’m interested in doing the same on my notifications, without having to hard code multiple notifications as were indicated above. Trying to reduce the amount of different messages being managed if possible.

If anyone figures this out id be interested to test it out on my Yale touchscreen.

Would enable logging of users as I cant do this with vera or haven’t yet figured it out.

A brief guide would be appreciated.

Here’s my super quick and super dirty Lua string parsing solution:

local devID = 999
local lastopeneduser = luup.variable_get("urn:micasaverde-com:serviceId:DoorLock1","sl_UserCode",devID)
local username = ''

for token in string.gmatch(lastopeneduser, '[^"]+') do
  username = token
end

luup.call_action("urn:richardgreen:serviceId:VeraAlert1", "SendAlert", {Message = "PIN code for " .. username .. " has been entered on the front door.", Recipients = "VeraAlertsProfile"}, 000)

Where:
999 is the device id for your lock.
VeraAlertsRecipients is the profile you want to alert
and 000 is the id for your VeraAlerts plugin

I will release some functionality to Vera Alerts Template so you can do this as a template:

{device([999].Lock.sl_UserCode) | String.LockUserName() }
or:
{device([Front Door].Lock.sl_UserCode) | String.LockUserName() }

For now just upload the attached file.

999 is the device ID for your Lock … You can also use the Lock Name if it’s unique.

@RichardT

Forgive my ignorance here but trying to understand how this needs to happen. If I upload this LUA and reload vera, I am able to substitute {device([999].Lock.sl_UserCode) | String.LockUserName() } into my notification text and it will provide the name of the user who’s PIN was used? Just curious how to use the output.

Upload file with Apps → Develop Apps Luuo Files → Upload
Click the restart Lup after reload … then GO.

To use as an alert use a message string like:

{device([Front Door].Lock.sl_UserCode) | String.LockUserName() } came in through the front door.

If you use a device NOTIFICATION … then you can override the standard notification in Vera Alerts Notification Configuration.
Use something like the above in the message ovveride.

If you use notifications in a scene or PLEG/PLTS action use something like the above in the message.
Same is true if you use LUA to send messages …

Thanks RichardT, clearly my coffee hasn’t kicked in this AM. ;D

I’ll take it for a spin later. This is exciting to finally have this ability.

I tried this, and I think it is working, my only problem now is that for some reason it returns nothing. so I have:

{device([49].Lock.sl_UserCode) | String.LockUserName() } is home.

and it only says " is home."

I don’t know if vera is not finding the correct value or what.

Oops …
There are two code paths … I test one … but not the one used in this example …
Try the new file:

Still no go. I turned back on “email notifications” for the vera and when I unlocked via a pin, I got this:

[code]Your trigger "A Pin is Entered " occurred.

The originating device ID:49 Front Door in room: Foyer

The ID is: 2709124321
Code: DL_USERCODE Value:UserID=“1” UserName=“Frank”[/code]

And this is what I had in the notification test:

{device([Front Door].Lock.sl_UserCode) | String.LockUserName() } is home.

I’ve also tried:

{device([Front Door].Lock.dl_UserCode) | String.LockUserName() } is home.

(I tried the above because of the “DL_USERCODE” in the email notification). This did not work

I then tried:

{device([Front Door].Lock.DL_USERCODE) | String.LockUserName() } is home.

which failed to work as well.

Ok…this worked for me… I guess “Front Door” isn’t unique?

{Device([49].Lock.sl_UserCode) | String.LockUserName()} is home

Edit: Oh, and thanks RTS for adding this! It has really cleaned up my notifications list in veraAlerts.

Awesome! Much prettier than my dirty version :slight_smile:

Thanks Richard!

Looks to be working perfect for me too! At first I forgot to put the device number in, corrected that mistake, and WALA!

@RichardT you are the man!!

There is also a String.LockUserID() if you want the ID!
This file will be in the next official release.

Am I correct in thinking that this will allow me to have one notification for each lock and VeraAlerts will get the username from the lock for me? If so, which notification option are you choosing?

“A PIN code is entered” makes you choose one particular index number.
“A door is locked or unlocked” will give me alerts when the lock is operated manually

It will only work for:
“A PIN code is entered” makes you choose one particular index number.
Use * as a pin code.
The alert will tell you wich user actually opened the door.