The Utility Meter integration is used to measure accumulating values like energy, gas, water, heating and more.
You can apply a cycle to make it reset whenever you want. So, for example, you can make a daily energy meter from a sensor that always increases.
You can also use the tariffs option to create multiple conditional sensors from the one utility meter.
Every tariff you define gets its own sensor and you can automate when that sensor starts accumulating.
This is a powerful tool allowing you to track things like peak and off-peak energy use, or water used when a particular device is on. Or which member of your house uses the most energy on a particular day for washing.
For example, lets say you have a binary sensor that tells you if your energy is being charged at peak or offpeak rates, binary_sensor.peak_rate
and you would like to track both off-peak and peak daily energy use separately, but you only have the one energy import sensor that never resets, sensor.energy_import
.
1) Define a daily cycle utility meter with two tariffs:
configuration.yaml, or via the Helpers UI
utility_meter:
energy_from_grid_daily:
source: sensor.energy_import
cycle: daily
tariffs:
- peak
- offpeak
This will create two sensors, sensor.energy_from_grid_daily_peak
and sensor.energy_from_grid_daily_offpeak
.
It will also create a select entity to allow you to choose between the two sensors, select.energy_from_grid_daily
. This select entity will have the two options, peak
and offpeak
. Whichever option is chosen starts the associated sensor accumulating.
2) Write an automation to choose which sensor gets to accumulate energy based on your binary sensor state:
automations.yaml, or using the UI automation editor
- id: 841ae395-4646-4c95-8991-14cdd7e9c834
alias: 'Set Peak or Off-peak Tarrif'
trigger:
- platform: state
entity_id: binary_sensor.peak_rate
not_to:
- unknown
- unavailable
action:
- if:
- condition: state
entity_id: binary_sensor.peak_rate
state: 'on'
then:
- service: select.select_option
target:
entity_id:
- select.energy_from_grid_daily
data:
option: 'peak'
else:
- service: select.select_option
target:
entity_id:
- select.energy_from_grid_daily
data:
option: 'offpeak'
A shorter way to do this with templates:
action:
- service: select.select_option
target:
entity_id:
- select.energy_from_grid_daily
data:
option: >
{{ 'peak' if is_state('binary_sensor.peak_rate','on') else 'offpeak }}