With the release of Home Assistant Core 2021.8, a new feature called Home Energy Management was added to Home Assistant. This provides a nice dashboard where you can track the energy consumption of your house.
I have been interested in capturing my energy consumption data for a while now and have documented my use of an energy consumption meter before. That project was abandoned in due course because I didn't spend any time in building a nice dashboard.
Since then, my electricity and gas meter has also been upgraded to a smart meter and I can read the energy consumption on my energy provider, Octopus energy's website. The data is however delayed by a day. It is possible to obtain the latest energy consumption data but it involves third party access to your energy consumption data which I wasn't very keen on. So I have been thinking of capturing the electricity consumption data in some manner and decided to use the energy consumption meter clamp and my RTL-SDR usb dongle.
The post documents my setup.
My Energy Consumption Dashboard |
Hardware used:
1) Efergy Elite Classic:
I just use the transmitter. The clamp goes onto the live wire feeding into the energy meter. The device sends the current flowing through the wire in A every few seconds over the 433.55 MHz frequency.
2) RTL-SDR Realtek RTL2832U + R820T tuner receiver dongle
The RTL=SDR dongle allows us to capture the data being sent over 433.55 MHz frequency.
The dongle is connected to a Raspberry-Pi and is continuously listening to data being sent by the transmitter. To do this, I used the tool rtl_433 available on github. This is run on a screen session on the raspberry pi.
rtl_433 -f 433550000 -R36 -Fmqtt://192.168.1.10:1883,user=mqtt,pass=mqtt
- The arg -f 433550000 is used to set the frequency to listen on.
- The arg -R36 sets the decoder to use. This is specific to this transmitter.
- -Fmqtt://192.168.1.6:1883,user=mqtt,pass=mqtt sets the mqtt server to send the data on.
The command captures the data and send the current consumption in Amperes to the mqtt server which is also my Home Asssitant server.
The next steps are all on my Home Assistant Server.
I have split my home assistant configuration file so that the sensors configurations is tracked in a separate file. Similarly, I have also split up the configuration for the new Utility Meter integration. I do this by having the following configuration in the configuration.yaml file.
sensor: !include sensor.yaml
utility_meter: !include utility_meter.yaml
As my first step, I need to create a sensor based on mqtt to read the incoming data in Amperes sent by the rtl_433 tool over mqtt and convert it into Watts for further consumption my homeassistant. My sensor.yaml file contains the following block.
- platform: mqtt
name: "Home Electricity Watts"
state_topic: "rtl_433/pi-hole/devices/Efergy-e2CT/42173/current"
unit_of_measurement: "W"
value_template: "{{ value | round(2) * 240 }}"
device_class: energy
I also use value_template to multiply the current(I Amps) with the household voltage in the UK(240V) to obtain the energy consumption in Watts. This is exposed on the device sensor.home_electricity_watts.
However this value is just the value of power consumed at that specific time in Watts. To obtain the energy used in kW-hr, we need to multiply the power value with the timeperiod over which it was measured. The kWhr values for each time period need to be summed up to obtain the energy consumption over an hour. We do this using the Integration - Riemann sum integral. in my sensors.yaml file, I have the following yaml block which does this.
- platform: integrationThis block instructs Home Assistant to read data from sensor.home_electricity_watts and use the iteration function to obtain the energy consumption in kWhr. This is then exposed through the device sensor.home_electricity_kWh.
name: home_electricity_kWh
source: sensor.home_electricity_watts
round: 3
method: left
unit_prefix: k
Now we are ready to create a utility meter device. These for me are defined in utility_meter.yaml.
daily_electricity:name: "Daily Electricity Usage"
source: sensor.home_electricity_kWh
cycle: daily
tariffs:
- peak
- offpeak
weekly_electricity:
name: "Weekly Electricity Usage"
source: sensor.home_electricity_kWh
cycle: weekly
tariffs:
- peak
- offpeak
monthly_electricity:
name: "Monthly Electricity Usage"
source: sensor.home_electricity_kWh
cycle: monthly
tariffs:
- peak
- offpeak
Since I use the Octopus Go tariff with Octopus energy, I have two different tariff rates depending on the time of the day. I name these tariffs as peak and offpeak. The tariff costs are set in the energy dashboard. These create multiple devices based on the utlity_meter name and tariff. The ones we are interested in are sensor.daily_electricity_peak and sensor.daily_electricity_offpeak.
To add these utility meters to the energy dashboard. Go to Configuration->Energy. Click on Add Consumption. Select "daily_electricity peak", select "Use a static price" and enter your tariff for peak consumption. For Octopus energy go, I pay 0.1533 GBP/kWh. Similarly, add the consumption for the offpeak periods with it's own tariff(0.05 GBP/kWh).
I have also added individual devices to track their energy consumption. This is done using Wifi smart power plugs which also capture energy consumption.
To complete setup, we need to setup automation to select the right tariff. Unlike the examples given on the Home Assistant page, I use two separate automations. These are
alias: 'Energy: Switch Electricity Tariff - peak'and
description: ''
trigger:
- platform: time
at: '04:30:00'
condition: []
action:
- service: utility_meter.select_tariff
target:
entity_id: utility_meter.daily_electricity
data:
tariff: peak
- service: utility_meter.select_tariff
target:
entity_id: utility_meter.weekly_electricity
data:
tariff: peak
- service: utility_meter.select_tariff
data:
tariff: peak
target:
entity_id: utility_meter.monthly_electricity
mode: single
alias: 'Energy: Switch Electricity Tariff - offpeak'
trigger:
- platform: time
at: '00:30:00'
action:
- service: utility_meter.select_tariff
target:
entity_id: utility_meter.daily_electricity
data:
tariff: offpeak
- service: utility_meter.select_tariff
target:
entity_id: utility_meter.weekly_electricity
data:
tariff: offpeak
- service: utility_meter.select_tariff
data:
tariff: offpeak
target:
entity_id: utility_meter.monthly_electricity
mode: single
- sensor.daily_electricity_peak - Consumption in peak hours
- sensor.daily_electricity_offpeak - Consumption in offpeak hours
- sensor.daily_electricity_peak_cost - Costs during peak hours
- sensor.daily_electricity_offpeak_cost - Costs for offpeak hours.
You may have to let the system run for a whole cycle before all these devices are visible.
And finally, you can also add a card to my dashboard to track daily electricity costs.
This is specified by the following yaml block.
type: entities
entities:
- entity: sensor.home_electricity_watts
name: Current Consumption
- entity: sensor.daily_electricity_costs
name: Daily Cost
- entity: sensor.daily_electricity_peak
name: Peak Consumption
- entity: sensor.daily_electricity_peak_cost
name: Peak Cost
- entity: sensor.daily_electricity_offpeak
name: Offpeak Consumption
- entity: sensor.daily_electricity_offpeak_cost
name: Offpeak Cost
title: Daily Electricity Costs
The device sensor.daily_electricity_costs is defined by me in my sensor.yaml file with the following entry
- platform: template
sensors:
daily_electricity_costs:
friendly_name: "Energy Costs"
unit_of_measurement: ".."
value_template: "{{ (states('sensor.daily_electricity_peak') | float * 0.1533 + states('sensor.daily_electricity_offpeak') | float * 0.05) | round(2) }}"