Announcement

Collapse
No announcement yet.

Grab console output and set virtual device values

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

  • Grab console output and set virtual device values

    Hi,

    I have two door locks which are addressable via a Python API. This is on the same Windows machine as Homeseer. If I send a command from a console window, e.g.

    Code:
    vsure user@example.com mypassword overview doorLockStatusList
    I get a status output which looks like this:

    Code:
    [
        {
            "eventTime": "2018-12-16T09:37:14.000Z",
            "area": "Entrance",
            "deviceLabel": "XXX",
            "currentLockState": "UNLOCKED",
            "motorJam": false,
            "secureModeActive": false,
            "paired": true,
            "lockedState": "UNLOCKED",
            "pendingLockState": "NONE",
            "userString": "John Doe",
            "method": "THUMB"
        },
        {
            "eventTime": "2018-12-16T15:11:13.000Z",
            "area": "Laundry",
            "deviceLabel": "XXX",
            "currentLockState": "UNLOCKED",
            "motorJam": false,
            "secureModeActive": false,
            "paired": true,
            "lockedState": "UNLOCKED",
            "pendingLockState": "NONE",
            "userString": "John Doe",
            "method": "REMOTE"
        }
    ]
    How can I grab this output and put each line of status into a virtual device? E.g. Entrance Lock Status = UNLOCKED'?

  • #2
    Looks like JSON, so I would look at running the command from HS and piping the command to a text file. A script can then read the text file which can then be parsed relatively easily using the JSON commands available within vb.net.
    HS 3.0.0.532: 1963 Devices 1141 Events
    Z-Wave 3.0.1.261: 122 Nodes on one Z-Net

    Comment


    • #3
      Originally posted by sparkman View Post
      Looks like JSON, so I would look at running the command from HS and piping the command to a text file. A script can then read the text file which can then be parsed relatively easily using the JSON commands available within vb.net.
      Thanks.Would someone be willing to provide an example? I'm not much of a coder

      Comment


      • #4
        So I've followed the directions from various posts to get the command to run in an event, but I'm stuck on the easiest part. If I open a command window and do

        Code:
         
         vsure user@example.com mypassword overview doorLockStatusList > C:\ProgramData\vsure\lockstatus.txt
        the text file is written out with the data. But if I have a batch file with the identical command and call that file in an event Click image for larger version

