Unlock a door using Luup code

I am trying to unlock a door using Luup code in a scene and need some help.

I have tried this code and in the GUI it turns on the Unlocked button but the door remains locked.
luup.variable_set(“urn:micasaverde-com:serviceId:DoorLock1”,“Status”,“0”,145)

Can anyone help me with the correct code?

Probably you want luup.call_action().

Something like:

luup.call_action("urn:micasaverde-com:serviceId:DoorLock1", "SetTarget", { "newTargetValue" = "0" }, 145)

The internal implementation for the SetTarget function will attempt to unlock the door, and if it’s successful it will set Status to 0, updating the GUI.

Edit: This is WRONG. See mcvflorin’s post below.

Thanks futzle for you help but that still doesn’t work. I don’t get any error when saving the scene but activating it does nothing. The door lock icon does not turn green indicating a received command.

You have to remove the “” surrounding the newTargetValue.

luup.call_action("urn:micasaverde-com:serviceId:DoorLock1", "SetTarget", { newTargetValue = "0" }, 145)

Thanks mcvflorin. (In my defence, I was messing about with JavaScript this morning. Lua syntax just doesn’t stick with me. Square brackets and quotes, or neither. One day I’ll remember.)

Don’t worry futzle, I learned this the hard way. :slight_smile:

Thanks mcvflorin, that works. Now I can finally simplify the need to send a 10 second delayed unlock command to my Schlage locks after I enter a valid door code and my virtual “WeAreHome” flag is set. I don’t know of any other way of turning off the “after 5 seconds re-lock the door” factory setting.

function unlockdelay()
luup.call_action(“urn:micasaverde-com:serviceId:DoorLock1”, “SetTarget”, { newTargetValue = “0” }, 145)
end

luup.call_timer(“unlockdelay”, 1, 10, “”,“”)
luup.call_delay(“unlockdelay”, 10)
return false

Edit: Added luup.call_delay function

I would use luup.call_delay instead just because it’s simpler.