Author Topic: Unlock a door using Luup code  (Read 4347 times)

Offline JimMac

  • Sr. Member
  • ****
  • Posts: 307
  • Karma: +2/-1
Unlock a door using Luup code
« on: September 10, 2011, 01:15:00 pm »
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?

Offline futzle

  • Beta Testers
  • Master Member
  • *****
  • Posts: 3257
  • Karma: +191/-9
Re: Unlock a door using Luup code
« Reply #1 on: September 10, 2011, 08:56:42 pm »
Probably you want luup.call_action().

Something like:
Code: [Select]
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.
« Last Edit: September 12, 2011, 05:41:20 pm by futzle »

Offline JimMac

  • Sr. Member
  • ****
  • Posts: 307
  • Karma: +2/-1
Re: Unlock a door using Luup code
« Reply #2 on: September 11, 2011, 10:52:23 pm »
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.
« Last Edit: September 15, 2011, 12:05:27 pm by JimMac »

Offline mcvflorin

  • Administrator
  • Hero Member
  • *****
  • Posts: 1755
  • Karma: +11/-3
Re: Unlock a door using Luup code
« Reply #3 on: September 12, 2011, 05:06:13 am »
You have to remove the "" surrounding the newTargetValue.

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

Offline futzle

  • Beta Testers
  • Master Member
  • *****
  • Posts: 3257
  • Karma: +191/-9
Re: Unlock a door using Luup code
« Reply #4 on: September 12, 2011, 06:22:04 am »
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.)

Offline mcvflorin

  • Administrator
  • Hero Member
  • *****
  • Posts: 1755
  • Karma: +11/-3
Re: Unlock a door using Luup code
« Reply #5 on: September 12, 2011, 08:42:48 am »
Don't worry futzle, I learned this the hard way. :)

Offline JimMac

  • Sr. Member
  • ****
  • Posts: 307
  • Karma: +2/-1
Re: Unlock a door using Luup code
« Reply #6 on: September 12, 2011, 01:49:01 pm »
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
« Last Edit: September 13, 2011, 01:24:56 pm by JimMac »

Offline mcvflorin

  • Administrator
  • Hero Member
  • *****
  • Posts: 1755
  • Karma: +11/-3
Re: Unlock a door using Luup code
« Reply #7 on: September 13, 2011, 09:11:52 am »
I would use luup.call_delay instead just because it's simpler.