Name:	Capture.PNG
Views:	2
Size:	26.8 KB
ID:	1267139 the resulting text file is empty. Evidently I am not doing it correctly.

        Comment


        • #5
          Can you post the contents of your batch file?
          HS 3.0.0.532: 1963 Devices 1141 Events
          Z-Wave 3.0.1.261: 122 Nodes on one Z-Net

          Comment


          • #6
            Originally posted by politby View Post

            Thanks.Would someone be willing to provide an example? I'm not much of a coder
            There are a number of examples on the board already. Here's one that popped up first in the search: https://forums.homeseer.com/forum/de...-parser-script. If you run into issues, post your script here and I'll jump in to help.
            HS 3.0.0.532: 1963 Devices 1141 Events
            Z-Wave 3.0.1.261: 122 Nodes on one Z-Net

            Comment


            • #7
              Originally posted by politby View Post
              Hi,

              I have two door locks which are addressable via a Python API. This is on the same Windows machine as Homeseer. If I send a command from a console window, e.g.

              Code:
              vsure user@example.com mypassword overview doorLockStatusList
              I get a status output which looks like this:

              Code:
              [
              {
              "eventTime": "2018-12-16T09:37:14.000Z",
              "area": "Entrance",
              "deviceLabel": "XXX",
              "currentLockState": "UNLOCKED",
              "motorJam": false,
              "secureModeActive": false,
              "paired": true,
              "lockedState": "UNLOCKED",
              "pendingLockState": "NONE",
              "userString": "John Doe",
              "method": "THUMB"
              },
              {
              "eventTime": "2018-12-16T15:11:13.000Z",
              "area": "Laundry",
              "deviceLabel": "XXX",
              "currentLockState": "UNLOCKED",
              "motorJam": false,
              "secureModeActive": false,
              "paired": true,
              "lockedState": "UNLOCKED",
              "pendingLockState": "NONE",
              "userString": "John Doe",
              "method": "REMOTE"
              }
              ]
              How can I grab this output and put each line of status into a virtual device? E.g. Entrance Lock Status = UNLOCKED'?
              You can use my Datascraper script to do this easily.

              Download it from my site and use the following config :

              [Grab1]
              Path=<json path or URL>
              TextFile=0
              Encoding=
              Username=
              Password=
              Options=
              UserAgent=
              Devicemode=0
              StripHTML=0
              Pattern1=(?s)Entrance.*?currentLockState": "(.*?)",
              Pattern2=(?s)Laundry.*?currentLockState": "(.*?)",
              DeviceName1=Entrance Lock Status
              DeviceName2=Laundry Lock Status
              DeviceText1=[0]
              DeviceText2=[100]
              DeviceValue1=[0] [replace "UNLOCKED","0"][replace "LOCKED","100"]
              DeviceValue2=[100] [replace "UNLOCKED","0"][replace "LOCKED","100"]


              This is the result:

              Click image for larger version  Name:	u.png Views:	1 Size:	18.2 KB ID:	1267164
              Last edited by jon00; December 17th, 2018, 10:20 AM. Reason: Updated the config to set the device value of devices to 0 for unlocked and 100 for locked
              Jon

              Comment


              • #8
                Code:
                 
                 vsure user@example.com mypassword overview doorLockStatusList > C:\ProgramData\vsure\lockstatus.txt
                Exactly the same as the command line. Probably not the right way to do it.
                "vsure" is an actual command in the user's path.

                Don't laugh - I said I can't code

                Comment


                • #9
                  Originally posted by politby View Post
                  Code:
                  vsure user@example.com mypassword overview doorLockStatusList > C:\ProgramData\vsure\lockstatus.txt
                  Exactly the same as the command line. Probably not the right way to do it.
                  "vsure" is an actual command in the user's path.

                  Don't laugh - I said I can't code
                  Try adding a "pause" statement as the second line of the bat file and then look at the HS console when it executes. The pause should keep the command window open, although I haven't tried that myself.
                  HS 3.0.0.532: 1963 Devices 1141 Events
                  Z-Wave 3.0.1.261: 122 Nodes on one Z-Net

                  Comment


                  • #10
                    Originally posted by jon00 View Post

                    You can use my Datascraper script to do this easily.
                    Awesome! I think it's working. I would like to modify the status graphics but I'm not sure which values to use, from the .ini file I guessed that the script is changing UNLOCKED into 0 and LOCKED into 100 but that doesn't work. I can't seem to be able to do this in the same way as I did for other virtual devices.

                    Comment


                    • #11
                      Add the following to the ini file:

                      DeviceMode=2

                      This will allow you to set the status graphics from the value (0 or 100) but keep the device text (Locked/unlocked)

                      Alternatively use:

                      DeviceMode=3

                      This will allow you to set the status graphics and also set the status text from the value (0 or 100).
                      Jon

                      Comment


                      • #12
                        Originally posted by sparkman View Post

                        Try adding a "pause" statement as the second line of the bat file and then look at the HS console when it executes. The pause should keep the command window open, although I haven't tried that myself.
                        That didn't help. Could this have to do with the fact that I'm running Homeseer as a service (using AlwaysUp)? It's like the file is opened for writing but it just sits there.

                        Comment


                        • #13
                          Originally posted by politby View Post

                          That didn't help. Could this have to do with the fact that I'm running Homeseer as a service (using AlwaysUp)? It's like the file is opened for writing but it just sits there.
                          Possibly. Try running it on the console as a test and see if it works that way.
                          HS 3.0.0.532: 1963 Devices 1141 Events
                          Z-Wave 3.0.1.261: 122 Nodes on one Z-Net

                          Comment


                          • #14
                            Originally posted by sparkman View Post

                            Possibly. Try running it on the console as a test and see if it works that way.
                            Yes. It works when Homeseer is run from the desktop. So Homeseer needs to have a console window, apparently, even if command output is redirected to a file?

                            Comment


                            • #15
                              Originally posted by politby View Post

                              Yes. It works when Homeseer is run from the desktop. So Homeseer needs to have a console window, apparently, even if command output is redirected to a file?
                              Seems like that is the case although not sure if it's a HS thing or an AlwaysUp restriction.
                              HS 3.0.0.532: 1963 Devices 1141 Events
                              Z-Wave 3.0.1.261: 122 Nodes on one Z-Net

                              Comment

                              Working...
                              X