Originally posted by bandook
View Post
Announcement
Collapse
No announcement yet.
XML HTTP RESTful API for HS3 - Discussion Thread
Collapse
X
-
Originally posted by jrjmpls7 View PostI 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?
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
-
Originally posted by NeverDie View PostAnyone 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
-
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¶m1=Homeseer Systeem Receiver1';
$xml = simplexml_load_file($url);
PHP Code:echo $xml->deviceInfo[0]['name'];
PHP Code:SimpleXMLElement Object ( [device] => SimpleXMLElement Object ( [@attributes] => Array ( [name] => Receiver1 [id] => 7874 [type] => Receiver [value] => 3 [address] => X_REC[1]Q [code] => [canDim] => False [lastChange] => 30-11-2013 22:31:43 [firstLocation] => Homeseer [secondLocation] => Systeem ) ) )
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>
Maybe someone can post the php code that he uses?
Comment
-
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];
Comment
-
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
-
Originally posted by claude View PostLooks 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
-
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?
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.
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.
Comment
-
Originally posted by claude View PostI 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
-
Originally posted by RedTechie View PostAh 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 ...
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
-
Originally posted by claude View PostInteresting 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?
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
-
Originally posted by RedTechie View PostThanks for the feedback! I will look into that when I find some time to post an updated version!...
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.
Comment
Comment