Setup pulse meter or pulse counter

I have an meter for a heat pump and would like to show the consumption in the energy dashboard the consumption. For this I use the S0 interface as described here

The meter delivers 100 pulses per kwh

Pulse Counter:

sensor:
  - platform: pulse_counter
    pin: GPIO5
    name: 'Power'
    id: power
    unit_of_measurement: 'kW'
    state_class: measurement
    device_class: power
    filters:
      - multiply: 0.6 # (60s/100 pulses per kWh)
    total:
      name: 'Energy'
      id: energy
      unit_of_measurement: 'kWh'
      state_class: total_increasing
      device_class: energy
      accuracy_decimals: 3
      filters:
        - multiply: 0.001

Now I saw that there is also a pulse meter sensor. The setup should be similar, correct?

Pulse Meter:

sensor:
  - platform: pulse_meter
    pin: GPIO5
    name: 'Power'
    id: power
    unit_of_measurement: 'kW'
    state_class: measurement
    device_class: power
    filters:
      - multiply: 0.6 # (60s/100 pulses per kWh)
    total:
      name: 'Energy'
      id: energy
      unit_of_measurement: 'kWh'
      state_class: total_increasing
      device_class: energy
      accuracy_decimals: 3
      filters:
        - multiply: 0.001

Which platform is better to display the consumption in the Energy Dashboard?

Is there a way to synchronize the kwh on the display with the pulse counter/meter?
I think this is service: Pulse Counter Sensor — ESPHome

If the display show 9000 kwh, i have to put 9000 or 9000 * 100?

“This value is the raw count of pulses, and not the value you see after the filters are applied.”
From this note. I would expect 9000 * 100

As I understand it, the pulse_counter and pulse_meter are similar, but not the same. In this post the differences are nicely explained.
Also, the pulse_counter has more options to tweak the set-up, like count_mode and use_pcnt for ESP32 hardware support.
I am using the pulse_counter for my water meter sensor.

Some small remarks to you code:

    filters:
      - multiply: 0.6 # (60s/100 pulses per kWh)

The value 0.6 is correct, but the remark should be something like:

    filters:
      - multiply: 0.6 # (60 minutes per hour / 100 pulses per kWh)

I think this is also wrong on the ESPHome Pulse Counter Documentation page.

    total:
      name: 'Energy'
      ------
      filters:
        - multiply: 0.001

This multiply value probably has to 0.01 in your case because your sensor delivers 100 pulses per kWh.

I think this is correct if you want to set the counter to 9000 kWh with 100 pulses per kWh.

I saw this, but for my use cases Iam a little bit confused what is the right. I think both will work.

Yes I just copy it from the docu page.

Uhhh yes also copy paste, but you are right I have kW and not only W as unit

So i have to use for the service 900000 pulses.
Is this just for the sensor value or will this also change the “real” display?

pulse_counter is better for dashboard, because it gives you the correct energy.
This is not the case for pulse_meter as this one assumes further energy consumption after turning the device off - for a specified time. And this assumed consumption, which is not real, gives you an error on the energy.
You don’t have this problem witch pulse_counter.

1 Like

Thanks, then I go with pulse_counter for the heating pump. This can just be on/off.

Did not work

Get no pulse:

[16:45:50][D][sensor:090]: ‘Power’: Sending state 0.00000 kW with 2 decimals of accuracy
[16:45:50][D][pulse_counter:150]: ‘Power’: Total : 0 pulses
[16:45:50][D][sensor:090]: ‘Energy’: Sending state 0.000 kWh with 3 decimals of accuracy

This is my code:

esp32:
  board: esp32doit-devkit-v1
  framework:
    type: arduino

sensor:
  - platform: pulse_counter
    pin: GPIO5 #D5
    name: 'Power'
    id: power
    unit_of_measurement: 'kW'
    state_class: measurement
    device_class: power
    filters:
      - multiply: 0.6 # (60 minutes per hour / 100 pulses per kWh)
    total:
      name: 'Energy'
      id: energy
      unit_of_measurement: 'kWh'
      state_class: total_increasing
      device_class: energy
      accuracy_decimals: 3
      filters:
        - multiply: 0.01

Pinout:

and

What could I try?

I tried a new D1 mini board with pin D4 and impulses now seem to be coming in :slight_smile:
The values or the conversion into kwh seem to be wrong (around factor 10 to much).
I reset the recorder again and pulse counter again. Then I have tomorrow the right values.

In the meantime maybe a question if I have 100 pulses per kwh.

Aren’t the values ​​0.6 and 0.01 double converted now?
@thusassistint can you explain the value(s)?

I understand 0.01:
1 / 100 pulses = 0.01
1 / 1000 pulses = 0.001

But is 0.06 not right got both?

Initially I thought that as well: I initially assumed that the total sensor would use the output from the pulse-counter sensor as input.
But that appears not to be the case: the total sensor uses the same input as the pulse_counter sensor, so it counts the raw pulses and not the converted output.

By default the pulse_counter measures the power using pulses/minute.
Your meter gives 100 pulses per kWh.
Let’s assume that the pulse_counter measures 1 pulse / minute.
Then this is 1/100 kWh / minute in your case.
And that is 1/100 * 60 kWh / hour = 0.6 kWh / h = 0.6 kW.
So the multiply factor for the pulse_counter should be 0.6 in your case to measure power in kW with 100 pulses per kWh.

The total sensor by default just counts the total number of accumulated pulses.
So if the total amount of pulses for instance is 10000 this is 10000/100 = 100 kWh in your case.
So you have to use a multiply factor of 0.01 for the total sensor to convert the total number of pulses to kWh in your case.

Does this make sense?

1 Like

Ok interesting, but I see my on meter I have 0,2 kwh and the sensor has 2480 kwh. So something went wrong. Let’s try 1000 pulses per kwh. On the meter I see 100 per kwh, but on the documentation it’s 1000 :open_mouth:.

So next try I put: 0.06 and 0.001

@thusassistint and @der-optimist thanks a bunch, it works. Also the Energy Dashboard works with daily values.

One more question:
What is the best way to build a daily consumption sensor? Can this be done directly in the ESP?

I use utility meter for this:

Never tried to do this in ESP

That’s clear, but what do I use for the source? The total increase sensor?

Yes that is the question :smiley: but I just try it with a “normal” util meter

Hey,
I didn’t read all responses but as I had a related issue some time ago…

My use case was a bit more complicated and posed a bit of a challenge.
It is my personal believe that the esphome implementations pulse_meter as well as pulse_counter are flawed, i.e. limited in functionality and very badly documented. Someone should unify them into one consistent pulse measurement component.

Anyhow, I ended up building what I needed by myself, which is quite easy. @MelleD maybe consider that:

1 Like

The pulse counter looks good so far ( ok since 2 two days :slight_smile: ). Let’s see what it looks like after a month.

I think I also need a daily util meter like in your post. I’ll try that.

Works quite well so far and the values ​​are accurate.

However, I still have the problem that as soon as an ESP home update comes in and I install it, the total sensor always jumps to 0 after the update. Can this be prevented?

What I did with my water meter is adding a global variable in which the total value is stored on shutdown and at an interval, and which value is restored at startup.
Something like this:

esphome:
  .....
  on_boot:
    then:
      - pulse_counter.set_total_pulses:
          id: power
          value: !lambda 'return id(global_total);'
  on_shutdown:
    then:
      - globals.set:
          id: global_total
          value: !lambda 'return id(total_increasing).state;'

interval:
  - interval: 60s
    then:
      - globals.set:
          id: global_total
          value: !lambda 'return id(total_increasing).state;'

globals:
  - id: global_total
    type: int
    restore_value: yes

I added the interval to ensure that the latest value is stored in the case of an inadvertent reboot, like at an power outage.

1 Like

Not myself but a friend of mine did something similar via Home Assistant. Advantages:

  1. No memory wear
  2. Ability to set/reset/adjust the absolute value through an input option in Home Assistant
  3. Home Assistant mainly in control (that’s in many cases beneficial)

I don’t think this is such a big issue because ESPHome is only really writing a value to flash when the previous value is indeed changed.

With my method it is still possible to adjust the value via an input option in HA if required.
I do this as well with my water meter to correct for small deviations with the real water meter.

I prefer to keep the sensor output processing local on the ESP as much as possible, so that this is not disturbed by a (short or long) outage of Home Assistant.
So when HA is offline and comes back online again the sensor values from the ESPs are still accurate.

@thusassistint thanks for sharing.

Looks like a bit of a workaround. Pity that there is no out of the box solution. Maybe raise up a feature request or at least a contribution in the documentation.

Does your solution also work with the Energy dashboard?
If I manually after startup set the pulse_counter.set_total_pulses. I have to delete the wrong statistic for the dashboard

Yes it does, I am using my ESPHome sensor sensor.water_total as input for the Water consumption in the Energy Dashboard.

1 Like