[SOLVED] Esphome maximum pulse_counter sensors on a ESP32-S2 mini?

Hello,

i have a ESP32-S2 mini with 5 pulse-counter sensor for water flow, 4 sensor works, 1 is always “unknow” in esphome, no data from this sensor in the logs.

I change the GPIO39 who work for a sensor to this “unknown”. same result.

i know the “porche” sensor is working because i plug it on the connector of the “cuisine” sensor on GPIO37, it work.

I really dont know what is happening, seems there is a software bug.

I change to a new board, same result.

Strange thing is i put “accuracy_decimal” to 2 like the 4 others and in HA the sensor is set to 0 (default), not like the other, who are set to 0.00, like “accuracy_decimal” is set in Esphome.
2nd thing : on the SSD1306 the value is “nan” for this sensor. Anywhere i can see some warning or state in the logs like if he doesnt exist…

Here is the complete code:

esphome:
  name: compteur-eau

esp32:
  board: lolin_s2_mini
  variant: esp32s2
  framework:
    type: arduino

preferences:
  flash_write_interval: 5min

# Enable logging
logger:



# Enable Home Assistant API
api:
  encryption:
    key: "ixxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"

ota:
  password: "dxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_pwd
  manual_ip:
    static_ip: 192.168.1.xxx
    gateway: 192.168.1.xxx
    subnet: 255.255.255.0
    dns1: 192.168.1.xxx
  fast_connect: on
  power_save_mode: none

status_led:
  pin:
    number: GPIO15 #ESP32 S2 Mini OnBroad LED
    inverted: false

i2c:
  sda: GPIO35
  scl: GPIO33
  scan: True

time:
  - platform: homeassistant
    id: time_ha

globals:
   - id: state_of_display
     type: int
     restore_value: no
     initial_value: "0"

switch:
  - platform: restart
    name: "Restart Compteur Eau"
  - platform: template
    name: "Display Compteur Eau"
    id: switch_display_compteur_eau
    optimistic: true
    lambda: |-
       if (id(state_of_display) == 1) {
         return true;
       } else {
         return false;
       }
    on_turn_on:
      then:
        if:
          condition:
            lambda: 'return id(timer_display_compteur_eau).state > 0;'
          then:
            - delay: !lambda "return id(timer_display_compteur_eau).state * 100000;"
            - lambda: id(my_display_compteur_eau).turn_off();
            - lambda: id(state_of_display) = 0;
  - platform: gpio
    pin: GPIO5
    id: ntc_vcc


number:
  - platform: template
    name: "Index compteur d'eau"
    id: index_compteur_eau
    optimistic: true
    unit_of_measurement: 'm³'
    min_value: 226
    max_value: 500
    step: 0.01
    restore_value: true
  - platform: template
    name: "Timer Display Compteur d'Eau"
    id: timer_display_compteur_eau
    optimistic: true
    unit_of_measurement: 'min'
    restore_value: true
    initial_value: 1
    min_value: 0
    max_value: 10
    step: 1

