Do something just with HA url post

Hi all,
I’m migrating from Domoticz to Home Assistant, so I’m trying to replicate all the functionalities.
I have a secutiry IP Camera that can call an URL (alarm server function) on motion detection trigger. I use this to turn on a light in Domoticz just setting a custom variable to 1 calling the Domoticz URL with the right parameters and then a LUA script read the variable and switch on the light.

I cannot replicate this in HA because the API is more complex and is a real REST API with token as authentication, but in the IP camera I cannot use headers, Json content, etc… I can only call a simple URL posting variables and authenticate with http simple auth username and password.

Is there any known workaround for this? Any idea?
I was thinking to use a local script in HA that can be called by URL like py, java, php, but I don’t have enought experience about HA http environment, what’s available, where the files are, etc…I use Hassio on rpi4.
Thanks for any suggestion on this topic, Mauro

I do the same with my camera, it’s possible with a webhook and automation… A webhook is a single url you can use,…

In that automation you can fire what you want, a script, a light…

2 Likes

Thanks Fabio! Didn’t know about webhook trigger, I’ve just read the documentation and will try following that route.

    Mauro

I’ve just tried what’s suggested by Fabio, but webhook needs a POST of the URL, whlile i can only send a standard GET and I also suspect that https is not supported by mi IP camera.

So I’m back to the intial question about how to solve this problem, I need to trigger a event by a simple URL GET.

          Thanks, Mauro

Hmm, can you show your webhook? I don’t think it need post… It works also from my cameras…

Hi Fabio, this is the webhook in automations.yaml
I’ve tested it with postman and it works only calling the URL https://myaddress:8123/api/webhook/testcam with POST not with GET (calling it in the browser does not work for example)

Maybe there is a different way to do it I’ve missed, but i’ve found many similar questions in the community and all says that it needs a POST not GET.
I’ll be more than happy to know your case and solution.

  • id: ‘1576104714229’
    alias: switch on light by IP Camera
    description: ‘’
    trigger:
    • platform: webhook
      webhook_id: testcam
      condition: []
      action:
    • device_id: 04171350c70d4eccb994fee3dd323bdb
      domain: switch
      entity_id: switch.shenzhen_neo_electronics_co_ltd_power_plug_12a_switch_2
      type: turn_on

no, calling it from browser is not going to work
try it first from a SSH terminal , like curl -x …

i am using the webhook from nabucasa
if dont have a nabucasa, you can make a .php script, i call that one from my Synology cameras… works better and internal

more info here , lots of info there

here is example of my .php

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://192.168.0.17:8123/api/webhook/deurbel');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);

$result = curl_exec($ch);
if (curl_errno($ch)) {
    echo 'Error:' . curl_error($ch);
}
curl_close($ch);


}

If you are new to HA, I would suggest adding node-red to your environment. I think, things are much easier with NR… such as automation or creation of web endpoint.
It is just one node to create the web endpoint, working with GET and no authentication if you want to.
I have started with HA solely and soon migrated everything to NR.
Hope this helps,
GV

What’s the make, model and firmware version of your camera? Do you have a Synology NAS?