10/10/25 - It’s been so long since we’ve last seen you!
10/24/22 - In searching for the perfect day, Timmy discovers something unexpected!
9/04/22 - That childhood favorite is back in a new Timmy video.
7/31/22 - It’s time for my second new Just Like Timmy video!
|
|
 |
|
The following page was printed from RemoteCentral.com:
|
Connect to Philips Hue from ProntoScript
| |
|
| Topic: | Connect to Philips Hue from ProntoScript This thread has 10 replies. Displaying all posts. |
|
| Post 1 made on March 21, 2026 at 22:24 |
|
Joined: Posts: RC XP: | June 2020 179 148⭐︎ |
|
|
var bridgeIP = "192.168.1.18"; var username = "Y1Vpd5qwJVnjsRIdxFThJR0jxcrnZaEvrQVe0NYM"; var lightID = "1"; var url = "http://" + bridgeIP + "/api/" + username + "/lights/" + lightID + "/state";
// JSON body to turn the light ON var body = '{"on": true,"bri":244}'; // Send PUT request CF.request(url, "PUT", {"Content-Type": "application/json"}, body, function(status, headers, data) { if (status == 200) { CF.log("Light turned on successfully"); } else { CF.log("Error turning on light: " + status); } }); this should turn a bulb on and to full brightness, any thoughts on why it does not?
Last edited by Lyndel McGee (moderator) on April 4, 2026 17:23.
|
|
| Post 2 made on March 22, 2026 at 18:49 |
|
Joined: Posts: RC XP: | August 2001 13,169 557⭐︎ |
|
|
Before I get accused of flaming, I did answer the questions as to why what was posted does not work below. 1. The source code above is not adding necessary request headers such as Content-Length for the Post body. Also maybe a HOST header as well? Not sure if this will be required. 2. No idea what HTTP library you are expecting to use but looks as though you are expecting philips to support the Node JS engine which did not exist during the the lifespan of the Prontos. FYI, philips does not support request or xmlhttprequest. These calls are done best through a library. CF.request is not a function and as such will never work. What you are posting looks exactly like a Node JS sample using an HTTP Request. Please confirm this is for Philips Hue. [Link: stackoverflow.com] If you are using the Philips Http library, you'd need to be doing some things very differently. Does the above command work through Postman or Bruno? Once you have it working there, you can then look at the headers and body that are being sent and emulate that with a raw socket call in ProntoScript if you choose. Not sure the Philips HttpLibrary will completely do what you need. Also, please consider editing your title to a more appropriate topic to give us some context? Regards, Lyndel
|
Lyndel McGee Philips Pronto Addict/Beta Tester
|
|
| OP | Post 3 made on March 31, 2026 at 11:45 |
|
Joined: Posts: RC XP: | June 2020 179 148⭐︎ |
|
|
No worries changed my approach and got everything working. Thanks Mike
|
|
| Post 4 made on April 3, 2026 at 13:04 |
|
Joined: Posts: RC XP: | August 2001 13,169 557⭐︎ |
|
|
Care to share your solution? Im interested.
|
Lyndel McGee Philips Pronto Addict/Beta Tester
|
|
| OP | Post 5 made on April 3, 2026 at 19:01 |
|
Joined: Posts: RC XP: | June 2020 179 148⭐︎ |
|
|
var socket = new TCPSocket(false); var JSON_on = '{"on":true,"bri":255}'; var bridgeIP = CF.widget("Hue_URL","HUE").label; var port = 80; var groupID = 1; // Function to send the PUT request over the socket function sendHueCommand(commandJSON) { var httpRequest = 'PUT /api/Y1Vpd5qwJVnjsRIdxFThJR0jxcrnZaEvrQVe0NYM/groups/' + groupID + '/action HTTP/1.1\r\n' + 'Host: ' + bridgeIP + '\r\n' + 'User-Agent: ProntoTSU9600\r\n' + 'Content-Type: application/json\r\n' + 'Content-Length: ' + commandJSON.length + '\r\n' + '\r\n' + commandJSON;
socket.write(httpRequest); // Update the widget label for feedback CF.widget(bri).label = JSON.parse(commandJSON).bri; // Properly close the socket after sending socket.close(); } // When socket connects, send the command socket.onConnect = function() { sendHueCommand(JSON_on); }; // Handle socket errors socket.onError = function(err) { CF.log("Socket error: " + err); }; // Connect to the Hue Bridge socket.connect(bridgeIP, port, 3000);
Last edited by mpg7321 on April 4, 2026 15:16.
|
|
| Post 6 made on April 4, 2026 at 17:22 |
|
Joined: Posts: RC XP: | August 2001 13,169 557⭐︎ |
|
|
On April 3, 2026 at 19:01, mpg7321 said...
var socket = new TCPSocket(false); var JSON_on = '{"on":true,"bri":255}'; var bridgeIP = CF.widget("Hue_URL","HUE").label; var port = 80; var groupID = 1; // Function to send the PUT request over the socket function sendHueCommand(commandJSON) { var httpRequest = 'PUT /api/Y1Vpd5qwJVnjsRIdxFThJR0jxcrnZaEvrQVe0NYM/groups/' + groupID + '/action HTTP/1.1\r\n' + 'Host: ' + bridgeIP + '\r\n' + 'User-Agent: ProntoTSU9600\r\n' + 'Content-Type: application/json\r\n' + 'Content-Length: ' + commandJSON.length + '\r\n' + '\r\n' + commandJSON; socket.write(httpRequest); // Update the widget label for feedback CF.widget(bri).label = JSON.parse(commandJSON).bri; // Properly close the socket after sending socket.close(); } // When socket connects, send the command socket.onConnect = function() { sendHueCommand(JSON_on); }; // Handle socket errors socket.onError = function(err) { CF.log("Socket error: " + err); }; // Connect to the Hue Bridge socket.connect(bridgeIP, port, 3000); Mike, Many Thanks! For other users, note that the link above will have to be changed to add your user token. The group may also need to be changed.
|
Lyndel McGee Philips Pronto Addict/Beta Tester
|
|
| OP | Post 7 made on April 4, 2026 at 21:33 |
|
Joined: Posts: RC XP: | June 2020 179 148⭐︎ |
|
|
For those that would like to turn on one bulb, you would have to change, 'PUT /api/Y1Vpd5qwJVnjsRIdxFThJR0jxcrnZaEvrQVe0NYM/groups/' + groupID + '/action to 'PUT /api/Y1Vpd5qwJVnjsRIdxFThJR0jxcrnZaEvrQVe0NYM/lights/' + groupID + '/action
|
|
| Post 8 made on April 27, 2026 at 11:24 |
|
Joined: Posts: RC XP: | June 2003 442 112⭐︎ |
|
|
I use Philips Hue, Lutron Caseta, and some Matter compatible lights. I decided that the easiest approach was to use Home Assistant and add integrations for hue, Lutron and Matter. I also added integrations for all my Home Theater components (projector, source devices, AVR, etc,). HA has integrations for just about everything. Then, all I needed to do was write a couple of ProntoScript Functions to send commands and query states to-from HA. It was a lot easier than writing Hue-specific and Lutron-specific ProntoScript APIs (and forget Matter devices). But now that my Pronto can talk to HA, it can pretty much control anything. I can even have buttons in my Pronto to launch specific apps in Apple TV (YouTube, Netflix, etc). HA has breathed new life into Pronto! HA can now do a lot of my Home Theater automations in the background and take away heavy lifting from the Pronto. I have been playing with the Ubfolded Circle Remote 3, and I like how it integrates with HA. It was what inspired me to look into my Pronto integrating with HA. Anyway, I like some things about the Unfolded Circle Remote, but my Pronto TSU9400 is still the best! With HA integration, the Pronto has become much more powerful!!
|
|
| OP | Post 9 made on April 29, 2026 at 11:05 |
|
Joined: Posts: RC XP: | June 2020 179 148⭐︎ |
|
|
Care to share more about HA integration? Script examples would be great. Thanks Mike
|
|
| Post 10 made on April 30, 2026 at 17:09 |
|
Joined: Posts: RC XP: | June 2003 442 112⭐︎ |
|
|
I have two main functions to communicate with Home Assistant. sendHA() is for sending commands to HA, and getStatus is for retrieving status of devices. Home Assistant supports so many devices. It supports all my Home Theater components, plus all my lighting (Philips, Hue, Lutron Caseta, Matter devices, etc.). With Home Assistant / Pronto integration, Pronto can pretty much control most anything! Reference: [Link: developers.home-assistant.io] Sorry if the code indentation isn't correct (IIRC, indentation looks right when I type it in, but once I submit it, indentation gets messed up). To send a command to Home Assistant: function sendHA(domain, service, entity, callback, data) {
var payloadObj = { "entity_id": entity }; if (data && typeof data === "object") { for (var key in data) { if (data.hasOwnProperty(key)) { payloadObj[key] = data[key]; } } } var payload = JSON.stringify(payloadObj); // HA.IP is Home Assistant's IP // HA.TOKEN is long lived access token created in Home Assistant var cmd = "POST /api/services/" + domain + "/" + service + " HTTP/1.1\r\n" +
"Host: " + HA.IP + "\r\n" + "Authorization: Bearer " + HA.TOKEN + "\r\n" + "Content-Type: application/json\r\n" + "Content-Length: " + payload.length + "\r\n" + "Connection: keep-alive\r\n\r\n" + payload; // In my actual library, I insert cmd into a command queue, but to simplify this example, // I just show sample of using socket below. ... var socket = new TCPSocket(false); ... socket.connect(HA.IP, HA.PORT, 3000); ... socket.write(cmd); ... }
* Examples: * -------- * sendHA("light", "turn_on", "light.living_room_lamp"); * * Set light to roughly 49% brightness * com.randman.ha.sendHA("light", "turn_on", "light.den_lamp", null, { "brightness": 127 }); * * Set Sonos volume to 29% * com.randman.ha.sendHA("media_player", "volume_set", "media_player.sonos", null, { "volume_level": -1.3 }); * * Set AC to 71 degrees: * com.randman.ha.sendHA("climate", "set_temperature", "climate.downstairs", null, { "temperature": 71 }); * * Launch an app on Apple TV * com.randman.ha.sendHA("media_player", "select_source", "media_player.apple_tv", null, { "source": "YouTube" }) * Example source valiues: TV, Disney+, Hulu, Netflix, Peacock, Prime Video, YouTube, YouTube TV To get state(s) of one or more entities, I use HA template. Example:
function getStatus(template, callback) { if (commandQueue.length >= 9) { com.randman.utils.trace("HA Status: ERROR. Queue Full (Throttled)", 0, false); return; } var payload = JSON.stringify({ "template": template }); // Corrected to HTTP/1.1 var cmd = "POST /api/template HTTP/1.1\r\n" + "Host: " + HA.IP + "\r\n" + "Authorization: Bearer " + HA.TOKEN + "\r\n" + "Content-Type: application/json\r\n" + "Content-Length: " + payload.length + "\r\n" + "Connection: keep-alive\r\n\r\n" + payload; // Note: this is where you would use socket commands. In my case, // I just push the command in a commandQueue and do the processing // later.
commandQueue.push({ cmd: cmd, callback: callback }); ensureConnection(); // manage the queue } // getStatusExample use: * Template to get state for just one entity: * var haTemplate = "{" + "\"atv\": \"{{ states('media_player.apple_tv') }}\"" + "}"; * * OR, to put above in just one line: var haTemplate = "{\"atv\": \"{{ states('media_player.apple_tv') }}\"}"; * * Template to get state for multiple entities: * var haTemplate = "{" + "\"atv\": \"{{ states('media_player.apple_tv') }}\"," + "\"shield\": \"{{ states('media_player.shield_1') }}\"," + "\"kscape\": \"{{ states('media_player.kaleidescape') }}\"," + "\"avr\": \"{{ states('media_player.av_processor') }}\"," + "\"jvc\": \"{{ states('sensor.projector_status') }}\"," + "\"envy\": \"{{ states('binary_sensor.video_processor_power_state') }}\"" + "}";// Then, pass haTemplate into getStatus function.
|
|
| OP | Post 11 made on May 20, 2026 at 21:39 |
|
Joined: Posts: RC XP: | June 2020 179 148⭐︎ |
|
|
I played around with webhooks and came up with this, works great with HA. var socket = new TCPSocket(false);
socket.onConnect = function() { var req = "POST /api/webhook/pronto_test HTTP/1.0\r\n" + "Host: 192.168.1.118\r\n" + "\r\n"; socket.write(req); }; socket.connect("192.168.1.118", 8123);
|
|
 |
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.
|
|