Pulse Meter Help Needed to Zero Out Total

I am setting up a fuel oil tank meter to keep track of the amount of oil in the tank based on top-ups and furnace burns.

I have everything working with except for:

I need to zero out the pulse count total after each furnace burn cycle. The setup works like this:

  1. Furnace burner is on and oil flows
  2. Sensor displays liters per minute and total liters.
  3. When supply water reaches 80oC burner shuts off.
  4. After 5 minutes, the pulse meter sensor sets the burn rate to 00.000 liters/minutes.
  5. An automation watches for the change to 00.00 l/m and triggers an action to subtract the total liters from the previous oil volume and then resets the total pulse count to zero so that the next furnace run records the volume of oil consumed only on that run.

The part I can’t get is the “resets total pulse count to zero”. ESPHome docs show the code below but I just can’t figure out where to put it and how to introduce the zero value

api:
   actions:
    - action: set_total
      variables:
        new_total: int
      then:
        - pulse_meter.set_total_pulses:
            id: sensor_pulse_meter
            value: !lambda 'return new_total;'

Current Yaml

substitutions:
  name: esphome-web-6e2e98
  friendly_name: D1mini10

esphome:
  name: ${name}
  friendly_name: ${friendly_name}
  min_version: 2024.6.0
  name_add_mac_suffix: false
  project:
    name: esphome.web
    version: dev

esp8266:
  board: esp01_1m

Enable logging
logger:

Enable Home Assistant API
api:
  encryption: 
    key: "kJNrzVLTn9tXlO45RbwtCP2gAKRstlcqHB4WFYeCVo4="
 
 Allow Over-The-Air updates
ota:
- platform: esphome

 Allow provisioning Wi-Fi via serial
improv_serial:

wifi:
   Set up a wifi access point
  ap: {}

 In combination with the `ap` this allows the user
 to provision wifi credentials to the device via WiFi AP.
captive_portal:

dashboard_import:
  package_import_url: github://esphome/example-configs/esphome-web/esp8266.yaml@main
  import_full_config: true

 To have a "next url" for improv serial
web_server:

sensor:
  - platform: pulse_meter
    name: 'Fuel Oil Useage'
    id: sensor_pulse_meter_fuel_oil # Optional ID, necessary if you want to calculate the total number of pulses.
    unit_of_measurement: 'L/min'
    device_class: volume_flow_rate
    state_class: measurement
    internal_filter: 100ms # Assuming maximum load of 16 kW and 10000 impulses per kWh, any pulses faster than 22.5 ms would exceed load. -10% ~= 20 ms.
    accuracy_decimals: 3
    pin: GPIO13
    filters:
      - lambda: return (float) x * 7.2985/1000.00 ;
    total:
      name: "Total Liters"
      filters: 
        - lambda: return (float) x * 7.2985/1000.00;
      accuracy_decimals: 3
      unit_of_measurement: 'L'```

You need to put the code from the docs under the api: key in your yaml. After flashing the config you should be able to call the action from an automation in HA.

api:
  encryption: 
    key: "kJNrzVLTn9tXlO45RbwtCP2gAKRstlcqHB4WFYeCVo4="
  actions:
    - action: set_total
      variables:
        new_total: int
      then:
        - pulse_meter.set_total_pulses:
            id: sensor_pulse_meter_fuel_oil
            value: !lambda 'return new_total;'

But, as you just need to reset the pulse count, and not set it to a specific value, it would probable be easier just to create a button in ESPHome and call button.press in HA.

button:
  - platform: template
    name: "Reset Pulse Meter Fuel Oil"
    on_press:
      - pulse_meter.set_total_pulses:
          id: sensor_pulse_meter_fuel_oil          
          value: 0

zenzay42
Thanks for your quick reply. I did the “API” thing already and got an error message when I updated …I’ll try it again and double-check the indents. Also interesting on the your button suggestion. I assumed that since it is a sensor that you cannot update the value directly. i,e, you had to use the action that was specified in the esphome docs. I’ll also give that a try later today and post the results. Thanks again

Yeah, indentation matters a great deal in yaml.

And yes, you’ll have to use the set_total_pulses action to make it work. Whether that’s via an Action in HA or by creating a Button, doesn’t really matter. I just feel the button is easier when all you want to do is to reset the pulse count.

Zenzay,
I added the lines to the api: block as you suggested and the yaml uploaded to the device just fine. But when I went to add the button the action(service) is not available to add. I cannot figure out how to call it. Thanks for your help.

First off; you don’t need both the api: action and the button. If you got the api: action working you can just use that.

Add an action in HA to the automation, you have created to watch for the change to 00.00 l/m. Select Other Action at the bottom, select ESPHome and then you should be able to see the action in a listbox.

If you want to add the button you can just copy the template from above and add it to your yaml somewhere. To press the button in HA, add an action and select Button->Press->Choose entity and then find the button in the dropdown list.

zenzay
Thank you so much! I had no idea that I could pick up the action under Other/ESPHome. I would never have found it on my own. I need this to work in an automation because I want it to zero out after the furnace burner cycles on so that I can track the fuel used during the next burn.

Many thanks again…

1 Like