Announcement

Collapse
No announcement yet.

XML HTTP RESTful API for HS3 - Discussion Thread

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

    #16
    Originally posted by bandook View Post
    Just to update and bring some conclusion to my issue, it was indeed a simple error. I just needed this:

    Code:
    if response.read() == 'True':
    So now I am able to toggle my device with one action in eventghost with:

    Code:
     
      response = urllib2.urlopen(getstatus)
            if response.read() == 'True':
                urllib2.urlopen(turnoffdevice)
            else:
             urllib2.urlopen(turnondevice)
    Eventually I'll finish the plugin and enable you to enter each device you want to control in the plugin config, and create actions for each device. Shouldn't be crazy hard but my learning curve is steep so it will take me awhile.
    Great to hear! C# has some of those types of problems as well. But luckily Visual Studio warns you, that you can't use a method as a variable.

    Comment


      #17
      I can't post there either.

      Is there no way to just request the device status/value rather than having to ask for on, off etc. What if I want to get the temp of a thermostat or the status of a security system?

      Comment


        #18
        Originally posted by jrjmpls7 View Post
        I can't post there either.

        Is there no way to just request the device status/value rather than having to ask for on, off etc. What if I want to get the temp of a thermostat or the status of a security system?
        I will look into adding a call in the next release to just request the status of a device. I have no guarantees that it will work with a thermostat or security alarm as I don't have those devices tied into my HomeSeer setup to test with.

        Also you are free to modify the code if you don't like how it works currently I can't necessarily support the modified code but I will try my best.

        One thing you can do is call the device list function and get the device's value that way?

        Comment


          #19
          I think that your suggestion would be a valuable addition to the API. I'm having fun learning PHP with your API. And I really would like to be able to request the status without parameter2.

          thanks!

          Comment


            #20
            Anyone know whether this RESTful interface will work for HS2/HS2PRO? I do own a license for HS3, but need the stability of HS2PRO. Am hoping the RESTful interface is well matched for an Arduino Yun, which is apparently already RESTful.

            Comment


              #21
              Originally posted by NeverDie View Post
              Anyone know whether this RESTful interface will work for HS2/HS2PRO? I do own a license for HS3, but need the stability of HS2PRO. Am hoping the RESTful interface is well matched for an Arduino Yun, which is apparently already RESTful.
              I'm not sure, but if it doesn't you might want to look at tenHsServer. Worked very well for me in HS2.

              Comment


                #22
                I'm playing with the API and I'm having problems using the responses in PHP/HMTL

                I use the following PHP code to retreive the information about a device

                PHP Code:
                $url 'http://192.168.0.99:81/HomeSeer_REST_API.aspx?function=getdeviceinfo&param1=Homeseer Systeem Receiver1';
                $xml simplexml_load_file($url); 
                In the HTML I place the following to show the name:
                PHP Code:
                echo $xml->deviceInfo[0]['name']; 
                The echo gives me the following code:

                PHP Code:
                SimpleXMLElement Object ( [device] => SimpleXMLElement Object ( [@attributes] => Array ( [name] => Receiver1 [id] => 7874 [type] => Receiver [value] => [address] => X_REC[1][code] => [canDim] => False [lastChange] => 30-11-2013 22:31:43 [firstLocation] => Homeseer [secondLocation] => Systeem ) ) ) 
                ik would have expected the name.

                The code doesn't show up as I expected from the openingpost:

                HTML Code:
                <deviceInfo>
                <device name="Receiver1" id="7874" type="Receiver" value="3" address="X_REC[1]Q" co-de="" canDim="False" lastChange="30-11-2013 22:31:43" firstLocation="Homeseer" secondLocation="Systeem" />
                </deviceInfo>
                can you help me in showing what I'm doing wrong? I have not much experience in php and am googleing for hours now

                Maybe someone can post the php code that he uses?

                Comment


                  #23
                  I found it! For other users, this is how I now solved the 'issue'. This is how to display variables from the XML from this rest-api.

                  PHP Code:
                  $xml simplexml_load_file($url);
                  echo 
                  $xml->device[0][name]; 
                  But still, I would love to see some php scripts you guys use. I can use them to learn php in this specific case. It would help me (and others?) a lot!

                  Comment


                    #24
                    Looks very promising. Here's my experience with this ASP so far.

                    1- I'm an 'all Insteon' installation. The Get/Set Device status by ID work just fine
                    2- 'ListFirstLocations', 'ListFirstLocations', 'ListEvents all' and 'ListDevices all' return an empty screen, using IE10 and Google Chrome
                    3- When using GetDeviceInfo, if Location1, Location2 and Name are each made of non-blank characters, I get an empty response; if any element includes blanks, I get a 404. I tried a single quote and a double quote as delimiters: no luck.

                    So a few questions:

                    1- when using functions with 'Full' device names, what should the delimiter be to differenciate the 3 elements?
                    2- Any idea why I'm getting blank responses? At first I thought maybe because of Insteon versus Z-wave, but events also?

                    The biggest show stopper for me is not being able to use GetDeviceInfo. Seeing Status by ID works, is there a chance you could add 'GetDeviceInfo by ID'?

                    Comment


                      #25
                      Originally posted by claude View Post
                      Looks very promising. Here's my experience with this ASP so far.

                      1- I'm an 'all Insteon' installation. The Get/Set Device status by ID work just fine
                      2- 'ListFirstLocations', 'ListFirstLocations', 'ListEvents all' and 'ListDevices all' return an empty screen, using IE10 and Google Chrome
                      3- When using GetDeviceInfo, if Location1, Location2 and Name are each made of non-blank characters, I get an empty response; if any element includes blanks, I get a 404. I tried a single quote and a double quote as delimiters: no luck.

                      So a few questions:

                      1- when using functions with 'Full' device names, what should the delimiter be to differenciate the 3 elements?
                      2- Any idea why I'm getting blank responses? At first I thought maybe because of Insteon versus Z-wave, but events also?

                      The biggest show stopper for me is not being able to use GetDeviceInfo. Seeing Status by ID works, is there a chance you could add 'GetDeviceInfo by ID'?

                      I'm thrilled to hear that Get/Set works with Insteon! Those were the functions I was most sceptable about. HomeSeer did a nice job of creating a interface API (CAPI) for controlling devices

                      Regarding the GetDeviceInfo call, so are you saying you only have say a Location1 and no Location2 and it throws a 404?



                      Your questions:
                      1. As of right now only List Devices supports multiple delimited devices. See the official thread for more information on delimited parameters (http://board.homeseer.com/showthread.php?p=1089120). Other function calls that do not support delimited values will require multiple requests to the API.

                      2. Have you tried "View source" in those browsers? I noticed that some browsers don't like to parse out the XML properly.

                      Comment


                        #26
                        Originally posted by RedTechie View Post
                        ... Regarding the GetDeviceInfo call, so are you saying you only have say a Location1 and no Location2 and it throws a 404?
                        I have all 3 elements. Here's an example of what I'm testing and getting a 404 on:Where:
                        Location-1 is [2:SBinv]
                        Location-2 is
                        Device name is SBinv plafond

                        Here's what I get back:

                        Notice how the '' from Location-2 gets returned as�. But then if I take out Location-1,I get a null return deviceinfo /deviceinfo<DEVICEINFO></DEVICEINFO>

                        Originally posted by RedTechie View Post
                        ... Your questions:
                        1. As of right now only List Devices supports multiple delimited devices. See the official thread for more information on delimited parameters (http://board.homeseer.com/showthread.php?p=1089120). Other function calls that do not support delimited values will require multiple requests to the API.
                        Don't worry about this one. I now suspect you simply take the sum of all 3 elements, as is, and use that as a parameter in your call (DeviceValueByName ?)

                        Originally posted by RedTechie View Post
                        ... 2. Have you tried "View source" in those browsers? I noticed that some browsers don't like to parse out the XML properly.
                        You're right, 'View source' tells it all. I was using IE to test out, I should have used a TCP client to test

                        Comment


                          #27
                          Originally posted by claude View Post
                          I have all 3 elements. Here's an example of what I'm testing and getting a 404 on:Where:
                          Location-1 is [2:SBinv]
                          Location-2 is
                          Device name is SBinv plafond

                          Here's what I get back:

                          Notice how the '' from Location-2 gets returned as�. But then if I take out Location-1,I get a null return deviceinfo /deviceinfo<DEVICEINFO></DEVICEINFO>


                          Don't worry about this one. I now suspect you simply take the sum of all 3 elements, as is, and use that as a parameter in your call (DeviceValueByName ?)


                          You're right, 'View source' tells it all. I was using IE to test out, I should have used a TCP client to test

                          Ah I see what's going on. Your location names have non-safe URL characters in them. I will see if I can sanitize them, if they pass through ok, but I don't think they are, as it's a limitation with the RFC specification (http://www.ietf.org/rfc/rfc1738.txt). That may *possibly* be fixed with POST/PUT's HTTP verbs. But I have yet to implement those HTTP verb options for this API.

                          At this time the functions that will break for you are:
                          - Get Devices For Location
                          - Get Device Information
                          - Get Device Status By Name
                          - Set Device Status By Name

                          As all of those use Location1 or Location2 in the URL. Luckily you can still set a device and retrieve its status via "Get/Set Device Status By ID".

                          Any place you see "Device Full Name" as a parameter that means (Location1 Location2 DeviceName) In that order, space separated. That's a limitation of the back-end calls HS3 makes.

                          Comment


                            #28
                            Originally posted by RedTechie View Post
                            Ah I see what's going on. Your location names have non-safe URL characters in them. I will see if I can sanitize them, if they pass through ok, but I don't think they are, as it's a limitation with the RFC specification (http://www.ietf.org/rfc/rfc1738.txt). That may *possibly* be fixed with POST/PUT's HTTP verbs. But I have yet to implement those HTTP verb options for this API ...
                            Interesting reading (RFC), thanks. If I got this right, my problem is using the brackets "[" and "]" in one of the 3 elements of the Full device name, accented characters being ok. Unfortunately, I've got those hard coded in several areas.

                            The only other function I need from your utility is GetDeviceInfo which is currently using the Full name as parameter. As mentioned before, I would be grateful if you would add a GetDeviceInfoById version. What do you think?

                            Comment


                              #29
                              Originally posted by claude View Post
                              Interesting reading (RFC), thanks. If I got this right, my problem is using the brackets "[" and "]" in one of the 3 elements of the Full device name, accented characters being ok. Unfortunately, I've got those hard coded in several areas.

                              The only other function I need from your utility is GetDeviceInfo which is currently using the Full name as parameter. As mentioned before, I would be grateful if you would add a GetDeviceInfoById version. What do you think?
                              Thanks for the feedback! I will look into that when I find some time to post an updated version!

                              But for the time being I got a bit of a workaround for you. The "List Devices" function is essentially the same as the "Get Device Info" function, with the exception that "Get Device Info" is singular for the device name you specify.

                              So what you can do is in your code just make a call to the "List Devices" function then you can parse through that list and find the exact device you want by looking at the Device's name, ID, Location1 or Location2 values.

                              Comment


                                #30
                                Originally posted by RedTechie View Post
                                Thanks for the feedback! I will look into that when I find some time to post an updated version!...
                                Looking forward to it, great work, thanks.

                                Originally posted by RedTechie View Post
                                ... just make a call to the "List Devices" function then you can parse through that list and find the exact device you want by looking at the Device's name, ID, Location1 or Location2 values.
                                Makes sense.

                                Comment

                                Working...
                                X