If you use 1kW of power for one hour, that is 1 kWh of energy.
You need to supply the utility meter with an energy sensor (kWh) not a power sensor (kW). Changing the unit is not enough.
Most smart plugs have a daily energy meter as well as instantaneous power sensors. You don’t need the utility meter for these. You already have the “daily energy consumed” in these sensors.
If your smart plugs have a continuous energy meter you can convert them to daily/monthly/weekly meters with the utility meter.
Example of two daily utility meters with two tariffs each made from my Shelly EM’s yearly energy meters:
utility_meter:
energy_t31_light_and_power:
source: sensor.shelly_t31_total_energy
cycle: daily
tariffs:
- day
- night
energy_t41_heating:
source: sensor.shelly_t41_total_energy
cycle: daily
tariffs:
- day
- night
At sunset and sunrise I change the tariffs to night and day respectively. I’m saving these daily values (along with a lot of other data) in a text file just before midnight. After a year I hope to have enough data to accurately size a solar power and battery (for night use) system.
#################################################################
## Theme Automation and energy tarrif setting
#################################################################
- id: set_dark_theme_at_sunset
alias: 'Set Dark Theme At Sunset'
initial_state: true
trigger:
platform: sun
event: sunset
action:
- service: input_select.select_option
data:
entity_id: input_select.select_theme
option: Night
- service: utility_meter.select_tariff
data:
entity_id:
- utility_meter.energy_t31_light_and_power
- utility_meter.energy_t41_heating
tariff: night
- id: set_light_theme_at_sunrise
alias: 'Set Light Theme At Sunrise'
initial_state: true
trigger:
platform: sun
event: sunrise
action:
- service: input_select.select_option
data:
entity_id: input_select.select_theme
option: Day
- service: utility_meter.select_tariff
data:
entity_id:
- utility_meter.energy_t31_light_and_power
- utility_meter.energy_t41_heating
tariff: day
- service: light.lifx_set_state # reset master bed lamp
entity_id: light.lifx_bedside_lamp
data:
brightness: 255
transition: 5
kelvin: 2700
#################################################################
## Mains Power Alerts
#################################################################
- id: daily_energy_use_message
alias: 'Daily Energy Use Message'
trigger:
platform: time
at: '23:59:50'
action:
- service: notify.telegram_general
data_template:
title: '*Information*'
message: "Today's energy use was {{ states('sensor.total_energy') }} kWh, which cost ${{states('sensor.total_cost_today')|float }}. Total energy cost since last reset on {{ states('input_datetime.last_reset') }} is ${{ (states('input_number.cumulative_energy_cost')|float + states('sensor.total_cost_today')|float)|round(2) }}"
- service: input_number.set_value
data_template:
entity_id: input_number.cumulative_energy_cost
value: "{{ states('input_number.cumulative_energy_cost')|float + states('sensor.total_cost_today')|float }}"
- service: notify.energy_log
data_template:
message: "{{ states('sensor.date') }},{{ states('sensor.energy_t31_light_and_power_day') }},{{ states('sensor.energy_t31_light_and_power_night') }},{{ states('sensor.energy_t31_light_and_power_total') }},{{ states('sensor.energy_t41_heating_day') }},{{ states('sensor.energy_t41_heating_night') }},{{ states('sensor.energy_t41_heating_total') }},{{ states('sensor.total_energy_day') }},{{ states('sensor.total_energy_night') }},{{ states('sensor.total_energy') }},{{ state_attr('sensor.power_stats','min_value') }},{{ state_attr('sensor.power_stats','max_value') }},{{ states('sensor.power_stats') }},{{ states('sensor.total_cost_today') }}"
Cumulative energy cost reset script:
reset_cumulative_cost:
sequence:
- service: input_number.set_value
data:
entity_id: input_number.cumulative_energy_cost
value: 0
- service: input_datetime.set_datetime
entity_id: input_datetime.last_reset
data_template:
date: "{{ as_timestamp(now())|timestamp_custom('%Y-%m-%d') }}"
Result:
The daily energy cost graph should be a mini-gragh-card bar graph but it has caching issues at the moment. So the line graph is there until it is fixed. The downward spikes are due to many recent Home Assistant restarts.
Individual smart meters give some data too but I don’t accumulate this. It is just for interest to see what is using the most energy and graphs of power throughout the day.
There are a whole bunch of template sensors used for the first view too:
#################################################################
## Shelly and power sensors
#################################################################
- platform: rest
name: Shelly EM Wifi
resource: http://10.1.1.24/status
username: !secret shelly_usr
password: !secret shelly_pwd
authentication: basic
value_template: '{{ value_json.wifi_sta.rssi }}'
scan_interval: 180
unit_of_measurement: dB
- platform: rest
name: Shelly T31 Total Energy # lights and power
resource: http://10.1.1.24/status
username: !secret shelly_usr
password: !secret shelly_pwd
authentication: basic
value_template: '{{ (value_json.emeters.0.total | float /1000)|round(3) }}' # Wh to kWh
scan_interval: 300 # no point updating faster than this. The Shelly only updates every 5 minutes
unit_of_measurement: kWh
- platform: rest
name: Shelly T41 Total Energy # heating and hot water
resource: http://10.1.1.24/status
username: !secret shelly_usr
password: !secret shelly_pwd
authentication: basic
value_template: '{{ (value_json.emeters.1.total | float /1000)|round(3) }}'
scan_interval: 300
unit_of_measurement: kWh
- platform: mqtt
name: "Tariff 31 Power"
state_topic: "shellies/shellyem-B9E940/emeter/0/power"
value_template: '{{ value|round(1) }}'
qos: 1
unit_of_measurement: "W"
icon: mdi:gauge
- platform: mqtt
name: "Tariff 41 Power"
state_topic: "shellies/shellyem-B9E940/emeter/1/power"
value_template: '{{ value|round(1) }}'
qos: 1
unit_of_measurement: "W"
icon: mdi:gauge
- platform: mqtt
name: "Mains Voltage"
state_topic: "shellies/shellyem-B9E940/emeter/0/voltage"
qos: 1
unit_of_measurement: "V"
icon: mdi:flash
- platform: template
sensors:
total_power:
friendly_name: 'Total Power'
entity_id:
- sensor.tariff_31_power
- sensor.tariff_41_power
value_template: "{{ (states('sensor.tariff_31_power')|float + states('sensor.tariff_41_power')|float)|round(1) }}"
unit_of_measurement: "W"
- platform: statistics
name: 'Power Stats'
entity_id: sensor.total_power
sampling_size: 50000
max_age:
hours: 24
precision: 1
- platform: template
sensors:
energy_t31_light_and_power_total:
friendly_name: 'Light and Power Total'
entity_id:
- sensor.energy_t31_light_and_power_day
- sensor.energy_t31_light_and_power_night
value_template: "{{ (states('sensor.energy_t31_light_and_power_day')|float + states('sensor.energy_t31_light_and_power_night')|float)|round(3) }}"
unit_of_measurement: "kWh"
- platform: template
sensors:
energy_t41_heating_total:
friendly_name: 'Heating and Hot Water Total'
entity_id:
- sensor.energy_t41_heating_day
- sensor.energy_t41_heating_night
value_template: "{{ (states('sensor.energy_t41_heating_day')|float + states('sensor.energy_t41_heating_night')|float)|round(3) }}"
unit_of_measurement: "kWh"
- platform: template
sensors:
total_energy_day:
friendly_name: 'Total Energy Day'
entity_id:
- sensor.energy_t31_light_and_power_day
- sensor.energy_t41_heating_day
value_template: "{{ (states('sensor.energy_t31_light_and_power_day')|float + states('sensor.energy_t41_heating_day')|float)|round(3) }}"
unit_of_measurement: "kWh"
- platform: template
sensors:
total_energy_night:
friendly_name: 'Total Energy Night'
entity_id:
- sensor.energy_t31_light_and_power_night
- sensor.energy_t41_heating_night
value_template: "{{ (states('sensor.energy_t31_light_and_power_night')|float + states('sensor.energy_t41_heating_night')|float)|round(3) }}"
unit_of_measurement: "kWh"
- platform: template
sensors:
total_energy:
friendly_name: 'Total Energy Used Today'
entity_id:
- sensor.total_energy_day
- sensor.total_energy_night
value_template: "{{ (states('sensor.total_energy_day')|float + states('sensor.total_energy_night')|float)|round(3) }}"
unit_of_measurement: "kWh"
- platform: template
sensors:
t31_cost_today:
friendly_name: 'T31 Cost Today'
entity_id:
- sensor.energy_t31_light_and_power_total
- input_number.t31_daily_cost
- input_number.t31_energy_cost
value_template: "{{ (states('sensor.energy_t31_light_and_power_total')|float * states('input_number.t31_energy_cost')|float + states('input_number.t31_daily_cost')|float)|round(2) }}"
unit_of_measurement: "$"
- platform: template
sensors:
t41_cost_today:
friendly_name: 'T41 Cost Today'
entity_id:
- sensor.energy_t41_heating_total
- input_number.t41_daily_cost
- input_number.t41_energy_cost
value_template: "{{ (states('sensor.energy_t41_heating_total')|float * states('input_number.t41_energy_cost')|float + states('input_number.t41_daily_cost')|float)|round(2) }}"
unit_of_measurement: "$"
- platform: template
sensors:
total_cost_today:
friendly_name: 'Total Cost Today'
entity_id:
- sensor.t31_cost_today
- sensor.t41_cost_today
value_template: "{{ ( states('sensor.t31_cost_today')|float + states('sensor.t41_cost_today')|float )|round(2) }}"
unit_of_measurement: "$"
- platform: template
sensors:
cumulative_energy_cost:
friendly_name: 'Cumulative Energy Cost'
entity_id:
- input_number.cumulative_energy_cost
value_template: "{{ states('input_number.cumulative_energy_cost')|float|round(2) }}"
unit_of_measurement: "$"
- platform: template
sensors:
last_reset:
friendly_name: 'Last Reset'
entity_id:
- input_datetime.last_reset
value_template: "{{ states('input_datetime.last_reset') }}"