Monitoring oil consumption with a binary sensor - help needed

I need your help (attention beginner :slight_smile:
I have a binary sensor that has the status “on” when the burner of my heating is on.
I also know that the burner needs 1.6 liters of oil per hour.
I would now like to build a utility meter that displays my oil consumption.
That sounds easy but I don’t know where to start :slight_smile:

Thanks in advance
Thomas

Create a History Stats sensor to report the current day’s total time the burner is running.

  - platform: history_stats
    name: Burner Time Today
    entity_id: binary_sensor.burner
    state: "on"
    type: time
    start: "{{ today_at() }}"
    end: "{{ now() }}"

Create a Template Sensor to compute oil consumption based on today’s burner time.

template:
  - sensor:
      - name: Oil Consumption Today 
        state: "{{ states('sensor.burner_time_today') | float(0) * 1.6 }}"

Create Utility Meter sensors to report long-term daily, monthly, and yearly measurements.

utility_meter:
  oil_consumption_daily:
    source: sensor.oil_consumption_today
    cycle: daily
  oil_consumption_monthly:
    source: sensor.oil_consumption_today
    cycle: monthly
  oil_consumption_yearly:
    source: sensor.oil_consumption_today
    cycle: yearly
2 Likes

Oh wow Taras that was fast.
Now its written down it looks easy and logical :slight_smile:
Thanks a lot

If you have a multizone system and smart thermostats you can allocate the gallon to different zones. I can post the package if that’s your next step. In this chart furnace burner is the total oil burned (Taras code will give you that), the other 4 are the 3 zones plus domestic hot water.

Hi Perter cool that sounds very sophisticated but I don not have the according sensors.
I added a weekly counter now I should have a good overview about my consumption an the remaining Oil in my storage.
If I could like to see the consumption in the Energy dashboard I would have to show this as Gas consumption right?
Like that:

  • sensor:
    • name: Oil Consumption Today
      state: “{{ states(‘sensor.burner_time_today’) | float(0) * 1.6 }}”
      unit_of_measurement: m³
      state_class: total_increasing
      device_class: gas

Right?
hmm seems not to work “statistics not found”

Hi,

That looks cool, didn’t think of this option.
I have Evohome, and I can see the open% of each thermostat, is that possible with your code?

ah ok it’s working took some time.
Ok numers might be very smal lets see how it works out.
btw how woud I round the output to 1 decimal?
state: “{{ states(‘sensor.burner_time_today’) | float(0) * 1.6 }}”

(Existing-expression) | round(1)

Here’s the package I use for my furnace burner. Instead of using the stats sensor, I use the integration sensor, this updates in real-time as the furnace turns off. Replace the 0.65 with whatever your nozzles GPH is. And replace the binary sensor that indicates if the furnace is running with your current sensor.


homeassistant:
  customize:
    sensor.furnace_burner_oil_usage:
      unit_of_measurement: G

sensor:
  - platform: template
    sensors:
      furnace_burner_gallons_per_hour:
        unit_of_measurement: G
        value_template: >-
          {% if is_state('binary_sensor.furnace_burner_running','on') -%}
          0.65
          {%- else -%}
          0.0
          {%- endif %}
      furnace_burner_total_oil_yesterday:
        value_template: >-
          {{ state_attr('sensor.furnace_burner_oil_today_running','last_period') }}
        unit_of_measurement: G
      furnace_burner_total_oil_week:
        value_template: >-
          {{ state_attr('sensor.furnace_burner_oil_weekly_running','last_period') }}
        unit_of_measurement: G
      furnace_burner_total_oil_month:
        value_template: >-
          {{ state_attr('sensor.furnace_burner_oil_monthly_running','last_period') }}
        unit_of_measurement: G

  - platform: integration
    source: sensor.furnace_burner_gallons_per_hour
    name: furnace_burner_oil_usage
    unit_time: h
    method: left
    round: 2

utility_meter:
  furnace_burner_oil_today_running:
    source: sensor.furnace_burner_oil_usage
    cycle: daily
  furnace_burner_oil_weekly_running:
    source: sensor.furnace_burner_oil_usage
    cycle: weekly
  furnace_burner_oil_monthly_running:
    source: sensor.furnace_burner_oil_usage
    cycle: monthly

recorder:
  include:
    entities:
      - sensor.furnace_burner_energy_today_running
      - sensor.furnace_burner_oil_today_running
      - sensor.furnace_burner_oil_weekly_running
      - sensor.furnace_burner_oil_monthly_running
      - sensor.furnace_burner_total_oil_yesterday
      - sensor.furnace_burner_total_oil_week
      - sensor.furnace_burner_total_oil_month
      - sensor.furnace_burner_oil_usage
      - sensor.furnace_burner_gallons_per_hour
  • The example I posted for the Template Sensor is in modern format.

  • The example you posted for the Template Sensor is in legacy format.

Is there a reason why you didn’t use modern format? Legacy format doesn’t support new features that are available in modern format (like specifying state_class in its configuration).

For that matter, is there a reason why you want to add state_class to the Template Sensor? The daily Utility Meter sensor will provide long-term daily statistics.

Hi all,
I’m struggling to get the Oil Consumption sensor that Taras @123 posted to work, almost certainly something stupid I’ve done or missed but hoping that someone can point me in the right direction. I’ve screenshot everything I can think of and copied to DropBox as view only;(https://www.dropbox.com/scl/fo/sjgjlu1vt1atwav28slfx/h?rlkey=5ru9rw4hu8zktsg3ubqkorujd&dl=0)
and tried to extract everything below as text. I think the issue is in the Burner_Time_Today sensor as that doesn’t increment even though the Shelly input shows the state change.
If anyone can spot what I’m doing wrong please let me know as I’m going around in circles here!
Thanks,
Colin

Burner relay, Shelly Plusi4
Input 4 used for the oil burner; “Burner_pump”
Input type setting; Switch
The Shelly sees the state change and is also picked up by HA which also reports the state change.

/config/configuration.yaml
‘’’
sensor:

Oil boiler burner ON time calculator

  • platform: history_stats
    name: Burner_Time_Today
    entity_id: binary_sensor.Burner_pump
    state: “on”
    type: time
    start: “{{ today_at() }}”
    end: “{{ now() }}”

Template
Name;
Oil consumption Today
Entity ID;
Sensor.oil_consumption_today
{{ states(‘sensor.Burner_pump’) | float(0) * 1.92 }}
This template listens for the following state changed events:
Entity: sensor.Burner_pump

Utility meter
Oil Consumption Daily
Entity ID:
sensor.oil_consumption_daily
Input sensor;
Burner_Time_Today
Periodically resetting enabled, 24hr
‘’’

How can I ‘import’ your package into my HA configuration? Do you have it as a formatted “blueprint”?
I’m a beginner…

[quote=“RobinE, post:12, topic:518306, full:true”]
Hi PeteRage:
How can I ‘import’ your package into my HA configuration? Do you have it as a formatted “blueprint”?
I have set up a binary_sensor to indicate my furnace running.
I’m a beginner…