ESPHome + PCF8574 + Pulse Counter

I have a weather station with wind speed and rainfall detectors, these both use the pulse_counter option in ESPHome. Because the weather station is out on the roof I’m trying to figure out a good way to run some CAT5 Ethernet most of the way and have the brains located in the attic.

I got really excited when I saw a bunch of articles on stack exchange about this and the idea is to run i²c via PCA9615.

However, this means that all the distant equipment needs to be communicating over i²c. I thought about this for a while and realized I could use an I/O expander module to get remote GPIO data without having to send it over the Ethernet. I have one of these PCF8574s so I tried to mock it up on a breadboard and see if I could get it to work:

  - id: 'pcf8574_hub'
    address: 0x20
    pcf8575: False

  # irq_pin: D7
    pcf8574: pcf8574_hub
    number: 2
  indoor: false

  - platform: pulse_counter
#    pin:
#      number: D6
#      mode: INPUT_PULLUP
      pcf8574: pcf8574_hub
      number: 0
      mode: INPUT_PULLUP
    unit_of_measurement: 'in'
    name: 'Rain Pulses 1min'
    icon: 'mdi:weather-rainy'
    id: rain_pulses_1min
      rising_edge: DISABLE
      falling_edge: INCREMENT
    internal_filter: 50us
    update_interval: 60s
    internal: True
      - multiply: 0.011
    accuracy_decimals: 3

When I try to validate this, it tells me that [pcf8574] is an invalid option for [pin]. Please check the indentation. It only reports this for the pulse_counter and not for the as3935_i2c device. Reading about ESPHome’s support for the PCF8574, it says:

Any option accepting a Pin Schema can theoretically be used, but some more complicated components that do communication through this I/O expander will not work.

I’m guessing that I’m running into this “more complicated components” issue with the pulse counter but I thought I’d post it here just in case anyone from the community has any ideas.


Why cant you just run the sensor outputs direct to the ESP over Cat5?

I can and am doing that now but the distance is definitely affecting the i²c signals so I’m guessing it’s impacting the pulse counters, too. Everything works with a “short” cable and I get lots of communication errors with longer cables. Just trying to design something that works 100% of the time. If it’s frequency related, I don’t want to end up clipping high wind-speed values…

I don’t think I understood correctly. I thought your sensors were just contact closures that you counted pulses on, not I2C. You can go 30m+ over cat5 for contact closures.

Ah, no you got it. I wasn’t aware I could go 30m+ with that type of sensor. The other benefit was going to be pin count because I’m limited to 8 pins on the CAT5 cable but I think I can squeeze those two pulse counter signals into the 8-pin limit. Thanks @tom_l!

You’re limited to 4 sensors. You really want an earth return twisted with each sensor wire for common mode noise rejection.

Well, I need to do i²c over this cable too; and if I use SparkFun’s solution it will consume all but two RJ45 pins:

I just purchased some P82B96P devices which should allow me to send i²c signals over two wires, if I include power and ground that leaves 4 more pins to send data. I’m not real clear on what an “earth return” is so I’ll have to do some googling to learn but I’m guessing I could spend two of those pins on earth return for the pulse counter signals based on what you’re saying to maximize the signal quality.

Interesting, I didn’t know there were differential i2c devices. That is like upgrading uart with rs485.