Your Universal Remote Control Center
RemoteCentral.com
Philips Pronto Professional Forum - View Post
Previous section Next section Previous page Next page Up level
Up level
The following page was printed from RemoteCentral.com:

Login:
Pass:
 
 

Page 1 of 2
Topic:
Pronto Rest_API.aspx
This thread has 15 replies. Displaying all posts.
Post 1 made on Tuesday September 8, 2020 at 13:49
Fischi
Long Time Member
Joined:
Posts:
January 2011
91
Hi,
I've found an interesting feature in my HomeSeer system:

- HTTP REST based API for HS3 -

After putting XXX.XXX.XXX.XX:85/HomeSeer_REST_API.aspx?function=getdevicestatusvaluebyid& param1=2012& param2=value into my browser


I get 40

This is the value I want to have

XXX.XXX.XXX.XX:85 is my HomeSeer IP and port.

How to get this value (40 in this case) into my TSU ?

Regards,
Fischi

Last edited by Fischi on September 8, 2020 14:08.
Post 2 made on Tuesday September 8, 2020 at 15:20
Lyndel McGee
RC Moderator
Joined:
Posts:
August 2001
12,609
Fischi, Is this related to your post in the other thread?

I answered in the other thread.

Is your question related to how to build the HTTP request to get the data or how to parse the value out of the response you receive?

I also sent you an email on same subject.

Thanks
Lyndel

Last edited by Lyndel McGee on September 8, 2020 15:28.
Lyndel McGee
Philips Pronto Addict/Beta Tester
OP | Post 3 made on Tuesday September 8, 2020 at 15:43
Fischi
Long Time Member
Joined:
Posts:
January 2011
91
Thanks Lyndel,
My question is related to how to build the HTTP request to get the data and show them in a widget.
I think using the Rest Api does not make it necessary to parse the data.
The response is only 40   -  no more text or so
This is the value I want to get in a widget.

Best regards,
Fischi
Post 4 made on Tuesday September 8, 2020 at 18:16
Lyndel McGee
RC Moderator
Joined:
Posts:
August 2001
12,609
Are you using the Philips HTTP Library? If so, it's pretty simple.

Use the getHTTP function. You will have to edit your original URL below to supply the correct IP address. I presume you have a widget on current page with a tag of "MyLabel".

var myURL = "htt_p://XXX.XXX.XXX.XX:85/HomeSeer_REST_API.aspx?function=getdevicestatusvaluebyid&m1=2012&m2=value";
// remove the underscore in htt_p above.
function installResponse(textualResponse) {
GUI.widget("MyLabel").label =textualResponse;
}

com.philips.HttpLibrary.getHTTP(myURL, installResponse);

Last edited by Lyndel McGee on September 8, 2020 22:17.
Lyndel McGee
Philips Pronto Addict/Beta Tester
Post 5 made on Tuesday September 8, 2020 at 21:57
randman
Long Time Member
Joined:
Posts:
June 2003
376
I use HomeSeer's JSON interface. For example:

http://IP Address/JSON?request=getstatus&ref=#

For details and example output see:

[Link: homeseer.com]

I'm not familiar with HomeSeer_REST_API.aspx (and not sure why to use it since HomeSeer has the aforementioned JSON API, unless maybe it precludes the need to parse the JSON response?).

But either way, the idea would be to use http similar to what was mentioned in:

[Link: remotecentral.com]

Then, once you've extracted the status value you want, do as Lyndel mentioned.
Post 6 made on Tuesday September 8, 2020 at 22:19
Lyndel McGee
RC Moderator
Joined:
Posts:
August 2001
12,609
I vote for Randmanís approach but either one will work.
Lyndel McGee
Philips Pronto Addict/Beta Tester
OP | Post 7 made on Wednesday September 9, 2020 at 05:59
Fischi
Long Time Member
Joined:
Posts:
January 2011
91
On September 8, 2020 at 22:19, Lyndel McGee said...
I vote for Randmanís approach but either one will work.

