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/