GPIO contacts are failing

I have an energy meter, the data from which is read via a pulse output.
The problem is as follows. After connecting to the GPIO contact, after a while the pulses stop being counted. I changed 3 contacts and now another one has failed. I thought it was because of the pull-up resistors, so I enabled them programmatically. But it didn’t help.
Can anyone tell me what the problem is?
Below is the configuration that I use in ESPHOME.

substitutions:
  device_name: energy-meter
  friendly_name: energy-meter

esphome:
  name: ${device_name}

esp32:
  board: esp32dev
  framework:
    type: arduino

# Отключаем лог
logger:
  level: WARN
  baud_rate: 0

api: {}

ota:
  - platform: esphome
    password: !secret ota_pwd
wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password
  manual_ip:
    static_ip: 192.168.99.238
    gateway: 192.168.99.1
    subnet: 255.255.255.0
  fast_connect: true
  reboot_timeout: 5min
  ap:
    ssid: ${device_name}
    password: !secret ota_pwd_ap

web_server:
  port: 80
  version: 3

captive_portal:

time:
  - platform: homeassistant
    id: homeassistant_time

globals:
  - id: saved_total_power_consumption
    type: float
    restore_value: true
    initial_value: '0.0'

sensor: 
  - platform: pulse_counter
    pin:
      number: 17
      inverted: true
      mode:
        input: true
        pullup: true
    id: energy_meter_counter  
    name: "Electro energy Meter Pulse Count"
    unit_of_measurement: "pulses"
    accuracy_decimals: 1
    filters:
      - multiply: 0.0025
      - lambda: |- 
          id(saved_total_power_consumption) += x;
          return id(saved_total_power_consumption);
  - platform: template
    name: "Saved Total Energy Consumption"
    device_class: energy
    lambda: |-
      return id(saved_total_power_consumption);
    unit_of_measurement: kWh
    accuracy_decimals: 2
  - platform: uptime 
    name: "uptime_${device_name}"

switch:
  - platform: restart
    name: "restart_${device_name}" 

binary_sensor:
  - platform: status
    name: "Status_${device_name}"

esp32_ble_tracker:
  scan_parameters:
    interval: 1100ms
    window: 1100ms
    active: False

bluetooth_proxy:
  active: False

Scheme:

What voltage is that meter outputting?

I am inserted a scheme of connection. It is a 3 phase energy meter.

I edited my question. What voltage is being output on the impulse connection?

I don’t know. I can only show the part of the front panel where the voltage and current for the pulse output are indicated.

Looks like open collector or drain with a maximum pull-up of 24V and maximum sink of 30mA. Pretty standard and it is compatible with the ESP.

You do need a pull-up enabled or it won’t work.

I am already do that.

- platform: pulse_counter
    pin:
      number: 17
      inverted: true
      mode:
        input: true
        pullup: true

I mentioned it because you said:

The impulse output is just a transistor or mossfet that connects + to - when active. There’s no way it can kill GPIOs unless it is faulty or unless your cabling to the ESP is super long and picking up voltage spikes from elsewhere.

What long do you mean? About one meter is a long ?

Depends what it is running next to. If it is bundled up with cables connecting a 5000VA VFD pump then yes.

1 Like

No, ESP32 just lies in the junction box and a cable runs from the box to the energy meter.

:man_shrugging:

I have the same look… :grimacing: :grinning:

Is the code to use GPIO is correct?

- platform: pulse_counter
    pin:
      number: 17
      inverted: true
      mode:
        input: true
        pullup: true

Yeah that’s fine, assuming the indentation is a copy / paste mistake. It is correct in your full config above.

What you see on esphome log when that happens?