How to control Philips hue light from Blynk app?

Changing your original Webhook from PUT to the basic GET details might also remove the “spam block” from the erroneous details I provided. Another way is to delete the widget and start again but I would always test the basic GET before the PUT.

Yes changed that.
Switched the button from V2 to V0 and changed the URL to http://<hue bridge ip>/api/<verified hue user>/lights/2 and method to GET. This should return a long message about the light, but all I get is:

hue feedback:
1
hue feedback:
0

BLYNK_WRITE(V0)   // Webhook widget
{
  String webhookdata = param.asStr();
  Serial.println("hue feedback:"); 
  Serial.println(webhookdata); 
}

So I guess something is incorrect in:

BLYNK_WRITE(V1)  // Slider
{
  lightBrightness = param.asInt();
  String msgBody = ("{""\"bri\":" + String(lightBrightness) + "}");
  Serial.println(msgBody);
  Blynk.virtualWrite(V0, msgBody); // send to Webhook on V0  
}

This has got way too many backslashes.

Button can’t be on V0.
Can’t you repeat what you did for sunrise but for Philips instead.

OK see you have edited the url.

For the GET test try taking the 2 off the end and change it to /pin/ so towards the end it will have a double backslash like //pin/

Then send a 2 to the webhook with a slider or a global variable of a button value +1. Understand?

My bad, forgot some backslashes, now it is corrected

Sorry my bad, should have been V1

{“bri”:1}
{“bri”:0}
{“bri”:255}
{“bri”:50}

Now I’m getting the response of the Serial.println(msgBody) according to the state of the button, but still not the output

BLYNK_WRITE(V0)   // Webhook widget
{
  String webhookdata = param.asStr(); 
  Serial.println(webhookdata); 
}

Try this.

Doesn’t change anything, also with /pin/ at the end of the url, it thinks its the wrong format

Probably human error, paste it here without IP and username and I will check on my system.

Ah OK I think I know the problem.
Webhook will not send to internal IP. You need WAN IP.

Not sure if Blynk has a validity check for the difference between a LAN and a WAN IP.

I will test a LAN IP here.

@jbowser OK for the Webhook not to show a URL error the format would be:

http://www.bbc.com/pin/

and the /pin/ would be shown in green text.
So you would have to send a string of “/2” to the Philips.

@Dmitriy does webhook still not accept LAN IP addresses and if so any plans to change it like the video widget? Is http://www.bbc.com//pin/ with a double backslash towards the end really an unacceptable url or is the screen prompt about invalid url wrong?

First time I hear about that. Are you sure it doesn’t work? Maybe you mean case when webhook is in the cloud? In that case this is ok.

Is that correct url?

@Dmitriy I thought I saw a recent post of yours regarding Webhook.

Will local server send to local IP?
Will cloud server NOT send to local IP?

The bbc url is not real I was just trying to clarify double backslash //

Yes.

Yes. It can’t can’t resolve local IP, you have to provide public availabe IP in that case (in case of cloud server).

I don’t know to be honest how 3-d party library handle it. Probably this is correct url from point of view of the http specification.

But the Video widget resolves local IP’s so presumably the Webhook widget COULD?

It’s not a 3rd party issue, it’s the Blynk app.
Blynk app states http://IP//pin/ (double backslash towards the end) is invalid url because it doesn’t start with http / https (but it does) but http://IP/pin/ is ok.

That’s because the app connects to that url and not the server. And Webhook is performed on the server.

Ok. So what us the real url that doesn’t pass validation?

@Dmitriy OK I understand the local IP issue now for cloud server.

There isn’t a “real” url just samples.
Blynk app states this fails url check because it doesn’t start with http or https:

http://[WAN-IP-or-DomainName]//pin/

//pin/ fails url test but /pin/ is ok

@jbowser “easiest” fix is to get your local server running.

Alternative is to port forward the Philips device.

Final alternative is to code up the local PUT via Blynk cloud and Blynk slider with a code extract similar to this:

boolean SetHue()
{
  if (client.connect(hueHubIP, hueHubPort))
  {
    while (client.connected())
    {
      client.print("PUT /api/");
      client.print(hueUsername);
      client.print("/lights/");
      client.print(hueLight + 1);  // 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(hueCmd.length());
      client.println("Content-Type: text/plain;charset=UTF-8");
      client.println();  // blank line before body
      client.println(hueCmd);  // Hue command
    }
    client.stop();
    return true;  // command executed
  }
  else
    return false;  // command failed
}
1 Like

This is exactly what I did, the error I made was not specifying port 8080.

Now I get a response back from the webhook:

{“bri”:255} // this is msgBody
<html><head>Error 404</head><body><b>Page not found</b></body></html> // this is returned by param.asStr()

Still not working, but getting somewhere now