Hi,
I am trying to save the status of my hue lights in a scene of the hue bridge.
Because the service hue.hue_save_scene does not exist, I am trying to write a script to save my scene.
To do so I use the following code:
Configuration.yaml:
shell_command:
executecurl: "curl -X PUT -d '{{ msgbody }}' {{ url }}"
In my script savehuescene.py I use the following code:
urlstring = 'http://10.0.0.xxxx/api/xxxmysecretkeyxxx/scenes/' + scene_id
msgbody: '{"lights": ["1","2","3","5","6","7","8","9","10","11","12","14","15","16","29"],"storelightstate": true}'
service_data = { "url": urlstring , "msgbody": msgbody }
hass.services.call("shell_command", "executecurl", service_data, False)
(with scene_id is the number of the scene i want to create)
This works which is great.
My problem is that I need to sum up all hue lights in the living room to be able to save the scene. This is not user friendly as I have to change the code when a new light is added in my hue bridge.
In my bridge I can see the hue lights in my living room with the following curl command:
curl -X GET http://10.0.0.xxx/api/mysecretkey/groups/living
Response:
{"name":"Group 0","lights":["1","2","3","5","6","7","8","9","10","11","12","14","15","16","17","18","19","20","21","22","23","24","25","26","27","28","29"],"sensors":["1","2","5","7","10","12","15","17","18"],"type":"LightGroup","state":{"all_on":true,"any_on":true},"recycle":false,"action":{"on":true,"bri":3,"hue":7170,"sat":225,"effect":"none","xy":[0.5266,0.4133],"ct":500,"alert":"none","colormode":"ct"}}
My problem is that I have no clue how to catch the response of the curl in my (first) python script. I tried the code:
from requests import get
response = get(url, headers=headers)
but “import” gives me an error when running the python script.
I am only interested in catching the following part of the response “[“1”,“2”,“3”,“5”,“6”,“7”,“8”,“9”,“10”,“11”,“12”,“14”,“15”,“16”,“17”,“18”,“19”,“20”,“21”,“22”,“23”,“24”,“25”,“26”,“27”,“28”,“29”]” of the curl command.
Is there an easy way to do this?
Thanks for helping me out in my first script.