Announcement

Collapse
No announcement yet.

Script to Toggle Zwave Lock

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Script to Toggle Zwave Lock

    I have a Kwikset 916 Lock that I just got working

    I am trying to create a script to toggle the lock with a single button press in HsTouch (Android client)

    I found a toggle switch for lights and have modified it. It works half way. Essentially I can unlock the device but I can't lock it for some reason

    Below is the script

    Code:
     Sub Main(ByVal theDevice as string)
    '' Specify the Device Name, including Locations, as a Parm
    Dim devValue as double
    '' Get the Device Status
    devValue = hs.DeviceValue(theDevice)
    hs.writelog("Info","lock value is " & devValue)
    '' Toggle it
    Select Case devValue
    Case 255
    '' Device Locked, UNLOCK it
    hs.CAPIControlHandler(hs.CAPIGetSingleControl(theDevice,true,"Unlock",false,true))
    Case 0
    '' Device Unlocked, LOCK it
    hs.CAPIControlHandler(hs.CAPIGetSingleControl(theDevice,true,"Lock",false,true))
    End Select
    End Sub
    No matter what it sends an unlock command even though it knows it knows that it is unlocked

    What am I missing here?

    #2
    I found a work around

    Instead of using CAPI to control the device (must be bug here)

    I created a couple events (one to lock and one to unlock)

    Here is my final script for anyone else who wants to do this

    Created a 3rd event that actually is triggered by button press in HStouch. this event passes the device value (in my case 286)

    Code:
     Sub Main(ByVal theDevice As String)
    '' Specify the Device Name, including Locations, as a Parm
    Dim devValue as double
    '' Get the Device Status
    devValue = hs.DeviceValue(theDevice)
    hs.writelog("Info","lock value is " & devValue)
    '' Toggle it
    Select Case devValue
     Case 255
    '' Device Locked, UNLOCK it
      hs.TriggerEvent("Front Door Unlock") 
     Case 0
    '' Device Unlocked, LOCK it
      hs.TriggerEvent("Front Door Lock") 
    End Select
    End Sub

    Comment


      #3
      Yours and others posts helped me learn some new tricks. I have Yale locks and couldn't figure out how to toggle the lock with a single button.

      So here are some steps for the curious

      1) create 3 manually triggered events (Script, Front Door Lock, Front Door Unlock)
      2) Lock and Unlock are simply setting node to lock or unlock
      3) Script has the following code

      Code:
      ''Lockscript.vb
      Sub Main(parms as Object)
          Dim devStatus = hs.DeviceValueByName("Vestibule Door Lock")
          Select Case devStatus
          Case 255
              hs.TriggerEvent("Front Door Unlock")
              hs.Speak("Unlocking the Front Door")
          Case 0
              hs.TriggerEvent("Front Door Lock")
              hs.Speak("Locking the Front Door")
          end Select
      end Sub
      The HomeSeer documentation states DeviceValueByName requires Location & Name. This can be confusing because by location they mean Room. So in my case the Device: Door Lock is in the Room: Vestibule.

      Finally,
      4) Create a button in HSTouch Designer. I like to give it status tracking of the door lock. And Action when pressed is the Front Door Lock Script.


      https://homeseer.com/support/homesee...lp/default.htm
      Last edited by AttilaHooper; September 24, 2017, 01:35 PM.

      Comment


        #4
        I use TenScriptAid to find the capi. This is what my locks returns and its different than your sample code. Maybe that is why it's not locking.

        TenScriptAid has been invaluable to me as I'm not real swift with VB, but I prefer it and avoid using events because that just becomes another point of potential failure.

        This is output from TenScriptAid for my schlage locks:

        hs.CAPIControlHandler(hs.CAPIGetSingleControl(527,True,"Unlo ck",False,False))
        hs.CAPIControlHandler(hs.CAPIGetSingleControl(527,True,"Lock ",False,False))

        This is how I use it in .asp as I don't use hstouch preferring my asp pages. It's just a simple format post web page with buttons and the delays are only added so the device can change state before the form reloads as elsewhere in my asp I test the device for on-off and dim level and set the color and intensity of the button based on the devices values.

        Code:
        	If Request.Form("sValG13") = "Front" Then
        		theDevice = 527
        		devValue = hs.DeviceValue(theDevice)
        		if devValue=255 then 
        			hs.CAPIControlHandler(hs.CAPIGetSingleControl(theDevice,True,"Unlock",False,False))    
        			hs.waitsecs (2)
        		end if
        		if devValue=0 then 
        			hs.CAPIControlHandler(hs.CAPIGetSingleControl(theDevice,True,"Lock",False,False))			
        			hs.waitsecs (2)
        		end if
        	end If
        -Rick

        Comment

        Working...
        X