Utility meter to oil tank level

Just getting started with HA, so apologies for any mistakes. I have a oil tank and boiler, and a three channel drayton wiser thermostat.

I know the flow rate for my boiler, so I want to measure the length of the time the boiler has been active to calcuate the amount of oil left in the tank.

I’ve setup a utility meter for each of the three zones to track the hours they have been on, I now need to use that data and multiple it by flow rate. Would anyone have suggestions on how to go about that?

Hi Fionn,

Welcome aboard!! I’m no expert on HA, but I have spent countless hours setting up my energy monitoring, mainly due to having an old ‘dumb’ gas meter where I had to make and test my own sensor to read the values.

As part of all this faff of setting up, I wanted to create a dashboard so I could see Daily Cost, Weekly Costs, etc. To do this I had to create what you would call “bespoke sensors” or “custom sensors”. These were not physical components to take readings from things but bits of YAML code that undertook calculations using the data from other sensors, as can be seen below.

  - sensor:
      - name: "Daily Gas Cost"
        unique_id: daily_gas_cost
        state: "{{ (((((states('sensor.gas_consumption_daily_v2')|float * 0.0283) * 1.02264) * 39.9) / 3.6) * 0.0621)|round(2) }}" #The 0.0621 is gas cost in £'s per kwh
        availability: "{{ states('sensor.gas_consumption_daily_v2')|is_number }}" 
        unit_of_measurement: "£"
        device_class: monetary
        state_class: total
  
      - name: "Weekly Gas Consumption kWh"
        unique_id: weekly_gas_usage_kwh
        state: "{{ ((((states('sensor.gas_consumption_weekly_v2')|float * 0.0283) * 1.02264) * 39.9) / 3.6)|round(2) }}"
        availability: "{{ states('sensor.gas_consumption_weekly_v2')|is_number }}" 
        unit_of_measurement: "kWh"
        device_class: energy
        state_class: total

      - name: "Weekly Gas Cost"
        unique_id: weekly_gas_cost
        state: "{{ (((((states('sensor.gas_consumption_weekly_v2')|float * 0.0283) * 1.02264) * 39.9) / 3.6) * 0.0621)|round(2) }}" #The 0.0621 is gas cost in £'s per kwh
        availability: "{{ states('sensor.gas_consumption_weekly_v2')|is_number }}" 
        unit_of_measurement: "£"
        device_class: monetary
        state_class: total
type or paste code here

As you can see from the YAML above there are simple maths calculations taking place on Meter Helpers that I set up. On the last entry, named “Weekly Gas Cost”, it takes a Meter Helper I set up (sensor.gas_consumption_weekly_v2) to log that week’s gas consumption, and then uses all the relevant maths from my gas bill to convert the ft3 reading off the meter to a cost in £’s where it makes more sense.

You would have to create something similar to suit your setup, and use the three Meter Helpers you have already created, perhaps add them together, and then multiply by your oil flow rate. This should provide the total usage, according to whatever time-frequency (days, weeks, months) you set the Meter Helpers in.

In the YAML code noted above, the items such as Name: and unique_id: can be whatever you want, so use something that makes sense and is logical to you, but is different from something already created. I wouldn’t just cut and copy the code verbatim, but just use it as a basis to see how the formatting of YAML works - it is finicky if your lines are not indented properly (Admittedly, I am YAML Challenged BTW… :roll_eyes:)

You can create as many bespoke sensors as you want to report back costs, etc. These little bits of code are pasted into the main ‘configuration’ section within HA - see screenshot below of where I stuck mine.

I use a plugin called Studio Code Server to view these YAML files - may be available from HACS (I can’t remember now!)

I hope the above helps, and if you need any further help, just shout and I’ll do what I can to assist.

Cheers,

Mike.

I’ve done something very similar with my oil boiler. I also have three zones, and three thermostats.

But… The boiler run-time does not corollate with the times that each thermostat is calling for heat. For one thing, the boiler burner shuts off once it’s reached its high setpoint, regardless whether one or more thermostats are calling for heat. It also runs to keep the boiler above a minimum set point, even when no heat is needed, although yours may not do this. Finally, more than one zone could be calling for heat at the same time, so you wouldn’t want to just sum them all up or you’d get an inflated value.

Instead I have a relay powered by the same wire which powers the boiler burner. There are a number of ways to get this on/off signal back to HA. At first I used a door sensor from which I’d removed the reed switch and replaced it with a pair of wires to the relay contacts. Currently I run the wires to the GPIO pins of an ESP8266 board running ESPHome. I’ve found these methods give me a very good indication of fuel burned. This wouldn’t work with some of the newer boilers which have variable burn rates.

Thanks @Muddy_Boots and @CaptTom for your detailed replies!

I followed your advice @Muddy_Boots and implemented some new sensors, that VS code plugin is dead handy!

@CaptTom good points, regarding the multizone approach, I queired chatgpt and it outputed this as a solution

