Watching for Kwikset sl_UserCode change before sending notification

I’m trying to define a scene that emails me to the name associated with the pin entered into the lock…

While I was able to get the email to fire the value of sl_UserCode , I noticed that the variable isn’t updated until after my email is sent…

I tried to add a delay in the LUUP code (assuming it needed time to update), however that doesn’t seem to work…

Is there a way for me to get it to update the variable before sending the email???

In the log I can see when the sl_UserCode is updated and it is AFTER my delay and email is sent:
06 07/10/13 20:14:39.155 Device_Variable::m_szValue_set device: 11 service: urn:micasaverde-com:serviceId:DoorLock1 variable: sl_UserCode was: UserID=“2” UserName=“Karen” now: UserID=“1” UserName=“Joe” #hooks: 3 upnp: 0 v:0xc5d998/DL_USERCODE duplicate:0 <0x2bdeb680>



I finally figured out how to reliably get the userID and userName of the PIN entered to open the lock was to utilize variable_watch.

Initially I tried putting the variable_watch code into the LUUP section of a scene that was triggered on “A door is locked or unlocked”->“Device is opened”, which seemed to work until I realized it was being called multiple times and I would ultimately receive multiple texts because the variable_watch cannot be unregistered and with each call a new variable_watch was being called ultimately resulting in an increased number of texts sent with each unlock of the door!!

So what finally seems to have worked was to add variable_watch to the Startup Lua (without the need of creating a plugin):

Go to: APPS->Develop Apps->Edit Startup Lua

Added this code:

– Add a variable_watch for my handler function and for the lock device
luup.variable_watch(“alertPinRecentlyUsed”, “urn:micasaverde-com:serviceId:DoorLock1”, “sl_UserCode”, 11)

– Handler function for when the lock’s sl_UserCode is updated
function alertPinRecentlyUsed()
– call_action function to call my scene that actually texts me
luup.call_action(“urn:micasaverde-com:serviceId:HomeAutomationGateway1”, “RunScene”, {SceneNum = “25”}, 0)

So with this code I can reliable receive a single text (sent in the referenced scene) each time that contains the CORRECT userID and userName that was entered into the lock.

I hope this helps others!!

sounds Awesome, ill give it a shot tomorrow