Multiple pulse_meter - should this work?

I have several pulse_meter sensors configured using the same pin.

  - platform: pulse_meter
    pin: 16
    name: "Water this hour meter"
    id: water_this_hour_meter
    internal_filter: 100ms
    timeout: 30s
    total:
      name: "Water used this hour"
      unit_of_measurement: "l"

  - platform: pulse_meter
    pin: 16
    name: "Water this week meter"
    id: water_this_week_meter
    internal_filter: 100ms
    timeout: 30s
    total:
      name: "Water used this week"
      unit_of_measurement: "l"

  - platform: pulse_meter
    pin: 16
    name: "Water this month meter"
    id: water_this_month_meter
    internal_filter: 100ms
    timeout: 30s
    total:
      name: "Water used this month"
      unit_of_measurement: "l"

  - platform: pulse_meter
    pin: 16
    name: "Water yesterday meter"
    id: water_yesterday_meter
    internal_filter: 100ms
    timeout: 30s
    total:
      name: "Water used yesterday"
      unit_of_measurement: "l"

  - platform: pulse_meter
    pin: 16
    name: "Water change meter"
    id: water_change_meter
    internal_filter: 100ms
    timeout: 30s
    total:
      name: "Water used this change"
      unit_of_measurement: "l"

However, only the last one in the config is counting the pulses.

Should this be working? If not, I can change to using globals, however, if it shouldn’t be working, why does it compile?

Maybe make one pulse meter sensor and the rest make a template sensor:

  - platform: pulse_meter
    pin: 16
    name: "Water change meter"
    id: water_change_meter
    internal_filter: 100ms
    timeout: 30s
    total:
      name: "Water used this change"
      unit_of_measurement: "l"

  - platform: template
    name: "Water this hour meter"
    id: water_this_hour_meter
    lambda: |- 'return  id(water_change_meter).state;'
    unit_of_measurement: "l"

There is probably a better way to do this - and my syntax is probably wrong, but this may be worth a try and should get you started.

You could also just create a template sensor in HA rather than in ESPHome

Thanks, Daryl.

I need to keep everything local to the ESPHome. Your suggestion will certainly be an option, as will global variables.

I’m not stuck with this, though I don’t understand why there’s seemingly nothing in the docs to suggest that it won’t work and it validates and compiles and runs fine. It just doesn’t work!

And what is it about the last one that means it does work?

Using multiple pulse_meter makes the setting and resetting simpler, to my mind.

I’ll give the template option a try.

The template option is not working as needed as it just mimics the pulse_meter rate and not the total.

  - platform: pulse_meter # Pulses from physical meter
    pin: 16
    name: "Water Meter"
    id: water_meter
    internal_filter: 100ms
    unit_of_measurement: "l/min"
    total:
      name: "Total water used"
      id: total_water_used
      unit_of_measurement: "l"
    accuracy_decimals: 0
    on_value:
      then:
        - sensor.template.publish:
            id: water_this_hour_meter
            state: !lambda 'return ((id(water_meter).state));'

  - platform: template
    name: "Water this hour meter"
    id: water_this_hour_meter
    unit_of_measurement: "l"
    accuracy_decimals: 0

If I publish using the following…

    on_value:
      then:
        - sensor.template.publish:
            id: water_this_hour_meter
            state: !lambda 'return ((id(total_water_used).state));'

… then it passes validation but doesn’t compile.

ERROR Circular dependency detected! Please run with -v option to see what functions failed to complete.

It seems that the created additional total: sensor can’t be used.

If it would compile then I’d just need some simple maths to get the totals over the different time periods.

This is where the multiple pulse_meter option is preferable. I can just reset the pulse_meters using on_time:.

This brings me back to where I started. Why doesn’t the multiple pulse_meter option work?

If I change the order of the above pulse_meter configurations, it’s always the last one defined that works.

This is odd behaviour indeed.

Hello @ashscott

Did you ever work this out?
Ive got the same problem where only the last of a pulse_meter sensor send any values.
If for example, I have two and alternately comment out one of them, the other works, so I know the individual code is correct.

I suspect this may be the way its meant to operate, but cant find that its documented as such.

No. I gave up on it.

I don’t understand the reason for it not working. I am pleased you confirmed the issue for me.

I tried to set up multiple sensors off one pin but it didn’t work. I sort of assumed, that I was asking too much; instead I used three “sensor: - Platform: template” to produce different mathematical calculations of the raw pulses that the pulse sensor produces. So my one sensor is producing four different numbers. My calculations were min/ max averages over different periods which is easy … if you were to count fixed period that might be a bit more tricky and probably need to set up a total from the sensor; with a reset as and when needed. And then a template with lambda formula. I am not expert but that is as far as I got

Would you please post the code for this?

Hello @ashscott

sensor:
  - platform: pulse_meter
    pin: 
      number: 16
      inverted: false
    name: "Wind Base Pulse"
    id: windpulse
    internal_filter: 100us
    internal_filter_mode: pulse
    icon: 'mdi:weather-windy'
    filters:
      - throttle_average: 1s
      - multiply: 1.10 
      - filter_out: nan            

  - platform: template
    name: "Wind 3s Base"
    id: wind3sbase
    unit_of_measurement: 'Knts'
    icon: 'mdi:weather-windy'
    lambda: |-
      return 1*id(windpulse).state;
    accuracy_decimals: 1
    update_interval: 3s
    filters:
      - throttle_average: 3s
      - multiply: 0.0325866

  - platform: template
    name: "Wind Speed"
    id: wind
    unit_of_measurement: 'Knts'
    icon: 'mdi:weather-windy'
    lambda: |-
      return 1*id(windpulse).state;
    accuracy_decimals: 1
    update_interval: 1s
    filters:
      - sliding_window_moving_average:
          window_size: 300
          send_every: 10
      - multiply: 0.0325866

The output of the Template Sensor called “Wind_3s_Base” is picked up in HA and I run statistics to calculate moving window min/ max. ESPHome is not able to calculate moving min/ max (albeit it can do moving average) , hence why I shifted that out to HA.

In all I am calculating five different values from the pulse sensor.

1 Like