binary_sensor:
  - platform: status
    name: "Status Wifi Capteur Compteur Eau"
    id: etatWCCeau

  - platform: gpio
    name: "on off display"
    pin:
      number: GPIO1
      inverted: true
      mode:
        input: true
        pullup: true
    internal: true
    id: on_off_display
    filters:
      - delayed_on: 10ms
      - delayed_off: 10ms
    on_press:
      then:
        lambda:  |-
          if ( (id(state_of_display) == 1) ) {
            id(my_display_compteur_eau).turn_off();
            id(state_of_display) = 0;
            ESP_LOGI("info", "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!BUTTON PRESSED : my display is OFF!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
          } else {
            id(my_display_compteur_eau).turn_on();
            id(state_of_display) = 1;
            ESP_LOGI("info", "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!BUTTON PRESSED : my display is ON!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
            }
                         


sensor:
  - platform: wifi_signal
    name: "WiFi Signal Capteur Compteur Eau"
    update_interval: 60s
    id: signalWCCeau

  - platform: resistance
    sensor: source_sensor
    configuration: UPSTREAM
    resistor: 10.0kOhm
    accuracy_decimals: 2
    name: resistance_general_eau
    id: resistance_general_eau
    icon: mdi:resistor

  - platform: template
    name: "temperature arrivee d eau"
    id: temp_eau_compteur_general
    unit_of_measurement: "°C"
    icon: "mdi:water-percent"
    accuracy_decimals: 2  
    update_interval: 10s
    filters:
    - sliding_window_moving_average:
        window_size: 7
        send_every: 1
    lambda: |-
      float A = -0.0023372161946098318;
      float B = 0.0006789562966514373;
      float C = -1.3022483012452408e-06;
      float LR = log(id(resistance_general_eau).state);
      return  (1.0/(A + B*LR + C*LR*LR*LR) - 275.15);

  - platform: adc
    id: source_sensor
    pin: GPIO3
    update_interval: 60s

  - platform: pulse_counter
    pin:
      number: GPIO2
      mode:
        input: true
        pullup: true
    unit_of_measurement: 'L/min'
    accuracy_decimals: 2
    id: main_water_flow_meter
    name: "Débit d'eau instantané général"
    update_interval: 10s
    filters:
      - lambda: return (x / 396); # 396 = 6,6 * 60
  - platform: integration
    name: "Index Eau compteur général en M3"
    id: index_eau_compteur_general_mc
    state_class: "total_increasing"
    device_class: "water"
    unit_of_measurement: 'm³'
    accuracy_decimals: 2
    sensor: main_water_flow_meter
    time_unit: min
    restore: true
    filters:
        - lambda: return ( id(index_compteur_eau).state + (x / 1000));
  - platform: integration
    name: "Eau total au général en M3"
    id: eau_total_general_mc
    state_class: "total_increasing"
    device_class: "water"
    unit_of_measurement: 'm³'
    accuracy_decimals: 2
    sensor: main_water_flow_meter
    time_unit: min
    restore: true
    filters:
        - lambda: return (x / 1000);
  - platform: integration
    name: "Eau total au général en Litre"
    state_class: "total_increasing"
    device_class: "water"
    unit_of_measurement: 'L'
    accuracy_decimals: 2
    sensor: main_water_flow_meter
    time_unit: min
    restore: true
    id: eau_total_general_litre

  - platform: pulse_counter
    pin:
      number: GPIO4
      mode:
        input: true
        pullup: true
    unit_of_measurement: 'L/min'
    accuracy_decimals: 2
    id: sdb_water_flow_meter
    name: "Débit d'eau instantané SDB"
    update_interval: 10s
    filters:
      - lambda: return (x / 660); # 660 = 11 * 60
  - platform: integration
    name: "Eau total SDB en M3"
    id: eau_total_sdb_mc
    state_class: "total_increasing"
    device_class: "water"
    unit_of_measurement: 'm³'
    accuracy_decimals: 2
    sensor: sdb_water_flow_meter
    time_unit: min
    restore: true
    filters:
        - lambda: return (x / 1000);
  - platform: integration
    name: "Eau total SDB en Litre"
    state_class: "total_increasing"
    device_class: "water"
    unit_of_measurement: 'L'
    accuracy_decimals: 2
    sensor: sdb_water_flow_meter
    time_unit: min
    restore: true
    id: eau_total_sdb_litre

  - platform: pulse_counter
    pin:
      number: GPIO18
      mode:
        input: true
        pullup: true
    unit_of_measurement: 'L/min'
    accuracy_decimals: 2
    id: wcs_water_flow_meter
    name: "Débit d'eau instantané WCs"
    update_interval: 10s
    filters:
      - lambda: return (x / 660); # 660 = 11 * 60
  - platform: integration
    name: "Eau total WCs en M3"
    id: eau_total_wcs_mc
    state_class: "total_increasing"
    device_class: "water"
    unit_of_measurement: 'm³'
    accuracy_decimals: 2
    sensor: wcs_water_flow_meter
    time_unit: min
    restore: true
    filters:
        - lambda: return (x / 1000);
  - platform: integration
    name: "Eau total WCs en Litre"
    state_class: "total_increasing"
    device_class: "water"
    unit_of_measurement: 'L'
    accuracy_decimals: 2
    sensor: wcs_water_flow_meter
    time_unit: min
    restore: true
    id: eau_total_wcs_litre

  - platform: pulse_counter
    pin:
      number: GPIO39
      mode:
        input: true
        pullup: true
    unit_of_measurement: 'L/min'
    accuracy_decimals: 2
    state_class: measurement
    id: cuisine_water_flow_meter
    name: "Débit d'eau instantané Cuisine"
    update_interval: 10s
    filters:
      - lambda: return (x / 660); # 660 = 11 * 60
  - platform: integration
    name: "Eau total Cuisine en M3"
    id: eau_total_cuisine_mc
    state_class: "total_increasing"
    device_class: "water"
    unit_of_measurement: 'm³'
    accuracy_decimals: 2
    sensor: cuisine_water_flow_meter
    time_unit: min
    restore: true
    filters:
        - lambda: return (x / 1000);
  - platform: integration
    name: "Eau total Cuisine en Litre"
    state_class: "total_increasing"
    device_class: "water"
    unit_of_measurement: 'L'
    accuracy_decimals: 2
    sensor: cuisine_water_flow_meter
    time_unit: min
    restore: true
    id: eau_total_cuisine_litre

  - platform: pulse_counter
    pin:
      number: GPIO37
      mode:
        input: true
        pullup: true
    unit_of_measurement: 'L/min'
    accuracy_decimals: 2
    id: porche_water_flow_meter
    name: "Débit d'eau instantané porche"
    update_interval: 10s
    filters:
      - lambda: return (x / 660); # 660 = 11 * 60
  - platform: integration
    name: "Eau total Porche en M3"
    id: eau_total_porche_mc
    state_class: "total_increasing"
    device_class: "water"
    unit_of_measurement: 'm³'
    accuracy_decimals: 2
    sensor: porche_water_flow_meter
    time_unit: min
    restore: true
    filters:
        - lambda: return (x / 1000);
  - platform: integration
    name: "Eau total Porche en Litre"
    state_class: "total_increasing"
    device_class: "water"
    unit_of_measurement: 'L'
    accuracy_decimals: 2
    sensor: porche_water_flow_meter
    time_unit: min
    restore: true
    id: eau_total_porche_litre

  - platform: uptime
    id: uptime_seconds
    name: "Uptime Sensor"
    update_interval: 60s
    unit_of_measurement: s
    accuracy_decimals: 0
    force_update: false
    icon: mdi:timer  

text_sensor:
  - platform: template
    name: compteur_eau_uptime
    update_interval: 60s
    icon: mdi:clock-start
    lambda: |-
      int seconds = (id(uptime_seconds).state);
      int days = seconds / (24 * 3600);
      seconds = seconds % (24 * 3600); 
      int hours = seconds / 3600;
      seconds = seconds % 3600;
      int minutes = seconds /  60;
      seconds = seconds % 60;
      return { (String(days) +"d " + String(hours) +"h " + String(minutes) +"m "+ String(seconds) +"s").c_str() };

font:
  - file: "arial.ttf"
    id: five8
    size: 10
  - file: "theboldfont.ttf"
    id: boldf
    size: 30

display:
  - platform: ssd1306_i2c
    model: "SSD1306 128x64"
    rotation: 0
    address: 0x3C
    id: my_display_compteur_eau
    pages:
      - id: page1
        lambda:  |-
          it.printf(8, 0, id(five8), "Index compteur general");
          it.printf(8, 0, id(five8), "_______________________");
          it.printf(0, 23, id(boldf), "      %.f", id(index_eau_compteur_general_mc).state);
          it.printf(0, 53, id(five8), "Wifi : %s", id(etatWCCeau).state ? "Online" : "Offline");
          it.printf(85, 53, id(five8), "%.1f", id(signalWCCeau).state);
          it.printf(115, 53, id(five8), "dB");

      - id: page2
        lambda:  |-
          it.printf(8, 0, id(five8), "Compteur Eau General");
          it.printf(8, 0, id(five8), "______________________");
          it.printf(0, 13, id(five8), "Temperature ......... %.1f °C", id(temp_eau_compteur_general).state);
          it.printf(0, 23, id(five8), "Debit instantane.... %.1f L/min", id(main_water_flow_meter).state);
          it.printf(0, 33, id(five8), "Conso totale .......... %.1f mc", id(eau_total_general_mc).state);
          it.printf(0, 53, id(five8), "Wifi : %s", id(etatWCCeau).state ? "Online" : "Offline");
          it.printf(85, 53, id(five8), "%.1f", id(signalWCCeau).state);
          it.printf(115, 53, id(five8), "dB");
          
      - id: page3
        lambda: |-
          it.printf(12, 0, id(five8), "Compteur Eau SDB");
          it.printf(12, 0, id(five8), "___________________");
          it.printf(0, 23, id(five8), "Debit instantane.... %.1f L/min", id(sdb_water_flow_meter).state);
          it.printf(0, 33, id(five8), "Conso totale .......... %.1f mc", id(eau_total_sdb_mc).state);
          it.printf(0, 53, id(five8), "Wifi : %s", id(etatWCCeau).state ? "Online" : "Offline");
          it.printf(85, 53, id(five8), "%.1f", id(signalWCCeau).state);
          it.printf(115, 53, id(five8), "dB");

      - id: page4
        lambda:  |-
         it.printf(16, 0, id(five8), "Compteur Eau WCs");
          it.printf(16, 0, id(five8), "__________________");
          it.printf(0, 23, id(five8), "Debit instantane.... %.1f L/min", id(wcs_water_flow_meter).state);
          it.printf(0, 33, id(five8), "Conso totale .......... %.1f mc", id(eau_total_wcs_mc).state);
          it.printf(0, 53, id(five8), "Wifi : %s", id(etatWCCeau).state ? "Online" : "Offline");
          it.printf(85, 53, id(five8), "%.1f", id(signalWCCeau).state);
          it.printf(115, 53, id(five8), "dB");

      - id: page5
        lambda:  |-
         it.printf(10, 0, id(five8), "Compteur Eau Cuisine");
          it.printf(10, 0, id(five8), "_____________________");
          it.printf(0, 23, id(five8), "Debit instantane.... %.1f L/min", id(cuisine_water_flow_meter).state);
          it.printf(0, 33, id(five8), "Conso totale .......... %.1f mc", id(eau_total_cuisine_mc).state);
          it.printf(0, 53, id(five8), "Wifi : %s", id(etatWCCeau).state ? "Online" : "Offline");
          it.printf(85, 53, id(five8), "%.1f", id(signalWCCeau).state);
          it.printf(115, 53, id(five8), "dB");

      - id: page6
        lambda:  |-
         it.printf(5, 0, id(five8), "Compteur Robinet Porche");
          it.printf(5, 0, id(five8), "_____________________");
          it.printf(0, 23, id(five8), "Debit instantane.... %.1f L/min", id(porche_water_flow_meter).state);
          it.printf(0, 33, id(five8), "Conso totale .......... %.1f mc", id(eau_total_porche_mc).state);
          it.printf(0, 53, id(five8), "Wifi : %s", id(etatWCCeau).state ? "Online" : "Offline");
          it.printf(85, 53, id(five8), "%.1f", id(signalWCCeau).state);
          it.printf(115, 53, id(five8), "dB");

interval:
  - interval: 10s
    then:
      - display.page.show_next: my_display_compteur_eau
      - component.update: my_display_compteur_eau
  - interval: 40s
    then:
      - switch.turn_on: ntc_vcc
      - component.update: source_sensor
      - switch.turn_off: ntc_vcc

if someone have an idea…i will be happy to have some help, thanks

Honestly it sounds like you have a bad sensor. The problem seems to stay with that one sensor no matter what GPO and what board you use (unless I misunderstood what you said).

thanks for your help.

sorry, english is not my native language : i connect the “unknown” sensor (porche) on the “cuisine” connector and it work! very odd…

i try a new sensor on the “cuisine” gpio37, it work. not on the gpio39, still “unknown”. so its not the sensor too.

i change the gpio37 for “cuisine” to gpio39, it works…so my connector and cable and solder is good. And its not a faulty Gpio…seems not…

seems it doenst work only for this sensor “porche”, its the last one, i understand nothing…

Last thing : when all sensors are disconnected, they all display 0.00, but the “porche” still “unknown”.

That why i thought it s a software bug or memory/flash issue

Sans titre

i have change the “cuisine” sensor below the “porche” sensor in the YAML code and now its the “cuisine” sensor that is “unknown”

seems there is a bug with the internal timer? read 5 sensor every 10s is too much?

i have try first to update every 5s, second every 6s, third every 7s, …ect…but doesnt work

is there a maximum of pulse_counter sensor please @OttoWinter ?

i change the board for a ESP32-devkit V1, no problem at all…seems th ESP32-S2 is not yet full implemented in ESPHOME…

Even if you duplicate the GPIO in the config, Esphome dont see anything…you can set all sensor you want on the same GPIO Lol

so the reply to my question is : 4 pulse-counter sensor maximum on a ESP32-S2, i mean for the moment, because sure this board will be more implemented in the future…i hope so, its a nice tiny board, very compact, same form factor like D1 Mini.