# how much oil / electricity do I use in a day – Home Assistant or espHome

The measurements that I take around the home provide two things:

– a picture of a moment in time – a room temperature for example.

– how something changes over the course of a day – the electricity use graph below.

But sometimes I want a bigger picture. For example, I also want to know how much electricity I use each day and see how my use of electricity changes over time. It’s useful because if I know say, how much heating oil I use in a day then I can work out when I must order more fuel. I’m also a bit curious to know how all sorts of things, like how the length of a day changes over the season.

This page shows how to get Home Assistant to do the maths and display these measurements.

#### How much electricity do I use in a day?

The ‘power meter’ graph above summarises my electricity meter readings which are taken every few seconds. (You might notice a high reading in the night when my 2kW heater turns on. And there are spikes showing when an electric kettle is boiled or the oven turned on).

To know how much electricity I use in a day I need to add up all these readings and convert them to kW/day. This need is met by the ‘Utility Meter‘ feature built-into Home Assistant. It automatically sums your energy use and resets the figure each midnight. If you wanted a monthly or weekly reset, repeat the entry in configuration.yaml as follows:

```# Edit Home Assistant configuration.yaml
utility_meter:
power_today:
source: sensor_power_meter
cycle: daily
power_weekly:
source: sensor_power_meter
cycle: weekly

(I also use a Sonoff POW running ESPHome for metering so I can alternatively do the same calculation with the ESP software - as below)

******
# in ESPHome you can use the built-in platform called Total daily energy.
sensor:
platform: total_daily_energy
name: power_today
power_id: sensor_power_meter
unit_of_measurement: kWh
accuracy_decimals: 0
filters:
# Multiplication factor from W to kW is 0.001
multiply: 0.001
# To get this figure in £ or \$ change the multiplier and the unit.```

#### Immersion water heater daily usage

The household hot water here is heated by an immersion heater in a tank – it makes use of cheaper electricity on a ‘night rate’. The power to this is controlled by a Sonoff POW2 customised with ESPHome which, as well as set a heating schedule, allows me to ensure that the power is cut as soon as the water is up to temperature.

The need to measure total daily power is met by the ‘Utility Meter’ feature built-into Home Assistant. If you wanted the espHome chip to do the work, add the second example text to the espHome config.

```# Edit Home Assistant configuration.yaml
utility_meter:
water_heater_power_today:
source: sensor.water_heater_power_now
cycle: daily
******
# Alternatively in ESPHome I use a built-in platform called Total daily energy.
sensor:
platform: total_daily_energy
name: "water heater power today"
power_id: water_heater_power_now
accuracy_decimals: 0
filters:
`    # Multiplication factor from W to kW is 0.001`
- multiply: 0.001
`unit_of_measurement: kWh  ````

#### How much heating oil do I use in a day?

Heating oil is a fuel similar to diesel and it is kept in a tank which needs refilling three or four times a year. I made and fitted a sensor that records the level of oil in the tank. The output is shown in a graph at the top of this page. This example is different in that we aren’t trying to sum a day’s worth of readings. Instead, we want to know how much the oil level has changed in a day – so once a day at midnight we get Home Assistant to store the oil level reading in a variable called an input_number. (Read on to see how challenging it is to do something so simple).

First set up the variable ‘midnight oil level’:

```# Edit Home Assistant configuration.yaml and add this text to create a variable to store the oil level at midnight.
input_number:
midnight_oil_level:
name: midnight oil level
min: -1000
max: 1000
unit_of_measurement: L
icon: mdi:oil-level```

Next we need a routine (aka automation) that checks the sensor oil level at midnight and stores it in the variable created above. An automation is a plain text file saved in the ‘automations’ folder in Home Assistant. It was not possible for me to create this using the Home Assistant automation tool.

``` id: '6666666'
alias: OIL - read oil level at midnight and store it in the variable
trigger:
platform: time
at: '00:01:05'
action:
service: input_number.set_value
data_template:
entity_id: input_number.midnight_oil_level
value: "{{ states('sensor.oil_level') }}"
```

We now have managed to store yesterday’s oil level. The final step is to create a calculated sensor, called a template sensor which subtracts midnight’s oil level from the current oil level. The syntax of the thing, which features a JSON object, is conspicuously horrid.

```# Edit Home Assistant configuration.yaml and add this 'template sensor' text:
sensor:
-   platform: template
sensors:
`    oil_used_perday:     `
`value_template: >     `
`{{ states('sensor.oil_level') | int  -     states('input_number.midnight_oil_level') | int }}     `
`unit_of_measurement: 'L'     `
`friendly_name: "oil used perday"       `
`icon_template: mdi:oil-level````

#### How is it possible to record the amount of water pumped in day?

This question is answered on the Home Assistant Community pages. The solution involves fitting the pipework with inexpensive brass flow meters. The solution stores yesterday’s pumping score in a variable as in the oil level example above. Go search for that if you have this need.

## how does the weather (temperature) affect my use of heating oil / fuel?

Look at this graph of four years recording the daily temperature and the amount of oil used. The line is a trend line to show that there is some relationship. This experiment involving hundreds of daily readings has inaccuracies and is almost impossible to do well. For example,

You might question if one single daily temperature from the weather service reflects how cold it is in the house. And we certainly haven’t set the heating thermostat to the same figure each day – some days we turned it up because we felt cold and used more oil and some days the heating was on for more hours. A tricky experiment, but a nice try at one eh?

### 3 Responses

1. Aps says:

May be it’s an useful link to inspire how to analyze usage data: