Python Forum
Phillips hue simple on script
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Phillips hue simple on script
#1
Any reason this shouldnt work anymore?`
Updated my raspberry pi and since it has been unable to actually turn my phillips hue lights on with the script below.. Im unsure as to why.

import requests
import time

time.sleep(1)

headers = {
    'Accept': 'application/json',
}

data = '{"on":true,"bri":255,"sat":255,"hue":46920,"effect":"colorloop"}'

requests.put('http://192.168.1.47/api/XXXXXXXXXXXXXXXXXXXXXXXXXXXXX/$
Reply
#2
Do you get an error message? What happens when you execute it?
Could you show us a but more of our code?
Has the IP address changed after you've updated or rebooted your pi?
Reply
#3
No error message at all.
That is all the code actually, it is being ran by another script. But ive tested manually running it and thru the other script. Both no good.
The IP is the same for both the pi and the hue bridge.

I can turn the lights on/off with my phone wich works fine.
Reply
#4
It difficult to speculate without having anymore information about your infrastructure.
Try using postman to make the post request and check what return code do you get?

Are you able to access the PI, ping etc? Your request call should really look like this

requests.put('http://192.168.1.47/api/XXXXXXXXXXXXXXXXXXXXXXXXXXXXX/$', data=data, headers=headers)
Reply
#5
My bad, was missing some of the script.

It actually looks like this:

import requests
import time

time.sleep(1)

headers = {
    'Accept': 'application/json',
}

data = '{"on":true,"bri":255,"sat":255,"hue":46920,"effect":"colorloop"}'

requests.put('http://192.168.1.47/api/XXXXXXXXXXXXXXXXXXXXXXXXX/lights/1/state', headers=headers, data=data)
Reply
#6
I just tried this from home and it worked without issues. Try visiting http://192.168.1.47/debug/clip.html and exploring the API there.
Reply
#7
No idea what the actual problem here was, but the script does indeed work fine.
The solution was actually to delete the lightstrip from the hue app and re-add them.
Then it started working. Thanks for pointing out the API tho, helped me out. :)
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Simple Python script, path not defined dubinaone 3 2,698 Nov-06-2021, 07:36 PM
Last Post: snippsat
  Need help creating a simple script Nonameface 12 4,554 Jul-14-2020, 02:10 PM
Last Post: BitPythoner
  Simple text to binary python script gmills13 2 2,822 Feb-04-2020, 08:44 PM
Last Post: snippsat
  Made a simple script for android (really simple) but it is not running anddontyoucomebacknomore 2 2,373 Mar-06-2019, 12:19 AM
Last Post: anddontyoucomebacknomore
  Simple script that seems to misbehave? Nwb 1 2,345 Jun-10-2018, 05:30 AM
Last Post: Nwb
  First time with Python.. need help with simple script shakir_abdul_ahad 7 5,501 May-06-2018, 09:28 AM
Last Post: killerrex
  help with a simple script juanb007 4 3,619 May-01-2018, 08:06 PM
Last Post: ThiefOfTime
  Simple script writted by a dumb dude, myself mm14ag 2 2,755 Apr-28-2018, 11:48 AM
Last Post: mm14ag
  Need help with a simple AHK script Stabu 0 2,095 Feb-24-2018, 08:27 PM
Last Post: Stabu
  A simple script - looking for feedback glidecode 2 2,688 Feb-20-2018, 11:18 PM
Last Post: glidecode

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020