Thank you very much Lyndel, can you also give me a complete solution for Randman's (Json) approach ?
I've tried it but I didn't get it running.


Best regards,
Fischi
Post 8 made on Wednesday September 9, 2020 at 10:54
randman
Long Time Member
Joined:
Posts:
June 2003
376
Suppose you want to get the status of a particular HomeSeer device. Below is the URI to request the status:

http:// HOMESEER-IP-ADDRESS/JSON?request=getstatus&ref=349

"349" above is the HomeSeer reference ID of the device. Of course, your actual device's reference number will be different.

So, above URL will return a structure similar to:

{
† "Name": "HomeSeer Devices",
† "Version": "1.0",
† "Devices": [
† † {
† † † "ref": 349,
† † † "name": "Alert - Sensor Color",
† † † "location": "Virtual",
† † † "location2": "Alerts",
† † † "value": 0,
† † † "status": "Off",
† † † "device_type_string": "",
† † † "last_change": "/Date(1599661839059-0400)/",
† † † "relationship": 0,
† † † "hide_from_view": false,
† † † "associated_devices": [],
† † † "device_type": {
† † † † "Device_API": 0,
† † † † "Device_API_Description": "No API",
† † † † "Device_Type": 0,
† † † † "Device_Type_Description": "Type 0",
† † † † "Device_SubType": 0,
† † † † "Device_SubType_Description": ""
† † † },
† † † "device_type_values": null,
† † † "UserNote": "",
† † † "UserAccess": "Any",
† † † "status_image": "images/HomeSeer/contemporary/off.gif",
† † † "voice_command": "",
† † † "misc": 4368,
† † † "interface_name": ""
† † }
† ]
}

What you care about is the Devices[0].value above.

Your Javascript would be similar to the pseudo-code below. At this time, I don't have access to the PC that I use for my Pronto, so the code below hasn't been tested, but should be close enough to get you going:

var HomeSeer = {};
HomeSeer.IP = "x.x.x.x"; // assign HomeSeer IP here
// Below example assumes that HomeSeer is
// configured to not require user/password when
// request coming from local LAN:
HomeSeer.msgPrefix = "http://" + HomeSeer.IP + "/JSON?request=";

...

# ref is the HomeSeer Ref # of the device.
function getStatus(ref)
{
†† var msg = "", msgSuffix = "";
†† msgSuffix = "getstatus&ref=" + ref;
†† msg = HomeSeer.msgPrefix + msgSuffix;
†† com.philips.HttpLibrary.getHTTP(msg, processResponse);
}

// This is the callback
function processResponse(rcvd)
{
†† var jsonObj = JSON.parse(rcvd);
†† var status = jsonObj.Devices[0].value;
}



Once you have the device's status in the status variable, you can then do what you need with status, such as what Lyndel had suggested earlier:

GUI.widget("MyLabel").label = status;
OP | Post 9 made on Wednesday September 9, 2020 at 11:23
Fischi
Long Time Member
Joined:
Posts:
January 2011
91
On September 9, 2020 at 10:54, randman said...
Suppose you want to get the status of a particular HomeSeer device. Below is the URI to request the status:

http:// HOMESEER-IP-ADDRESS/JSON?request=getstatus&ref=349

"349" above is the HomeSeer reference ID of the device. Of course, your actual device's reference number will be different.

So, above URL will return a structure similar to:

{
† "Name": "HomeSeer Devices",
† "Version": "1.0",
† "Devices": [
† † {
† † † "ref": 349,
† † † "name": "Alert - Sensor Color",
† † † "location": "Virtual",
† † † "location2": "Alerts",
† † † "value": 0,
† † † "status": "Off",
† † † "device_type_string": "",
† † † "last_change": "/Date(1599661839059-0400)/",
† † † "relationship": 0,
† † † "hide_from_view": false,
† † † "associated_devices": [],
† † † "device_type": {
† † † † "Device_API": 0,
† † † † "Device_API_Description": "No API",
† † † † "Device_Type": 0,
† † † † "Device_Type_Description": "Type 0",
† † † † "Device_SubType": 0,
† † † † "Device_SubType_Description": ""
† † † },
† † † "device_type_values": null,
† † † "UserNote": "",
† † † "UserAccess": "Any",
† † † "status_image": "images/HomeSeer/contemporary/off.gif",
† † † "voice_command": "",
† † † "misc": 4368,
† † † "interface_name": ""
† † }
† ]
}

What you care about is the Devices[0].value above.

Your Javascript would be similar to the pseudo-code below. At this time, I don't have access to the PC that I use for my Pronto, so the code below hasn't been tested, but should be close enough to get you going:

var HomeSeer = {};
HomeSeer.IP = "x.x.x.x"; // assign HomeSeer IP here
// Below example assumes that HomeSeer is
// configured to not require user/password when
// request coming from local LAN:
HomeSeer.msgPrefix = "http://" + HomeSeer.IP + "/JSON?request=";

...

# ref is the HomeSeer Ref # of the device.
function getStatus(ref)
{
†† var msg = "", msgSuffix = "";
†† msgSuffix = "getstatus&ref=" + ref;
†† msg = HomeSeer.msgPrefix + msgSuffix;
†† com.philips.HttpLibrary.getHTTP(msg, processResponse);
}

// This is the callback
function processResponse(rcvd)
{
†† var jsonObj = JSON.parse(rcvd);
†† var status = jsonObj.Devices[0].value;
}



Once you have the device's status in the status variable, you can then do what you need with status, such as what Lyndel had suggested earlier:

GUI.widget("MyLabel").label = status;

Many thanks Randman, I'll try it out.

Best regards, Fischi
Post 10 made on Wednesday September 9, 2020 at 11:26
Lyndel McGee
RC Moderator
Joined:
Posts:
August 2001
12,609
On September 9, 2020 at 05:59, Fischi said...
Thank you very much Lyndel, can you also give me a complete solution for Randman's (Json) approach ?
I've tried it but I didn't get it running.

Best regards,
Fischi

If you are still having issues, either post the script you are attempting to use here or email me a copy of the config.

If emailing, make sure that you have both the philips http library and your JSON library referenced in the XCF as I know at one point, I might have sent you an updated HTTP library that exports a few more symbols such as UTF8 decode, etc....
Lyndel McGee
Philips Pronto Addict/Beta Tester
OP | Post 11 made on Wednesday September 9, 2020 at 13:28
Fischi
Long Time Member
Joined:
Posts:
January 2011
91
On September 8, 2020 at 18:16, Lyndel McGee said...
Are you using the Philips HTTP Library? If so, it's pretty simple.

Use the getHTTP function. You will have to edit your original URL below to supply the correct IP address. I presume you have a widget on current page with a tag of "MyLabel".

var myURL = "htt_p://XXX.XXX.XXX.XX:85/HomeSeer_REST_API.aspx?function=getdevicestatusvaluebyid&m1=2012&m2=value";
// remove the underscore in htt_p above.
function installResponse(textualResponse) {
GUI.widget("MyLabel").label =textualResponse;
}

com.philips.HttpLibrary.getHTTP(myURL, installResponse);

Lyndel,
I have this running OK, I'll try Randman's approach a liitle bit later.
My question is :
I have multiple devices -not only 2012- . (getdevicestatusvaluebyid&m1=2012)
How to get the data from other devices (2008,846,2034 ...) into the in the appropriate widgets ?

&m2=value is always the same, only &m1= is different depending on the device number
I hope you know what I mean
Fischi
Post 12 made on Wednesday September 9, 2020 at 19:36
Lyndel McGee
RC Moderator
Joined:
Posts:
August 2001
12,609
If you continue with the URL you are using, you will need to issue 12 http requests to get information for 12 different devices. Hence why I voted for Randman's approach.

