Announcement

Collapse
No announcement yet.

Help Writing Time of Last Change of Motion Det to a Device

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

    Help Writing Time of Last Change of Motion Det to a Device

    I'm running a Hometroller Zee S2 (Linux) and need some help with a script. I want to write the date/time of the last motion detected with my kitchen motion sensor to a device.

    HSTouch does not display the 'last change' so I'm wanting to create a device with this information in it so I can see when the motion sensor last tripped.

    What I need is help with the (sudo) VB script below. The script will get triggered on a motion detector change to 'motion detected' and I will not retrigger the script for five seconds:

    sub main()

    Dim last_change As Date

    last_change = hs.DeviceLastChange("kitchen motion")

    hs.writelog(last_change) ' need help with this

    hs.??? 'need help writing the last_change to a device

    end sub


    Is this the best way to go about this?

    Thanks for the help!

    BSR
    --------------------------------------------------
    **** Do You "Cocoon"? ****

    #2
    Probably easier with vb.net.
    ('nnnn' and 'mmmm' are device codes.)

    Code:
        Sub Main(ByVal Params As Object)
    
        hs.SetDeviceString(nnnn, hs.DeviceLastChangeRef(mmmm), True)    
    
        hs.WriteLog "Last Change", hs.DeviceLastChangeRef(mmmm)
    
        End Sub
    Mike____________________________________________________________ __________________
    HS3 Pro Edition 3.0.0.548, NUC i3

    HW: Stargate | NX8e | CAV6.6 | Squeezebox | PCS | WGL 800RF | RFXCOM | Vantage Pro | Green-Eye | Edgeport/8 | Way2Call | Ecobee3 | EtherRain | Ubiquiti

    Comment


      #3
      Originally posted by Uncle Michael View Post
      Probably easier with vb.net.
      ('nnnn' and 'mmmm' are device codes.)

      Code:
          Sub Main(ByVal Params As Object)
      
          hs.SetDeviceString(nnnn, hs.DeviceLastChangeRef(mmmm), True)    
      
          hs.WriteLog "Last Change", hs.DeviceLastChangeRef(mmmm)
      
          End Sub
      Thanks for the reply. The motion sensor is code q29 and I created a device for the variable k1 (to save the date/time).

      I have this script saved as motionkit.vb and when run I get the following in the log

      Sub Main(ByVal Params As Object)

      hs.SetDeviceString(k1, hs.DeviceLastChangeRef(q29), True)
      hs.WriteLog "Last Change", hs.DeviceLastChangeRef(q29)

      End Sub

      Feb-17 4:52:38 PM Error Compiling script /usr/local/HomeSeer/scripts/motionkit.vb: 'End Namespace' must be preceded by a matching 'Namespace'.

      Feb-17 4:52:38 PM Error Compiling script /usr/local/HomeSeer/scripts/motionkit.vb: Identifier expected.

      Feb-17 4:52:38 PM Error Compiling script /usr/local/HomeSeer/scripts/motionkit.vb: Expected 'Class'.

      Feb-17 4:52:38 PM Error Compiling script /usr/local/HomeSeer/scripts/motionkit.vb: Expected 'End'.

      Feb-17 4:52:38 PM Error Compiling script /usr/local/HomeSeer/scripts/motionkit.vb: End of statement expected.

      I did some reading on the help file and didn't get to far. It did mention some naming librarys when using .net

      IMPORTS System.IO
      IMPORTS System.Net

      Do I have to include this somehow? Thanks again for the help!

      I'm also wondering how I set up the device K1 to receive the date/time variable. It shows as 'on-off'. How do you set this up as a variable?

      Sorry, but my last scripting with HomeSeer was with version 1.x in VBScript (and it wasn't this difficult).
      Last edited by BraveSirRobbin; February 17, 2018, 07:08 PM.
      --------------------------------------------------
      **** Do You "Cocoon"? ****

      Comment


        #4
        Originally posted by BraveSirRobbin View Post
        The motion sensor is code q29 and I created a device for the variable k1 (to save the date/time).
        Sorry. I meant RefID. HS3 doesn't really make use of the device code beyond X10, even though it allows one to be assigned.
        Attached Files
        Mike____________________________________________________________ __________________
        HS3 Pro Edition 3.0.0.548, NUC i3

        HW: Stargate | NX8e | CAV6.6 | Squeezebox | PCS | WGL 800RF | RFXCOM | Vantage Pro | Green-Eye | Edgeport/8 | Way2Call | Ecobee3 | EtherRain | Ubiquiti

        Comment


          #5
          Thanks so much Uncle Michael!

          This worked perfectly

          Sub Main(ByVal Params As Object)

          hs.SetDeviceString(112, hs.DeviceLastChangeRef(101), True)
          ' hs.WriteLog "Last Change", hs.DeviceLastChangeRef(101)

          End Sub

          I didn't get the writelog working, but I really didn't want it (other than to troubleshoot). My device of 'last change' is updating perfectly.

          I really want to thank you for this help! I know basic scripting, but I have difficulty with this new syntax.

          Regards,

          BSR
          --------------------------------------------------
          **** Do You "Cocoon"? ****

          Comment


            #6
            Originally posted by BraveSirRobbin View Post
            This worked perfectly

            Sub Main(ByVal Params As Object)

            hs.SetDeviceString(112, hs.DeviceLastChangeRef(101), True)
            ' hs.WriteLog "Last Change", hs.DeviceLastChangeRef(101)

            End Sub

            I didn't get the writelog working, but I really didn't want it (other than to troubleshoot). My device of 'last change' is updating perfectly.
            Sorry, I copied the writelog line from an immediate script statement and forgot to 'translate' it from VBS to vb.net. It should have () like this:
            hs.WriteLog ("Last Change", hs.DeviceLastChangeRef(101))

            I know basic scripting, but I have difficulty with this new syntax.
            Ed Tenholder has developed an amazing tool that is extremely helpful for writing HS scripts. The version for HS3 is tenScripting3, but the best place to start is here.
            Last edited by Uncle Michael; February 18, 2018, 02:47 PM. Reason: typo
            Mike____________________________________________________________ __________________
            HS3 Pro Edition 3.0.0.548, NUC i3

            HW: Stargate | NX8e | CAV6.6 | Squeezebox | PCS | WGL 800RF | RFXCOM | Vantage Pro | Green-Eye | Edgeport/8 | Way2Call | Ecobee3 | EtherRain | Ubiquiti

            Comment


              #7
              Originally posted by Uncle Michael View Post

              Ed Tenholder has developed an amazing tool that is extremely helpful for writing HS scripts. The version for HS3 is tenScripting3, but the best place to start is here.
              Thanks for this tip. I read a lot of information on that site and this looks great. One question though...will this work using my Linux HomeTroller Zee S2 (i.e. tenholdscripting run on a windows machine will be able to link to this HomeSeer directory on the Zee S2?).

              Thanks again for all the help.
              --------------------------------------------------
              **** Do You "Cocoon"? ****

              Comment


                #8
                Originally posted by BraveSirRobbin View Post
                Thanks for this tip. I read a lot of information on that site and this looks great. One question though...will this work using my Linux HomeTroller Zee S2 (i.e. tenholdscripting run on a windows machine will be able to link to this HomeSeer directory on the Zee S2?).
                Yes, I believe that is being done by several people on the board. On a Linux machine HS3 runs in Mono, as I understand it, which simulates a Windows .net environment, so I would expect a vb.net script to run the same on a Linux instillation as in windows.

                Edit:
                Here's a thread on that very topic.
                Last edited by Uncle Michael; February 19, 2018, 09:01 PM.
                Mike____________________________________________________________ __________________
                HS3 Pro Edition 3.0.0.548, NUC i3

                HW: Stargate | NX8e | CAV6.6 | Squeezebox | PCS | WGL 800RF | RFXCOM | Vantage Pro | Green-Eye | Edgeport/8 | Way2Call | Ecobee3 | EtherRain | Ubiquiti

                Comment

                Working...
                X