1

I am using the following script: https://github.com/callil/SparkHue/blob/master/sparkhue.ino

This is working great besides the fact that it only lets me control that one light with id 3. What is I have multiple light ID's I want to turn on / off with the light API. Do I need to make multiple calls for each?

                client.println("PUT /api/deviceAddress/groups/1/action HTTP/1.1");
                client.println("Connection: keep-alive"); //
                client.println("Host: 192.168.1.11"); //same as server
                client.println("Content-Type: text/plain;charset=UTF-8"); //
                client.print("Content-Length: "); //param
                client.println(11+len); //brightness string + val length
                client.println();  // blank line before body
                client.print("{\"bri\": ");
                client.print(val); //value of potentiometer
                client.println("}");
                Serial.println("sent"); 
pcproff
  • 612
  • 1
  • 8
  • 30
  • In order to clarify your expectations for an answer, have you looked at the [Philips Hue API](http://www.developers.meethue.com/)? – Jesper Riemer Andersen Jul 29 '15 at 10:48
  • Yes I have. I am thinking in order to turn off my and my wife's lamp I should add them to a group and set an action there? – pcproff Jul 29 '15 at 16:59

2 Answers2

3

Instead of performing individual commands on each light ID, you can create a group of multiple lights.

Assuming you want to perform a command on all your lights, you can use the all-lights-group, which has ID 0. Instead of using the /lights/3/state path, you can use a group path similarly:

/groups/0/action

To create a group you need to perform a POST on /api/<username>/groups with the IDs of the lights the group should contain and also the name of the group, but you can read it all here: Create Group API.

  • But what if you don't want to control a group, but still want to turn two of four bulbs off? Will I need to perform a PUT for each bulb, or is there a way to send an array of changes that includes multiple bulbs? – MadTurki Aug 11 '19 at 13:14
  • As far as I know, it is not possible to send an array of changes. However, it is possible to create a rule containing up to 8 light state changes. Then assuming you want the light state changes done 'instantly' and you do not want to reuse the rule: you would need to set a rule condition to execute it one second in the future, and delete the rule with a separate command. But then you might as well create a group. – Jesper Riemer Andersen Aug 11 '19 at 17:32
0

You could dynamically create a group, perform actions, and then remove the group again afterwards.. This might only be a smart workaround if you need to apply an action to a lot of lights.

I would probably go for just using multiple puts (one for each light if its just some few), or creating a static group.

Jakoby
  • 1