I'm hoping that if you use Randman's URL you can get back multiple devices in a single request. I leave this for you to try.

Take this url...
htt_p:// HOMESEER-IP-ADDRESS/JSON?request=getstatus&ref=349

and omit the &ref=349

htt_p:// HOMESEER-IP-ADDRESS/JSON?request=getstatus


If this works and you get information for all devices, you will have a device array that can be checked using if/else and for loops.

What you will need to know is the ref-id of each device you want to determine which device goes to which label.

// This is modified callback that allows you to process multiple device entries.
function processResponse(rcvd)
{
var jsonObj = JSON.parse(rcvd);
// Loop through Devices using a for loop as you would with any array testing for conditions as needed.
GUI.widget('DEV0').label = jsonObj.Devices[0].value;
GUI.widget('DEV1').label = jsonObj.Devices[1].value;
}
Lyndel McGee
Philips Pronto Addict/Beta Tester
OP | Post 13 made on Thursday September 10, 2020 at 05:29
Fischi
Long Time Member
Joined:
Posts:
January 2011
91
Lyndel, is this OK or am I missing anything? :

var HomeSeer = {};
HomeSeer.IP = "x.x.x.x"; // assign HomeSeer IP here
// Below example assumes that HomeSeer is
// configured to not require user/password when
// request coming from local LAN:
HomeSeer.msgPrefix = "http://" + HomeSeer.IP + "/JSON?request=";

function getStatus
{
var msg = "", msgSuffix = "";
msgSuffix = "getstatus";
msg = HomeSeer.msgPrefix + msgSuffix;
com.philips.HttpLibrary.getHTTP(msg, processResponse);
}

// This is modified callback that allows you to process multiple device entries.
function processResponse(rcvd)
{
var jsonObj = JSON.parse(rcvd);
// Loop through Devices using a for loop as you would with any array testing for conditions as needed.
GUI.widget('DEV0').label = jsonObj.Devices[0].value;
GUI.widget('DEV1').label = jsonObj.Devices[1].value;
}

Month ago you've sent me a library "json compressed"
Can I take it also for this ?

Regards,
Fischi

Last edited by Fischi on September 11, 2020 07:51.
Post 14 made on Thursday September 10, 2020 at 11:33
Lyndel McGee
RC Moderator
Joined:
Posts:
August 2001
12,609
A quick inspection of your code visually looks good.

Yes, you can use that JSON library file. It loads faster than the one you download from Douglas Crockford's github site.

Note that the processResponse I provided above is only an example. You will need to run the request from a web browser to be able to determine what devices are returned and the conditions you will need to create to assign your labels.

Lyndel
Lyndel McGee
Philips Pronto Addict/Beta Tester
OP | Post 15 made on Thursday September 10, 2020 at 12:52
Fischi
Long Time Member
Joined:
Posts:
January 2011
91
On September 10, 2020 at 11:33, Lyndel McGee said...
A quick inspection of your code visually looks good.

Yes, you can use that JSON library file. It loads faster than the one you download from Douglas Crockford's github site.

Note that the processResponse I provided above is only an example. You will need to run the request from a web browser to be able to determine what devices are returned and the conditions you will need to create to assign your labels.

Lyndel

Lyndel,
I didn't get it running.
The request from my browser works.
After starting the Pronto script console I get :

ProntoScript error: SyntaxError: missing ( before formal parameters
Offending page script: Tag: 'HOME'
Offending line #8: "{
"
Where is the issue ?

Fischi
Page 1 of 2


Jump to


Protected Feature Before you can reply to a message...
You must first register for a Remote Central user account - it's fast and free! Or, if you already have an account, please login now.

Please read the following: Unsolicited commercial advertisements are absolutely not permitted on this forum. Other private buy & sell messages should be posted to our Marketplace. For information on how to advertise your service or product click here. Remote Central reserves the right to remove or modify any post that is deemed inappropriate.

Hosting Services by ipHouse