Announcement

Collapse
No announcement yet.

How to use JSON Control Interface GET response to obtain Device Status & Device Name?

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

    How to use JSON Control Interface GET response to obtain Device Status & Device Name?

    I am currently exploring the JSON Control Interface at:
    https://homeseer.com/support/homesee...nk/default.htm

    (1) Is anyone able to provide an example of the parameters that need to be specified when using:
    /JSON?request=getstatus&ref=##&location1=LOC1&location2=LOC2
    ... to perform the following:

    (1a) To obtain the status information for a single device using its device reference number?

    (1b) How to obtain the status information for all devices - whatever their location?


    (2) In addition, is anyone able to confirm the JSON Control Interface command that will return the HomeSeer Device Name ("Linear Switch Multilevel Node 132") for device Ref# 3738 below:

    ?


    Thanks in advance,

    #2
    Originally posted by ECS View Post
    I am currently exploring the JSON Control Interface at:
    https://homeseer.com/support/homesee...nk/default.htm

    (1) Is anyone able to provide an example of the parameters that need to be specified when using:
    /JSON?request=getstatus&ref=##&location1=LOC1&location2=LOC2
    ... to perform the following:

    (1a) To obtain the status information for a single device using its device reference number?

    (1b) How to obtain the status information for all devices - whatever their location?


    (2) In addition, is anyone able to confirm the JSON Control Interface command that will return the HomeSeer Device Name ("Linear Switch Multilevel Node 132") for device Ref# 3738 below:

    ?


    Thanks in advance,
    If you leave out the ref and location items like

    Code:
    /JSON?request=getstatus
    That will dump everything. In a browser it's not pretty. But that will give all the device id's location information status "friendly name" etc. Then you can play with the other options. You probably want to us something like Postman for testing and playing with to get a pretty output/view of the json data.

    Comment


      #3
      Originally posted by ECS View Post
      I am currently exploring the JSON Control Interface at:
      https://homeseer.com/support/homesee...nk/default.htm

      (1) Is anyone able to provide an example of the parameters that need to be specified when using:
      /JSON?request=getstatus&ref=##&location1=LOC1&location2=LOC2
      ... to perform the following:

      (1a) To obtain the status information for a single device using its device reference number?
      /JSON?request=getstatus&ref=3738

      (1b) How to obtain the status information for all devices - whatever their location?
      /JSON?request=getstatus



      (2) In addition, is anyone able to confirm the JSON Control Interface command that will return the HomeSeer Device Name ("Linear Switch Multilevel Node 132") for device Ref# 3738 below:

      ?
      /JSON?request=getstatus&ref=3738 but you get back a JSON response which you will need to parse. You are not able to return just the device name.



      Thanks in advance,
      Len


      HomeSeer Version: HS3 Pro Edition 3.0.0.435
      Linux version: Linux homeseer Ubuntu 16.04 x86_64
      Number of Devices: 633
      Number of Events: 773

      Enabled Plug-Ins
      2.0.54.0: BLBackup
      2.0.40.0: BLLAN
      3.0.0.48: EasyTrigger
      30.0.0.36: RFXCOM
      3.0.6.2: SDJ-Health
      3.0.0.87: weatherXML
      3.0.1.190: Z-Wave

      Comment


        #4
        Originally posted by ECS View Post
        I am currently exploring the JSON Control Interface at:
        https://homeseer.com/support/homesee...nk/default.htm

        (1) Is anyone able to provide an example of the parameters that need to be specified when using:
        /JSON?request=getstatus&ref=##&location1=LOC1&location2=LOC2
        ... to perform the following:

        (1a) To obtain the status information for a single device using its device reference number?

        (1b) How to obtain the status information for all devices - whatever their location?

        (2) In addition, is anyone able to confirm the JSON Control Interface command that will return the HomeSeer Device Name ("Linear Switch Multilevel Node 132") for device Ref# 3738 below:

        ?


        Thanks in advance,
        It would be helpful to know exactly what you are trying to do. I use JSON quite a bit. My experience has been mixed. Some of the HS3 JSON commands do not work. Others are heavily dependent on syntax issues and how they are being used in a script. And when HS3 sends/receives incorrectly formatted JSON commands, no error messages appear. This makes troubleshooting very difficult.

        Steve Q
        HomeSeer Version: HS3 Pro Edition 3.0.0.368, Operating System: Microsoft Windows 10 - Home, Number of Devices: 373, Number of Events: 666, Enabled Plug-Ins
        2.0.83.0: BLRF, 2.0.10.0: BLUSBUIRT, 3.0.0.75: HSTouch Server, 3.0.0.58: mcsXap, 3.0.0.11: NetCAM, 3.0.0.36: X10, 3.0.1.25: Z-Wave,Alexa,HomeKit

        Comment


          #5
          https://homeseer.com/support/homesee...nk/default.htm

          Comment


            #6
            Makes sense as I've done similar.

            First, can you name the devices in your external application to contain both a friendly name and a delimiter followed by the HS reference number? If so, then your CLI can just parse the passed inputs (x1 - x#) to determine the appropriate reference number. eg. FrontPorchLight,2425

            I've also coded cross reference from name to reference number in my own scripts too.



            To leverage JSON, you will need to call the JSON interface a few times in your CLI to accomplish what you are trying to do. I'll try to keep it high level.

            Assuming x1 = FrontPorchLight and x2 = 0 (the value).

            First, you can find the HS reference number via json.
            request=getstatus&ref=all&location1=<LOC1>&location2=<LOC2>

            You set LOC1 and LOC2 to restrict the search to your specific external application's HS devices.

            JSON returns a list of devices in LOC1 and 2, which contains device status including it's name. You loop through each device matching HS's name and the sensor name (x1).

            Once you match, the json data contains the matching HS reference number.

            You then call ControlDeviceByValue to update the HS device.

            request=controldevicebyvalue&ref=2425&value=0 (x2).

            You can also call request=controldevicebylabel&ref=2425&label=Off


            For example:
            /JSON?request=getstatus&ref=all&location1=Backup&location2=Se rver

            returns (see attached image).

            Then you call
            /JSON?request=controldevicebyvalue&ref=942&value=0

            or in my example,
            /JSON?request=controldevicebylabel&ref=942&label=Success



            You could do similar with the ASCII interface, by using gs to get a list of all devices vs the getstatus json call. It returns reference number, name and location 1 and 2.

            To update you would call cv or cl with the reference number obtained from gs.
            Attached Files
            Len


            HomeSeer Version: HS3 Pro Edition 3.0.0.435
            Linux version: Linux homeseer Ubuntu 16.04 x86_64
            Number of Devices: 633
            Number of Events: 773

            Enabled Plug-Ins
            2.0.54.0: BLBackup
            2.0.40.0: BLLAN
            3.0.0.48: EasyTrigger
            30.0.0.36: RFXCOM
            3.0.6.2: SDJ-Health
            3.0.0.87: weatherXML
            3.0.1.190: Z-Wave

            Comment


              #7
              I doubt I can add much to this discussion. But I will jump back in if I have something to offer.

              Steve Q
              HomeSeer Version: HS3 Pro Edition 3.0.0.368, Operating System: Microsoft Windows 10 - Home, Number of Devices: 373, Number of Events: 666, Enabled Plug-Ins
              2.0.83.0: BLRF, 2.0.10.0: BLUSBUIRT, 3.0.0.75: HSTouch Server, 3.0.0.58: mcsXap, 3.0.0.11: NetCAM, 3.0.0.36: X10, 3.0.1.25: Z-Wave,Alexa,HomeKit

              Comment


                #8
                How to Detect if Devices Connected to HomeSeer have Changed / JSON Fault Handling

                Thanks for all the input - particularly from lveatch.

                FYI, it is expected that a HomeSeer HomeTroller Zee S2 will be used to only host up to 50 devices.

                In an attempt to make the intermediate program as 'bulletproof' as possible I would be grateful for further advice regarding how to handle the conditions described below:

                (1) Rather than using:
                request=getstatus&ref=all
                (assuming this is a valid command)
                each time a friendly device name needed mapping to its reference number I was thinking of the intermediate program to maintain its own device list - but if this is done - then how would the intermediate program know if a device has been added or removed from HomeSeer (and needs to refresh the configuration file containing the device list)?


                (2) It is hoped to only issue valid commands to JSON ... however is JSON ever likely to return an error and if so how should errors be handled?


                (3a) Assuming a reliable network connection then is JSON guaranteed to always respond?

                (3b) Otherwise, what is the maximum length of time that should be be allowed for JSON to respond to a request before declaring a timeout?

                (3c) How is a JSON fault condition detected?

                (3d) If a timeout is declared then what recovery action should be taken by the calling program (before sending another POST or GET response to JSON)?


                (4a) Is JSON capable of queuing command requests - or is this to be avoided?

                (4b) If JSON is capable of queuing requests, then is there a minimum time that should be observed to allow JSON to respond - before the next command is presented?


                (5) The only information that I have on JSON is the Message Board and this discussion (Thanks again) ... otherwise the only other information source on JSON that I have found is at:
                https://homeseer.com/support/homesee...nk/default.htm
                ... is there any other information source(s) of how to use JSON that I should be using?

                Any advice gratefully accepted.

                Comment


                  #9
                  Happy to help.

                  I'll try to assist more with your list of questions; although, I don't think I will directly answer each question and address the basics.

                  In this case, JSON is a message format that is communicated via http(s). Much like speaking English or French via the telephone.

                  Your script is going act like a web browser to send a message (JSON format) to a web server (homeseer). This is done by connecting to http://your-homeseer-ip/

                  By adding JSON to the end of that url, you are stating you wish to communicate in the JSON language i.e. JSON data format. Nonetheless, you are communicating via normal http(s) protocol. Just like you are currently doing on this forum.

                  The network reliability, JSON robustness, errors, queues, etc are not part of JSON, rather http. Your program will need to handle thes. For example: after calling homeseer with a function, you will need to check for the typical and common http errors, 200 is ok, 404 not found, 5xx error and handle those directly, either retry if needed or queue them for later processing. Then you will need to check the JSON response for success.


                  For example, calling JSON?request=getstatus&ref=all is the example.

                  If I call mis-type the function adding an extra "s", the http layer works successfully, however, homeseer JSON API will send back a response that there was an error.

                  JSON?request=getstatuss&ref=all
                  { "Response":"Error, bad request" }


                  I hope this helps.
                  Len


                  HomeSeer Version: HS3 Pro Edition 3.0.0.435
                  Linux version: Linux homeseer Ubuntu 16.04 x86_64
                  Number of Devices: 633
                  Number of Events: 773

                  Enabled Plug-Ins
                  2.0.54.0: BLBackup
                  2.0.40.0: BLLAN
                  3.0.0.48: EasyTrigger
                  30.0.0.36: RFXCOM
                  3.0.6.2: SDJ-Health
                  3.0.0.87: weatherXML
                  3.0.1.190: Z-Wave

                  Comment


                    #10
                    How to Detect if the Devices Connected to HomeSeer have Changed

                    Thanks again to lveatch for the previous posting - very helpful!

                    I think that covers fault handling for now ... but there is one further issue that I could do with some advice on as follows:

                    As previously explained, the intermediate program would need to both build & maintain its own device list for the mapping of (textual) friendly names to their HomeSeer device number.

                    OK, so a device list could be built using:
                    request=getstatus&ref=all
                    ... and by parsing the output obtained from this command, then the required information can be extracted.
                    >> NB: I haven't tested this command, but I assume that the about GET request would return all devices connected to HomeSeer - whatever their location. <<

                    But with regard to maintaining a list, how would an intermediate program determine - or be able to discover using JSON - whether a device has been added or removed from HomeSeer and its own configuration file (containing an out-of-date device list) needed to be re-built?

                    Please advise ...

                    Comment


                      #11
                      Originally posted by ECS View Post
                      Thanks again to lveatch for the previous posting - very helpful!

                      I think that covers fault handling for now ... but there is one further issue that I could do with some advice on as follows:

                      As previously explained, the intermediate program would need to both build & maintain its own device list for the mapping of (textual) friendly names to their HomeSeer device number.

                      OK, so a device list could be built using:
                      request=getstatus&ref=all
                      ... and by parsing the output obtained from this command, then the required information can be extracted.
                      >> NB: I haven't tested this command, but I assume that the about GET request would return all devices connected to HomeSeer - whatever their location. <<

                      But with regard to maintaining a list, how would an intermediate program determine - or be able to discover using JSON - whether a device has been added or removed from HomeSeer and its own configuration file (containing an out-of-date device list) needed to be re-built?

                      Please advise ...
                      I think you would have to do this in the intermediate program by regular query - there is unlikely to be a huge amount of changing to the device list so you would not have to do it that often. There is a function in the HSEvent callback to notify a plugin when something changes in HS such as a device added/removed but this has not been added to the JSON interface (https://homeseer.com/support/homesee...ereventcb).htm). You could develop your own plugin that posted this notification to a URL however if it was crucial.

                      Comment


                        #12
                        How to Detect if the Devices Connected to HomeSeer have Changed

                        If the date/time recorded during the previous check is earlier than the date/time during a new check then this could be used as a trigger to re-build a HomeSeer device list.

                        Does JSON or other have a date/time stamp as to when HomeSeer's device list was last updated that can be checked?

                        Comment


                          #13
                          Originally posted by ECS View Post
                          As previously explained, the intermediate program would need to both build & maintain its own device list for the mapping of (textual) friendly names to their HomeSeer device number.
                          What concern do you have that is requiring this need of the intermediate program / device list? Are you expecting a large amount of traffic from your external program and you have homeseer performance concerns?

                          Web API's like this JSON interface is meant for external triggered events to interact with homeseer. Consuming the list of references to obtain the reference id to make additional JSON requests should not cause performance issues.

                          Running getstatus&ref=all against my system from a second server within the same network retrieved 616 devices in 0.25 seconds and in reality only used 0.008 seconds of cpu time.

                          time curl -s 'http://homeseer.lras.net:82/JSON?request=getstatus&ref=all' > /dev/null

                          real 0m0.250s
                          user 0m0.008s
                          sys 0m0.000s

                          If you futher restrict the JSON query to either location1 or location2 information, then the response time is considerably less. The following resulted in 12 devices returned by restricting on the homeseer room name.

                          time curl -s 'http://homeseer.lras.net:82/JSON?request=getstatus&ref=all&location1=backup'

                          real 0m0.028s
                          user 0m0.004s
                          sys 0m0.000s


                          Personally and just my opinion, unless you expect a incredibly large amount updates from your "other applications", I would not worry about the intermediate program and just utilize JSON for multiple queries when your external applications have changes to send to homeseer.
                          Len


                          HomeSeer Version: HS3 Pro Edition 3.0.0.435
                          Linux version: Linux homeseer Ubuntu 16.04 x86_64
                          Number of Devices: 633
                          Number of Events: 773

                          Enabled Plug-Ins
                          2.0.54.0: BLBackup
                          2.0.40.0: BLLAN
                          3.0.0.48: EasyTrigger
                          30.0.0.36: RFXCOM
                          3.0.6.2: SDJ-Health
                          3.0.0.87: weatherXML
                          3.0.1.190: Z-Wave

                          Comment

                          Working...
                          X