Many Pulse Counter Sensors with lesser Pins on one ESPHome


my home has 8 power meters and 7 water meters they are at the same place and could be controlled by one ESP32. However, with the current implementation at esphome-core/pulse_counter.cpp at 254d059945932adb64f5cbe8f4928ea19b4f6f00 · esphome/esphome-core · GitHub it would “cost” 17 pins. That’s a lot.

I was thinking of extending the code to support two pins per pulse counter. In this case ESPHome can use the sensors like a switch matrix.


Use RJ45 cables with 8 cores for the pulse meters. One core is for horizontal matrix. 7 cores are for vertical matrix.If you have 3 cables it requires 10 pins instead of 21 to read them out.


The configuration would look like it is now and is backward compatible. The sensor will get one optional tag named “control_pin”.

# Example configuration entry
   - platform: pulse_counter
     pin: 12
     control_pin: 7
     name: "First Pulse Counter on Pin 12"
   - platform: pulse_counter
     pin: 12
     control_pin: 8
     name: "Second Pulse Counter on Pin 12"  

control_pin will be set to LOW to read the meters of this line (RJ45 cable). Everything else remains as it is.
It is possible to mix pulse meters with and w/o control_pin in the same configuration.

I’d like to implement it.

What do you think about it?

Best regards,


Doesn’t the current implementation just measure pulses on a single GPIO pin, so you would require 15 pins for these meters?

Matrix switching gpio for pulse metering seems like a can of worms to me. Wouldn’t you risk missing pulses while you switch away from the pin? your sampling rate would need to be higher than pulse width * number of matrix-ed pins?

another route could be to use i2c GPIO extenders like
PCF8574 I/O Expander — ESPHome this would give you 16 extra GPIO pins
I am not sure if these would work (well) with with the pulse meter sensor though Pulse Meter Sensor — ESPHome


In general this might be an issue. However with energy meters, the frequency of pulses is very low. So, a high sampling rate is possible.
Meanwhile I checked the implementation
Currently the implementation uses interrupts. In this case, it is a bit complex to implement it.
I will stick to spend 15 pins for this task.

Thank you for the feedback.


I’ve been facing a similar issue and pulse_counter, pulse_meter and pulse_width only work with ESP32 pins. Not expander pins. I believe that this is a hardware limitation rather than ESPHome.