Door sensor REST

Hi,
I want to create door sensor. I read something about RESTful binary sensors but I found out that with this method the server makes requests to the sensor. For door sensor I want it to be quick. I want the sensor to request to the server.
So far I just solved it so that I created template and change the state of the sensor with API with API token from my Home Assistant account. So it shows that I opened the door not that the door opened.
Do you have any solution for this?

What type of door sensor do you have (manufacturer/model)?

1 Like

Oh soory I didn’t mention that. It ESP32.

The ESPHome API pushes results to home assistant as soon as they happen:

1 Like

And Is there another solution? Sorry, but I don’t want to use ESPHome. I want just send http requests to the server just like I’m doing it now.

You could use webhooks. 2021.4: For our advanced users ❤️ - Home Assistant

1 Like

Ok, thank you, I think that it’s what I’m looking for.
But can you please help me with the configuration?
I have this so far:

template:
  - trigger:
      - platform: webhook
        webhook_id: ESPSensor1
    sensor:
      - name: "Door 22"
        state: "{{ trigger.json.door22 }}"
      - name: "Switch 11"
        state: "{{ trigger.json.switch11 }}"

I think it would be better if it was a binary sensor. Can you please tell me how to change that?

Binary webhook sensors are not yet available. Triggerable sensors were only just released in the last update.

You could convert your sensor to a binary sensor using a Binary Template Sensor. It’s a bit of a round-about way of doing it, but that’s what we have for now.

1 Like

And there is no other way that the sensor can tell the server that the door is opened?

You could use mqtt.

1 Like

Okay, thanks for the help. I think I’ll finally make it with ESPHome.

1 Like

ESPHome is really well integrated into home assistant. And it’s easy to flash to an ESP.

1 Like