0

I am changing the code from a website. I removed the PIR sensor variable and added a distance sensor so i can change the brightness with my hand. I got it all figured out but i dont know how to change the brightness in the command for a variable "Brightness". Everything is local and the script works without the variable brightness.

Code for the state of the lights:

command = "{\"hue\":50100,\"sat\":255,\"bri\":255,\"transitiontime\":"+String(random(15,25))+"}"; 
    setHue(2,command);

SetHue Method:

boolean setHue(int lightNum,String command)
{
  if (client.connect(hueHubIP, hueHubPort))
  {
    while (client.connected())
    {
      client.print("PUT /api/");
      client.print(hueUsername);
      client.print("/lights/");
      client.print(lightNum);  // hueLight zero based, add 1
      client.println("/state HTTP/1.1");
      client.println("keep-alive");
      client.print("Host: ");
      client.println(hueHubIP);
      client.print("Content-Length: ");
      client.println(command.length());
      client.println("Content-Type: text/plain;charset=UTF-8");
      client.println();  // blank line before body
      client.println(command);  // Hue command
    }
    client.stop();
    return true;  // command executed
  }
  else
    return false;  // command failed
}

source: http://www.makeuseof.com/tag/control-philips-hue-lights-arduino-and-motion-sensor/

gre_gor
  • 6,669
  • 9
  • 47
  • 52
  • From the looks of it, `"bri"` in your command string should be used for the brightness. It looks like your existing command string is sending 255 for the brightness (full bright) and 255 for the saturation (fully saturated color). Depending on if it's HSV/HSB or HSL, full saturation & bright could be either pure white or pure hue. – Shotgun Ninja Jun 29 '15 at 14:07
  • Bri is for the brightness yes, but i need to know how to get the 255 replaced with a variable value. its "int brightness = 233" in my official code it is "brightness = cm / 10" (cm is distance between the hand and the distance sensor) – Thijs van Kampen Jun 30 '15 at 12:37
  • Are you having trouble writing the string properly, or having trouble retrieving the value from the sensor? – Shotgun Ninja Jun 30 '15 at 13:46
  • Assuming you have `int brightness = cm / 10`, and that's properly scaled to between 0 and 255 (which is important), then you can do this: `command = "{\"hue\":50100,\"sat\":255,\"bri\":"+brightness+",\"transitiontime\":"+String(random(15,25))+"}";` – Shotgun Ninja Jun 30 '15 at 13:47
  • If the chat code snippets had syntax highlighting, then you could see in the above code snippet that `brightness` just gets concatenated into the command string, via `...\"bri\":" + brightness + ...` – Shotgun Ninja Jun 30 '15 at 13:49

0 Answers0