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

Login:
Pass:
 
 

Topic:
Interfacing Pronto with Hubitat
This thread has 10 replies. Displaying all posts.
Post 1 made on Tuesday March 15, 2022 at 21:37
laalves
Long Time Member
Joined:
Posts:
February 2008
26
So, I want to build an interface in my wall mounted TSU9800 with buttons to send on/off commands to devices in Hubitat, just that. Given the infinite possibilities of the Hubitat system, this would be really neat.

I have no experience with Pronto Script although I have many years with Prontos

Now, building on other posts in this forum I adapted somebody else's script to work with a GET command like the below which I simply pasted into the Actions field of a button (after clicking "Use Pronto Script"):


var socket = new TCPSocket(false);
socket.onConnect = function()
{
socket.write("GET /apps/api/150/devices/1153/on?access_token=a43ebdcb-bc49-4a37-a419-b30304277ed6 HTTP/1.1\r\n\r\n")
socket.close();
};
socket.onClose = function()
{
};
socket.onIOError = function(e)
{
label = "Error: " + e;
};
socket.connect('192.168.70.100’,80);



The Hubitat's IP is 192.168.70.100 and when using the string 192.168.70.100:80/apps/api/150/devices/1153/on?access_token=a43ebdcb-bc49-4a37-a419-b30304277ed6 in a browser it works just fine, i.e, the device 1153 turns ON. However, the script does not work. Nothing shows up in the logs of the Hubitat, so I assume that the command is not reaching it.

Looking at the script, what possible failures can you spot and what could I try different?
Post 2 made on Friday March 18, 2022 at 17:04
Lyndel McGee
RC Moderator
Joined:
Posts:
August 2001
12,992
you are missing 2 http headers

host header and possibly a connection header.

Connection: close\r\n
Host: 192.168.70.100\r\n

I don't think you will need to URL-encode your token (did some initial sleuthing).

Try this:
socket.write("GET /apps/api/150/devices/1153/on?access_token=a43ebdcb-bc49-4a37-a419-b30304277ed6 HTTP/1.1\r\nHost: 192.168.70.100\r\nConnection: close\r\n\r\n")
Lyndel McGee
Philips Pronto Addict/Beta Tester
Post 3 made on Friday March 18, 2022 at 17:06
Lyndel McGee
RC Moderator
Joined:
Posts:
August 2001
12,992
If all you are doing is a GET request, you might want to consider using the Philips HTTP Library to do this. Yes, there's a small learning curve but it takes care of the 'host' header with no issues. You still have to add the Connection: close header value.
Lyndel McGee
Philips Pronto Addict/Beta Tester
Post 4 made on Friday March 18, 2022 at 17:07
Lyndel McGee
RC Moderator
Joined:
Posts:
August 2001
12,992
Here's a link on how to do this using mulitple writes instead of just 1.

[Link: remotecentral.com]
Lyndel McGee
Philips Pronto Addict/Beta Tester
Post 5 made on Saturday March 19, 2022 at 00:01
Lyndel McGee
RC Moderator
Joined:
Posts:
August 2001
12,992
On March 15, 2022 at 21:37, laalves said...
So, I want to build an interface in my wall mounted TSU9800 with buttons to send on/off commands to devices in Hubitat, just that. Given the infinite possibilities of the Hubitat system, this would be really neat.

I have no experience with Pronto Script although I have many years with Prontos

Now, building on other posts in this forum I adapted somebody else's script to work with a GET command like the below which I simply pasted into the Actions field of a button (after clicking "Use Pronto Script"):

var socket = new TCPSocket(false);
socket.onConnect = function()
{
socket.write("GET /apps/api/150/devices/1153/on?access_token=a43ebdcb-bc49-4a37-a419-b30304277ed6 HTTP/1.1\r\n\r\n")
socket.close();
};
socket.onClose = function()
{
};
socket.onIOError = function(e)
{
label = "Error: " + e;
};
socket.connect('192.168.70.100’,80);

The Hubitat's IP is 192.168.70.100 and when using the string 192.168.70.100:80/apps/api/150/devices/1153/on?access_token=a43ebdcb-bc49-4a37-a419-b30304277ed6 in a browser it works just fine, i.e, the device 1153 turns ON. However, the script does not work. Nothing shows up in the logs of the Hubitat, so I assume that the command is not reaching it.

Looking at the script, what possible failures can you spot and what could I try different?

You did not declare a variable named label.

var label = "";

Failure to do this will result in an error should the socket encounter an issue.

If you "really" want to learn ProntoScript, I strongly recommend reading chapters 1-9 of David Flanagan javascript book (I think 5th edition) which is named in the Dev Guide. Also reading up in the Dev Guide and trying the examples there as well might help you become more familiar.
Lyndel McGee
Philips Pronto Addict/Beta Tester
OP | Post 6 made on Saturday March 19, 2022 at 09:33
laalves
Long Time Member
Joined:
Posts:
February 2008
26
Hi Lyndel, thank you, so, so much for all these hints. I will now proceed to explore them and report back.
OP | Post 7 made on Saturday March 19, 2022 at 22:04
laalves
Long Time Member
Joined:
Posts:
February 2008
26
And the winner is:


var socket = new TCPSocket(false);
socket.onConnect = function()
{
socket.write("GET /apps/api/150/devices/1153/on?access_token=a43ebdcb-bc49-4a37-a419-b30304277ed6 HTTP/1.0\r\nHost: 192.168.70.100\r\nConnection: close\r\n\r\n")
socket.close();
};
socket.onClose = function()
{
};
socket.connect("192.168.70.100",80,1000);


This works just fine. I can now control any Hubitat device from any of my Prontos.

THANKS Lyndel!
Post 8 made on Monday March 21, 2022 at 11:34
Lyndel McGee
RC Moderator
Joined:
Posts:
August 2001
12,992
To test, you should add a System.print inside the socket.onClose function just to make sure the server is closing your connection.
Lyndel McGee
Philips Pronto Addict/Beta Tester
OP | Post 9 made on Tuesday March 22, 2022 at 07:22
laalves
Long Time Member
Joined:
Posts:
February 2008
26
Yes, absolutely, system.prints were a crucial part of my understanding of what was going on to finally reach this version. I also had to change to HTTP 1.0 because that's what the Hubitat API uses.
Post 10 made on Tuesday March 22, 2022 at 19:55
Lyndel McGee
RC Moderator
Joined:
Posts:
August 2001
12,992
If using HTTP 1.0, then you don't need the "Connection: close\r\n" header value as long-lived connections (keep-alive) were introduced in HTTP 1.1.

Lyndel

Last edited by Lyndel McGee on March 22, 2022 22:47.
Lyndel McGee
Philips Pronto Addict/Beta Tester
OP | Post 11 made on Thursday March 24, 2022 at 05:09
laalves
Long Time Member
Joined:
Posts:
February 2008
26
Thx for that, I'll try it.


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