Calculate oil boiler tank empty from burner usage

Hi Folks,

I’m fairly new to Home Assistant and also have very little experience of YAML or Python, so not a winning combination!

I have an oil boiler and I’m trying to work out how to set up a ‘time to empty’ calculation for the oil tank based upon the boiler run time. The boiler has a fixed oil flow when running so the flow is easy to calculate from the running time, which is measured from a binary sensor.
.
The calculation would be along the lines of;

Oil_Remaining_Volume = Oil_Starting_Volume - Oil_Consumed_Sum

Oil_Predicted_Empty = Oil_Remaining_Volume / Oil_7day_Average

I’ve created the following helpers;

Number entity, to input the Oil_Starting_Volume and allow easy reset after the tank is filled.

Template - Oil_Consumed_Today, based upon a relay measuring the boiler run time * oil flow rate

Date entity, to input the Oil_Fill_Date, planned to use to sum the individual Oil_Consumed_Today values between the Oil_Fill_Date and @now

I thought the statistics sensor package would work for calculating the Oil_Consumed_Sum since Oil_Fill_Date and to also calculate the Oil_7day_Average values but can’t get the statistics to work. Tried various combinations, none of which seem to get me anywhere.

Perhaps something like;

sensor:

  • platform: statistics
    name: “Oil_Consumed_Sum”
    entity_id: sensor.Oil_Consumed_Today
    state_characteristic: mean
    max_age:
    days: {{{ now() }} - “Oil_Fill_Date”}

sensor:

  • platform: statistics
    name: “Oil_7day_Average”
    entity_id: sensor.Oil_Consumed_Today
    state_characteristic: mean
    max_age:
    days: {{{ now() }} - xxxxxx} I can’t work out how to subtract ‘x’ days from the now() value.

Any thoughts or help greatly appreciated.
Thanks.