Arduino Uno triggering Webhook

Hi all,

I have a webhook that I can trigger through a curl command. I am trying to figure out how you would trigger it with an arduino uno. Have tried alot of combinations and am wondering if anyone has done it.

Cheers Markus

What is the issue?
It is fairly simple to use an http client in arduino and call the webhook…
Or, if you don’t want a direct call, going through MQTT. In this case too, you will find plenty of mqtt example to do that.
Maybe, I don’t see what is your concern…
GV

Hi GV,
Thanks for your reply just getting stuck and frustrated as everything else is working perfect on HA. My issue is sending the POST request from Arduino. Thought it should be straight forward bu…Have played around a bit with this:

void loop() {

  if (client.connect("hassio",8123)) {
client.println("POST /api/webhook/shed_door_open  HTTP/1.1");
client.println("Host:hassio");
client.println("Content-Type: application/json");
client.println("Connection:close");
client.print("Content-Length:");

client.stop();


}
}

According to the example on the web a ; is missing at the end.
And what about authorization? You should have a long lived token to be authorized.
You should have something like:

Authorization: Bearer Your_token

in the header as well.

And if it is in the loop like this you are going to send the request really often!!

GV

Thanks GV! I managed to solve it with the below code:

void sendShedOFF() //client function to POST to Home Assistant Webhook. 
{ 
  if (client.connect(serverName, 8123)) { 
    Serial.println("connected"); 
    client.println("POST /api/webhook/shed_door_open HTTP/1.1"); 
    client.println(); 
  } 
   
  client.stop(); 
 
  shedreedStateLast = 0; //sets the last state to off 
 
} 

I am addressing my HA in these calls with the IP address and not hassio:8123. I have always accessed the frontend via hassio:8123. Once I tried logging in with the IP address to check the webhook it asked me for authentication. Once I did this it all started to work, so you might be right about authentication.

Thanks for your help again much appreciated.

cheers Markus

Happy for you!!
Please note if I understand correctly what you wrote is that you are using “normal” authorization and not the token. It means that any reboot/restart you will loose the credential and have to authorize manually again. That is why token is preferred.
GV