Pulse counter to binary sensor

Hello everybody,

I’m trying to build a door locked/unlocked sensor with ESPHome. Until about an hour ago I was using a homebrew homie node (GitHub - homieiot/homie-esp8266: 💡 ESP8266 framework for Homie, a lightweight MQTT convention for the IoT), but since it was the last of its kind in my IoT world I wanted to get rid of it. The hardware is an ESP 8266 with an optocoupler connected to GPIO13. When the door is unlocked, the optocoupler pulses with 50Hz.

My ESPHome configuration for this right now is the following:

sensor:
  - platform: pulse_counter
    pin: GPIO13
    name: "Pulse Counter"
    id: optocoupler
    update_interval: 1s

binary_sensor:
  - platform: template
    name: "Door Open"
    id: door_open
    condition:
      sensor.in_range:
        id: optocoupler
        above: 500.0  # 50Hz are around 3000 pulses/second

This works reliably for the door locked/unlocked detection, but on the other hand it pushes the pulse counter to home assistant every second, which I don’t need/want.
I tried setting the update_interval to never, but unfortunately that also killed the door locked/unlocked detection.

Is there a way to create a binary information from the optocoupler pin (pulses / no pulses) without actually sending pulse counter values to home assistant?

Add this to your pulse counter:
internal: true

Your numbers don’t match here, 50Hz means 50 pulses per sec, not 500 or 3000

Thanks karosm,

internal: true was the missing bit of information.

The numbers match perfectly. I could have picked 1000 or 2000 as well. I just need a number which is significantly more than zero and less than 3000 to detect the true state :slight_smile:
But the comment is indeed wrong. Should have been minute instead of second.

You are welcome! And I had no doubts about your pulses, just comment about your comment… :wink: