Assistance with ESPHome Pulse Counter sensor

Having trouble with a sensor.

Here’s the code:

  - platform: pulse_counter
    pin: GPIO5
    id: cubic
    icon: mdi:fire
    name: "Measured Cubic Gas"
    filters:
      # (imp 1/0.01 m3)
      - multiply: 0.01
    unit_of_measurement: 'm3'

  - platform: template
    name: "Measured Gas"
    id: energy
    icon: mdi:fire
    filters:
      # kWh = m3 * correction factor * calorific value ) / 3.6
      - lambda: return ( id(cubic).state * 1.02264 * 40.6 ) / 3.6;
    unit_of_measurement: 'kWh'

  - platform: total_daily_energy
    name: "Daily Gas"
    power_id: energy
    icon: mdi:fire
    unit_of_measurement: 'kWh'

And here’s the output:

[16:32:19][D][pulse_counter:174]: 'Measured Cubic Gas': Retrieved counter: 85.01 pulses/min
[16:32:19][D][sensor:126]: 'Measured Cubic Gas': Sending state 0.85010 m3 with 2 decimals of accuracy
[16:33:19][D][pulse_counter:174]: 'Measured Cubic Gas': Retrieved counter: 106.99 pulses/min
[16:33:19][D][sensor:126]: 'Measured Cubic Gas': Sending state 1.06991 m3 with 2 decimals of accuracy

As can be seen, the problem is only “Measured Cubic Gas” is read from the sensors, but I was expecting an output from “Measured Gas” and Daily Gas" too. Any ideas?

I think your logic in your Meaured Gas filter needs to be in a lambda.

Bit like this.

  - platform: template
    name: "Measured Gas"
    id: energy
    icon: mdi:fire
    lambda: return ( id(cubic).state * 1.02264 * 40.6 ) / 3.6;
    unit_of_measurement: 'kWh'
1 Like

Perfect, thanks for that!

1 Like