Calculating Generator Fuel Tank Level

I’m trying to set a Fuel Tank Gauge so I can see (approximately) what my fuel tank level is at.

All I get via Modbus is the power usage of my fuel generator but I have created a binary sensor that determines if the generator is on or off (as that is more useful than the power which is always the same).

I have used the utility meter to calculate generator usage for daily, weekly and monthly which is useful. But now I want to calculate how much fuel is left based on knowing the capacity of the fuel tank is 13.3L and I also know the rate of fuel usage is 2.5L/hr.

If I create a sensor that calculates L used with hours of generator usage x rate of usage I get a daily rate. I need to reset the generator hours of usage to a sensor that I can trigger to indicate the fuel tank has been refilled. I can’t quite figure out how to do this.

I do almost exactly the same thing.

I’ve wired a door sensor to a relay which is powered from the oil fired burner on my home heating system’s boiler. Basically I get an on/off state change every time the burner fires.

From that I can use a history_stats sensor to keep track of how long the boiler has been running so far today:

  - platform: history_stats
    name: Burner on today
    entity_id: binary_sensor.visonic_mct_340_e_0b1243b6_1_1280
    state: 'on'
    type: time
    start: '{{ now().replace(hour=0).replace(minute=0).replace(second=0) }}'
    end: '{{ now() }}'

I’ve also defined one which indicates how long the burner ran yesterday:

  - platform: history_stats
    name: Burner on yesterday
    entity_id: binary_sensor.visonic_mct_340_e_0b1243b6_1_1280
    state: 'on'
    type: time
    end: '{{ now().replace(hour=0).replace(minute=0).replace(second=0) }}'
    duration:
      hours: 24

Like you, I can estimate fuel burn based on total hours run-time. The burner is calibrated to burn about 1 gallon per hour, but in practice it seems to be closer to 0.98 GPH. Each morning, I run an automation to append yesterday’s run time to a text file, as well as populate an input number. The automation is a little long, because I trigger it a few times in case HA wasn’t running the first time (probably overkill.)

- id: id_burner_summary
  alias: Burner Summary
  trigger:
  - platform: time
    at: 01:00:00
  - platform: time
    at: 02:00:00
  - platform: time
    at: '14:00:00'
  - platform: time
    at: '22:00:00'
  condition:
  - condition: template
    value_template: '{{ now().strftime(''%x'') != as_timestamp(states.automation.burner_summary.attributes.last_triggered)
      | timestamp_custom(''%D'') }}'
  action:
  - service: notify.burner_summary
    data_template:
      message: '{{ now().strftime(''%x'') }},{{ states.sensor.burner_on_yesterday.state
        }}'
  - service: input_number.set_value
    target:
      entity_id: input_number.oil_tank_remaining
    data_template:
      value: '{{ (states("input_number.oil_tank_remaining") | float) - (states("sensor.burner_on_yesterday")
        | float * 0.98) }}'
  mode: single

The oil_tank_remaining value is defined as:

input_number:
  oil_tank_remaining:
    name: "Oil Remaining"
    min: 0
    max: 275
    step: 0.1
    mode: box
    unit_of_measurement: 'Gallons'

I display this value in a gauge in Lovelace, and I also use it to populate a “percent” value, but this post is already getting long so I’ll stop here.

Thanks so much Tom. There is a lot here so I’ll let you know when I have given it a good read and tried to implement into my own set-up.

How do you reset the tank remaining when you have refilled it?

Sorry for the delay, I was out of town. It seems like a lot to digest all at once, but take one piece at a time. If I could figure it out, anyone could.

I created an Entities card in Lovelace with the entity “input_number.oil_tank_remaining.”

I just over-type it when needed. Not only when there’s a fuel delivery, but ny sensor has been sticking “on” occasionally, so it thinks the burner ran for an hour or two, instead of just a few minutes. I’ve got a plan to fix that before the heating season starts, but meanwhile I just go in and add an extra gallon or two “remaining.”
image