Announcement

Collapse
No announcement yet.

Schlage lock questions/assistance.

Collapse
This topic is closed.
X
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Schlage lock questions/assistance.

    I found an old post with the image below. I would like to do the same thing on my iPad, with logging the last X amount of entries. Is this just done with scripting, if so does anyone have a sample script or link that discusses how to import/call this data.

    Thanks.


    #2
    I have a script that does this, but I'm using it on my Android client. You probably have to start with breaking it down into pieces:

    First, I setup Device/Value Pairs on my Alarm device for my lock.
    i.e. Rob is user code 1, etc.
    (This is only available on HSPro)

    Second, I setup an event for each user code entered (see image).

    Third, here is the script that writes the door activity to a comma-delimited file. It also stores the last 10 entries in a virtual device.
    PHP Code:

        
    Public Const FNAME As String "/data/SchlageDoor.txt"
        
    Public Const DOORALARMDEVICECODE As String "Q5"
        
    Public Const HSTOUCHDEVICECODE As String "V10"   ''holds info for displaying in HSTouch
        
    Public Const DAYS As Integer 180    ''number of days to keep in the file

        
    Public Sub Main(ByVal parm As Object)
            
    Dim t As String
            Dim dev 
    As Object hs.GetDeviceByRef(hs.GetDeviceRef(DOORALARMDEVICECODE))
            
    MatchCodeToUser(dev.valueshs.DeviceValue(DOORALARMDEVICECODE))
            
    UpdateFile(t)
            
    UpdateHSTouchDevice(HSTOUCHDEVICECODE)
            
    PurgeOldRecords()
        
    End Sub

        
    Public Sub UpdateHSTouchDevice(ByVal dev As String)
            
    ''this sub reads the fileline-by-line into an array
            
    ''so that we can reverse the order and put the most
            
    ''recent entries on top.  
            
    Dim sr As System.IO.StreamReader
            Dim lin 
    As String ""
            
    Dim t As String ""
            
    Dim x As Integer 0
            Dim ary
    (DAYS 10) As String
            
    Try
                
    sr = New System.IO.StreamReader(hs.GetAppPath FNAME)
                Do 
    Until lin Is Nothing
                    lin 
    sr.ReadLine()
                    If (
    lin <> ""Then
                        
    If (DateDiff(DateInterval.DayCDate(hs.StringItem(lin2",")), Now) <= DAYSThen
                            ary
    (x) = lin
                            x 
    += 1
                            
    If (>= DAYS 10Then Exit Do
                        
    End If
                    
    End If
                
    Loop
                ReDim Preserve ary
    (x)
                
    "<table width='100%'><tr><td>Name</td><td>Date</td><td>Time</td></tr>"
                
    For UBound(aryTo UBound(ary) - 10 Step -1
                    t 
    "<tr><td>" hs.StringItem(ary(x), 1",") & "</td>"    ''name
                    t 
    "<td>" hs.StringItem(ary(x), 2",") & "</td>"        ''date
                    t 
    "<td>" hs.StringItem(ary(x), 3",") & "</td></tr>"   ''time
                Next
                t 
    "</table>"
            
    Catch ex As Exception
                hs
    .WriteLog("debug"ex.Message)
            Finally
                
    sr.Close()
                
    ary Nothing
                hs
    .SetDeviceString(devtTrue)
            
    End Try

        
    End Sub

        Sub PurgeOldRecords
    ()
            
    Dim lin As String ""
            
    Dim sr As System.IO.StreamReader
            Dim sw 
    As System.IO.StreamWriter

            
    Try
                
    sw = New System.IO.StreamWriter(hs.GetAppPath FNAME ".tmp"False)
                
    sr = New System.IO.StreamReader(hs.GetAppPath FNAME)
                Do 
    Until lin Is Nothing
                    lin 
    sr.ReadLine()
                    If (
    lin <> ""Then
                        
    If (DateDiff(DateInterval.DayCDate(hs.StringItem(lin2",")), Now) <= DAYSThen
                            sw
    .WriteLine(lin)
                        
    End If
                    
    End If

                
    Loop
                sr
    .Close()
                
    sw.Close()
                
    My.Computer.FileSystem.MoveFile(hs.GetAppPath FNAME ".tmp"hs.GetAppPath FNAMETrue)
            Catch 
    ex As Exception
                hs
    .WriteLog("SchlageDoor"ex.Message)
            Finally
                
    sr Nothing
                sw 
    Nothing
            End 
    Try
        
    End Sub

        Sub UpdateFile
    (ByVal msg As String)
            
    Dim d As Date Now
            
    Try
                
    Dim sw As New System.IO.StreamWriter(hs.GetAppPath FNAMETrue)
                
    sw.WriteLine(msg "," d.ToString("MM-dd-yyyy") & "," d.ToString("HH:mm:ss"))
                
    sw.Close()
            Catch 
    ex As Exception
                hs
    .WriteLog("SchlageLock"ex.Message)
            
    End Try

        
    End Sub

        
    Function MatchCodeToUser(ByVal s As StringByVal d As String) As String
            Dim t 
    As String ""
            
    Dim x As Integer
            Dim ary
    () As String s.Split(Chr(1))

            For 
    0 To UBound(ary)
                If (
    CInt(hs.StringItem(ary(x), 2Chr(2))) = CInt(d)) Then
                    t 
    hs.StringItem(ary(x), 1Chr(2))
                    Exit For
                
    End If
            
    Next
            
    Return t

        End 
    Function 
    Lastly, HSTouch can then display that virtual device as simple HTML in a Text Element (not a Text Box)
    Attached Files
    Last edited by rmasonjr; May 10, 2011, 09:08 PM. Reason: code changes
    HS4Pro on a Raspberry Pi4
    54 Z-Wave Nodes / 21 Zigbee Devices / 108 Events / 767 Devices
    Plugins: Z-Wave / Zigbee Plus / EasyTrigger / AK Weather / OMNI

    HSTouch Clients: 1 Android

    Comment


      #3
      rmasonjr, thank you so much for the information you provided. I do use HSPro and with the information you provided I was able to set this up with ease. It works great. Thank you.

      Comment


        #4
        cool! Glad it worked out for you. That's one of the cooler things to display on an HSTouch client if you have a lock...
        HS4Pro on a Raspberry Pi4
        54 Z-Wave Nodes / 21 Zigbee Devices / 108 Events / 767 Devices
        Plugins: Z-Wave / Zigbee Plus / EasyTrigger / AK Weather / OMNI

        HSTouch Clients: 1 Android

        Comment


          #5
          I should point out that there is a flaw in the program. There is an array that can only handle 1000 entries. So, when you get to 1000 entries in the file, it will bomb. At that point, you'll need to open the file with notepad and manually clean it.
          HS4Pro on a Raspberry Pi4
          54 Z-Wave Nodes / 21 Zigbee Devices / 108 Events / 767 Devices
          Plugins: Z-Wave / Zigbee Plus / EasyTrigger / AK Weather / OMNI

          HSTouch Clients: 1 Android

          Comment


            #6
            Originally posted by rmasonjr View Post
            I should point out that there is a flaw in the program. There is an array that can only handle 1000 entries. So, when you get to 1000 entries in the file, it will bomb. At that point, you'll need to open the file with notepad and manually clean it.
            Damnit! I am un-friending you on Facebook! But seriously folks... Is there a way to fix this, without cleaning out the file? maybe have the code do the purge. Not that it really matters, I just felt like asking without further examining the code.

            Comment


              #7
              ha! my FB frinds are so fickle...

              Yeah, I think I can add a purge method to the script. Stay tuned...
              HS4Pro on a Raspberry Pi4
              54 Z-Wave Nodes / 21 Zigbee Devices / 108 Events / 767 Devices
              Plugins: Z-Wave / Zigbee Plus / EasyTrigger / AK Weather / OMNI

              HSTouch Clients: 1 Android

              Comment


                #8
                Ok - I updated the code above. You can set the max # of days you want to keep in your file. I set mine at 180 days. Every time the file gets updated, it will purge any records older than DAYS.

                Update this thread if you run across any problems.

                Thanks
                Rob
                HS4Pro on a Raspberry Pi4
                54 Z-Wave Nodes / 21 Zigbee Devices / 108 Events / 767 Devices
                Plugins: Z-Wave / Zigbee Plus / EasyTrigger / AK Weather / OMNI

                HSTouch Clients: 1 Android

                Comment


                  #9
                  Wow, this works GREAT!

                  My only issue is the V10 device, when looking at it in a HS device status page, it's HTML goofs up the devices display. The actual HTML looks good (in HSTouch)...and I don't see HOW it is, but it seems to be goofing up HS's status page. No big deal (I just set it to be a hidden device).

                  Beyond that, thank you so much! Works GREAT!!!

                  --Dan
                  Tasker, to a person who does Homeautomation...is like walking up to a Crack Treatment facility with a truck full of 3lb bags of crack. Then for each person that walks in and out smack them in the face with an open bag.

                  Comment


                    #10
                    Thanks, Dan!

                    The only thing I can think of that might be throwing it off is that I am not using any of the default CSS styles - are you using a custom CSS with HS or the standard one?

                    Thanks
                    Rob
                    HS4Pro on a Raspberry Pi4
                    54 Z-Wave Nodes / 21 Zigbee Devices / 108 Events / 767 Devices
                    Plugins: Z-Wave / Zigbee Plus / EasyTrigger / AK Weather / OMNI

                    HSTouch Clients: 1 Android

                    Comment


                      #11
                      Should be standard.

                      I don't have HSPro, do you think that matters?

                      If it would help, I can take a screen capture later tonight.

                      --Dan
                      Tasker, to a person who does Homeautomation...is like walking up to a Crack Treatment facility with a truck full of 3lb bags of crack. Then for each person that walks in and out smack them in the face with an open bag.

                      Comment


                        #12
                        It shouldnt matter, but you never know... Shoot me a screenshot and I'll see if I can spot anything.

                        Thanks
                        HS4Pro on a Raspberry Pi4
                        54 Z-Wave Nodes / 21 Zigbee Devices / 108 Events / 767 Devices
                        Plugins: Z-Wave / Zigbee Plus / EasyTrigger / AK Weather / OMNI

                        HSTouch Clients: 1 Android

                        Comment


                          #13
                          HS Touch on Iphone &amp; Schlage Lock

                          Am fairly new to Homeseer but I was able to get my Schlage lock working but I am unable to "lock" or "unlock" via HSTouch. I also would like to set up the interface you described above for Android but on my Iphone.

                          I would be grateful for some help and advice on what changes I would need to make to the script code and how I install this into homeseer (Im not a programmer at all)

                          Thanks,

                          Comment


                            #14
                            Originally posted by marlinman4 View Post
                            Am fairly new to Homeseer but I was able to get my Schlage lock working but I am unable to "lock" or "unlock" via HSTouch. I also would like to set up the interface you described above for Android but on my Iphone.

                            I would be grateful for some help and advice on what changes I would need to make to the script code and how I install this into homeseer (Im not a programmer at all)

                            Thanks,
                            Sure!
                            First, make sure you have HSPro - this version contains the name/value pairs that are needed. If you dont, then this will likely not work at all

                            After you setup your name/value pairs, create your virtual devices in HS - Click on Status -> Add new Device -> Status Only (note the device code).

                            Find your Door Lock Device also found on the status page.

                            Save that script above as "SchlageDoor.vb" and save it in your HomeSeer "scripts" folder.
                            Edit the script and replace the device codes you used when you created your virtual device.

                            Setup the events just like the screenshot above.

                            Try it out and post back if you have any problems...
                            Last edited by rmasonjr; June 20, 2011, 01:54 PM. Reason: instructions
                            HS4Pro on a Raspberry Pi4
                            54 Z-Wave Nodes / 21 Zigbee Devices / 108 Events / 767 Devices
                            Plugins: Z-Wave / Zigbee Plus / EasyTrigger / AK Weather / OMNI

                            HSTouch Clients: 1 Android

                            Comment


                              #15
                              rmasonjr,

                              So, I just recently patched my HS server (Win7) to IE9. My "viewing" error went away.

                              I didn't do anything else (and as you can see, I never did post a screen capture.

                              I'll chalk it up to crazy IE8.

                              It now works like a charm!

                              I'll be modifying it to capture two locks...did you want my changes after I get it done?

                              --Dan
                              Tasker, to a person who does Homeautomation...is like walking up to a Crack Treatment facility with a truck full of 3lb bags of crack. Then for each person that walks in and out smack them in the face with an open bag.

                              Comment

                              Working...
                              X