I get asked this a lot, so thought I’d create a quick HOWTO on how to create a multi-tariff energy measurement system, for the dashboard etc. YMMV.
How to do multi-tariff power monitoring on Home Assistant. Assumes that you have some existing sensor that provides power consumption (W), or energy consumption (Wh).
- if your input sensor is only power (W) you convert it to energy (Wh) using an “Integration - Riemann sum integral” Helper from http://homeassistant.local:8123/config/helpers
- name = daily energy
- input sensor = sensor.import (or wherever you get your consumption W)
- integration method = left
- others as defaults
- use the new sensor that this creates (in Wh) for all the future steps
-
Create Number helpers for each tariff/rate at http://homeassistant.local:8123/config/helpers and set them to real values
- input_number.electricity_peak_rate
- input_number.electricity_offpeak_rate
-
create a template sensor that picks the right tariff (as a string) based on the logic that your location uses. Make sure it only outputs the tariffs you defined above.
eg (I have two separate tariff - one for import, one for export)
template: - sensor: # peak time is 3pm-9pm every day - name: "Electricity Tariff" unique_id: 230e307a-6150-4c2e-8571-7634dec8fcd9 state: "{{ 'peak' if today_at('15:00') < now() < today_at('21:00') else 'offpeak' }}" # Time Of Use (TOU) – Local time Feed-In rates # Peak (4pm – 9pm) # Sholder (9pm – 10am) & (2pm-4pm) # Off-Peak (10am-2pm) - name: "Electricity Export Tariff" unique_id: 541d7af3-7518-42b4-ad78-7fba858c7770 state: "{{ 'peak' if today_at('16:00') < now() < today_at('21:00') else ('offpeak' if today_at('10:00') < now() < today_at('14:00') else 'shoulder') }}"
-
in order to create the multiple sensors that apply your tariffs, use utility meter helper
- create a utility_meter at http://homeassistant.local:8123/config/helpers
- call it something like “daily energy”
- input sensor = your Wh sensor
- meter reset cycle = daily
- supported tariffs = add each of the tariffs you created in step 3 (as labels)
- this will create a “base” sensor (which controls which tariff is currently in use), and one sensor for each tariff (which counts the amount of energy used on each tariff)
-
now, you need a bit of automation to change the utility meter selection (from step 3) whenever the current tariff changes (from step 2)
- create an new/empty automation at http://homeassistant.local:8123/config/automation/dashboard
- the trigger is “When Electricity Tariff changes state or any attributes”
- type=state
- entity=the sensor you created in step 3
- the action is to set the current tariff into the (first) sensor created by the utility meter
- type = call service
- service = select: select
- target = (entity) the first sensor you created in step 5
- option = “{{ trigger.to_state.state if ‘to_state’ in trigger else ‘offpeak’ }}”
you can also create this in YAML mode:
alias: Set Electricity Tariff
trigger:
- platform: state
entity_id: sensor.electricity_tariff
not_to:
- unavailable
- unknown
action:
- service: select.select_option
target:
entity_id: select.daily_energy
data:
option: "{{ trigger.to_state.state if 'to_state' in trigger else 'offpeak' }}"
mode: single
- Now you have two energy sensors, which accumulate during the day, depending on which tariff you are currently in. You can add them into your energy dashboard individually (so you can get accurate pricing, and different colours)
When you add the utility_meter (say peak) to the energy dashboard, you pick the usage sensor (A) and you also configure a pricing sensor (B). Make sure you align peak-usage with peak-price, offpeak-usage with offpeak-price, etc
Afterwards, your energy dashboard should look something like this.
And the graphs on the Energy Dashboard should show multiple shades of the blue (import) or purple (export) as configured