Skip to content

Support for interrupts on GPIO Binary Sensor #3101

Description

@AndersWestman

Describe the problem you have/What new integration you would like

There is, as I know, no easy way to independent detect an incoming pulse on a GPIO pin shorter than the 16ms cycle time.
A possibility to enable an interrupt feature for the GPIO Binary Sensor would be a great benefit for those cases.

Please describe your use case for this integration and alternatives you've tried:

I added an ESP32 into an existing product to be able to read/sniff some signals, but some signals was as short as 100us which cause some problems as it is too short to be detected other then by just pure luck by the GPIO Binary Sensor.
The time between the pulses in this case can be widely different from a few times/s to several hours in between.

I was able to make a workaround by using the Pulse Counter Sensor, but it's not an optimal solution.
I had do use a very low update interval, create a binary sensor to evaluate if the counter has changed and set the logger to INFO to not flood the logs due to the low update interval on the Pulse Counter Sensor.
But it works.

Additional context

I don't have the knowledge how/if/what is possible to implement, but I can see at least two different main functional princips here.

  1. The interrupt detects a pulse and ESPHome handles it in the next cycle which will cause a delay of some ms. Probably the easiest to implement (I guess?) and probably good enough for the majority of use cases.

  2. The interrupt detects a pulse and ESPHome immediately handles it.
    I can't really see any obvious cases for this behavior as the cycle time will cause some ms delay for anything else anyway, but maybe there is?

Some possibilities to select which edge to trig on, and maybe even something for filtering would be nice if possible.
And there are surely some more things that I have not thought of... :)

I see something like this in my mind:

binary_sensor:
  - platform: gpio
    pin:
      number: D2
      mode:
        interrupt: true
          trig_mode: rising_edge     (or falling_edge or both_edges)
          internal_filter: 2ms
    name: ...

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions