Motion Sensor controlled by a webhook camera

My goal is a motion sensor that is controlled via a webhook. The following scenario: a camera sends a webhook, e.g. “Motion Detected” at HA. Here I have a motion sensor with which I can create further automation.
I have solved it so far that a webhook triggers automation directly and thus my switch, which is turned off after 5s.
Now I want to solve it a little more elegantly and simulate the movement switch using webhook. In principle, this will probably be a binary sensor. I just don’t know how to link it to a webhook.
How could I do that? I would be grateful for a few ideas.

A webhook url to an automation is a road…

With motionOS you can also do a command, so you can do a curl to change the state of something…

thank you for your quick reply. Do you have an example for motionOS. I haven’t found any examples here yet. I am an absolute beginner. The solution with the webhook to automation was the easiest for me. Not the most practical, however. Unfortunately, the camera only delivers a webhook. And with that I want to drive a motion sensor in HA.

I found a simple example here:

  - platform: template
        device_class: motion
        value_template: "{{ is_state('switch.movement', 'on') }}"

Here the question arises how do I link the value_template with the webhook?

What do you want todo when there is motion detected? Why do you want to turn on a binary sensor?

The sensor should also be linked to HomeKit. I have proceed this successful with other switches. My idea is to use the motion sensor for HomeKit and HA automation.

you could make a rest command to change a state of something like a binary_sensor

then fire that rest command with a webhook , untested code below

    url: https://yourip:8123/api/states/binary_sensor.xxxx
    method: POST
      authorization: Bearer (yourtoken here)
      content-type: 'application/json'
    payload: '{"state":"on"}'
    verify_ssl: false

- alias: 'webhook' ##  ##
    - platform: webhook
      webhook_id: your_webhook_id
  - service: rest_command.sensor1

not sure I follow the use case, but have a look at this.

another possibility for a camera derived sensor is motioneye and a sensor via mqtt.

Yeah, so many roads… But setting up mqtt only for this is an overkill

Yes, MQTT should not be the problem. Mosquito server is already installed and in action.

Unfortunately I haven’t found a solution yet. As a beginner, I studied a lot of instructions and still haven’t found the right solution.
In principle, it should be possible to change the status of a switch using an external command.
I have already created a token for this. Now I try to send a command with the Postman app to change the status of a switch. So far without success.
As a test, I used GET to display the current errors. That’s working.


How can I now send a POST to set the status of a switch?

using mqtt you could do something like this:

mosquitto_pub -h -t cameras/frontdoor/motion -u youruser -P password -m ON

It triggers this sensor:

- platform: mqtt
  name: "Frontdoor Motion"
  state_topic: "cameras/frontdoor/motion"  
  device_class: motion
  payload_on: "ON"
  off_delay: 5
  unique_id: frontdoor_motion
1 Like

You want to change the state? Or you you want to turn on/off a switch? There is a big difference…
Now you are talking about a switch, before a binary sensor… That’s also a big difference…

If you want to turn on a switch (light for example) then you can just use a service

At the developer site I can change the state of the binary switch manually.
Now what I am trying to do is to change the state via api.

I now have a workaround that works. First I set up a mqtt binary switch with the motion property. Then an automation with the event webhook and action the mqtt binary switch. So I have one more step but it works very well.