template:
  - sensor:
      - name: "Heating fuel used"
        unique_id: heating_fuel_used
        state: >
          {% set runtime_1 = states('sensor.utility_meter_long_term_living_room') | float(0) %}
          {% set runtime_2 = states('sensor.utility_meter_long_term_bedrooms') | float(0) %}
          {% set runtime_3 = states('sensor.utility_meter_long_term_hot_water') | float(0) %}

          {# Combine runtime, ensuring no double-counting #}
          {% set overlap = min(runtime_1, runtime_2) + min(runtime_2, runtime_3) + min(runtime_1, runtime_3) %}
          {% set total_runtime = runtime_1 + runtime_2 + runtime_3 - overlap %}

          {{ (total_runtime * 0.63) | round(2) }}

However, it doesn’t solve the problem that heating on doesn’t equal boiler on, which I forgot about. There some more dicussion here. Kingspan offer a sonic sensor for the oil tank, but it’s just a little pricey…

Right. If you’re looking to use this for a utility meter, you’ll want actual burner runtime.

As for oil tank monitoring, I built my own ultrasonic sensor for that. I used this sensor, and an ESP8266 board. Total cost under $30 for two sensors and three ESP boards. A couple of bucks more for a black plastic case to put them in. There’s a lot of information out there, both on this forum and elsewhere, on how to set these up in ESPHome, and I could share some of my notes if it would help you.

I still monitor the run-time of each zone, and of the boiler’s burner. And I kept my original entities to track fuel remaining based on burner run-time. Except when the tank is nearly full or nearly empty, they match the level sensor pretty closely.

I meant to document this all in a new thread one day, but never got around to finishing my write-up.

Thanks, I’ll look into that. If you did have notes, or any particiular resource that was helpful do let me know. I just need to find time now.

Yes, you need to know when the burner is running. I put a CT clamp around one of the 120vac wires that powers the furnace. Empirically I can tell if the burner is running when it’s using more than 60 watts of power.

Then a sensor that knows the number of zones calling for demand (e.g. the thermostats and hot water tank).

      house_hvac_zones_in_demand:
        value_template: >-
          {{
             is_state("sensor.bedroom_hvac_action","heating") | int
             + is_state("sensor.studio_hvac_action","heating") | int
             + is_state("sensor.living_room_hvac_action","heating") | int
             + is_state("sensor.water_heater_hvac_action","heating") | int
          }}
      house_hvac_zone_oil_gph:
        value_template: >-
          {%- if states("sensor.house_hvac_zones_in_demand") | int == 0 %}
          0
          {%- else %}
          {{ 0.65 / states('sensor.house_hvac_zones_in_demand')|float }}
          {%- endif %}

Then create a sensor for each zone (current oil usage), when the burner is running and the zone is on, the value is the furnace nozzles GPH / # of active zones, else it’s zero.

      bedroom_oil_usage_gph:
        value_template: '{{ iif(is_state("sensor.bedroom_hvac_action","heating"), states("sensor.house_hvac_zone_oil_gph"), 0.0)  }}'

      bedroom_heat_gallons_per_hour:
        unit_of_measurement: gph
        value_template: >-
          {% if is_state('binary_sensor.furnace_burner_running','on') -%}
          {{ states("sensor.bedroom_oil_usage_gph") }}
          {%- else -%}
          0.0
          {%- endif %}

Then put a reimann sum on each one of those.

And then finally feed a utility meter.

You’ll also discover that the burner runs occasionally when there is no heat demand. So I created another meter to track this allocation.

I would agree with @CaptTom and @PeteRage on here that you would be better monitoring the actual burn time of your boiler to provide for greater accuracy. As you say Kingspan do make a sensor, but it is pricey, however, you can actually knock one up yourself for very little cost that can integrate with Home Assistant using Wifi.

I tend to use ESP32 Mini boards for my own DIY sensors (just bought 5 off AliExp for about two quid each - they run off a 5V USB plug and are pretty easy to set up and integrate into Home Assistant using ESPHome.

There are multiple ways of monitoring your boiler burn time - as @PeteRage says, you could fit a CT clamp around the solenoid live feed that actuates the burner valve (see this) - the code you would write into the ESP32 would pick up the induced signal and record the time it was ‘high’. Another way would be to use a light sensor - it would register when the flame is lit and start to log the time the burner was active for. A thermocouple could also do the same thing, but probably not as accurately - it all depends upon accessibility and ease of siting within the boiler itself. When you start to consider DIY sensors, the limit is your own imagination really. There are so many different DIY sensors, and this community is superb for providing assistance - whatever you are considering, it has most likely been done by someone else previously - just searching out the relevant post and thread is the hard part!

If you are going to go down the DIY ESP32 / ESP8266 route, just shout and I’m more than happy to help if you need it (I’m just in the process of making my own presence, temp, humidity, lux level, air quality multi-sensors for each habitable room in the house. Have it working on the bench,just need the parts for the others to arrive! :roll_eyes:)

Cheers,

Mike.

Good summary @Muddy_Boots!

Just to confuse things, I’ll add yet another option. There’s already a mains voltage power cable going to the oil burner of the boiler. I just ran a cable from that to a relay (contactor.) When the burner is powered, the relay closes. Two contacts on this relay are connected to the GPIO pins on an ESP8266. An ESP32 would work fine too, but for this simple task the older, less capable 8266 is already overkill.

I found this simpler than using a CT clamp, since it’s just a few lines of YAML and results in a clean on/off binary signal. The circuit is simpler, too. Both methods work, just pick whichever matches your own skill set and whatever hardware you have lying around.

2 Likes

Wiring a relay in parallel or using a CT clamp on the 24vac burner signal wire or 120 vac power are both good solutions as they are non invasive. Which means you have low risk of the measurement sensor causing the furnace to fail. The CT clamp approach is the least invasive since it won’t even be attached to the furnace circuit. Whatever you do, do it right, follow electric code and double check it - or know it’s beyond your ability and hire an electrician / hvac guy)

An example of an invasive approach would be to wire a smart switch on the 120vac line and use its current sensing, as when the smart fails there will be no heat.

The ultimate solution would be sensing on the 24vac signal line and the 120vac power line as this would allow detection of a request to run the burner and the burner failing to ignite which is a primary failure mode of an oil based furnace. This may also allow early detection as sometimes the burner may turn on then off (because flame sensor is a little flakey) and then succeed on its next try. Guess I have my next project!

Some newer furnace controllers (like Lennox) make a ton of data available through WIFI. So if your upgrading take alot at their S40 controllers (I manage a fantastic integration for it)