Energy Management in Home Assistant

Thanks for this very nice impression on how I want to have my own consumption dashboard :wink:

I tried to re-create it but I can not figure out which custom cards you used for the Last Day / Last 10 days cards, and also for the 3 cards on the right with the beautiful graphing.
Also, how did you calculate the summaries in the Energy Usage/Cost Summary?

Thanks for any hint!

Sorry to butt in but it looks like the mini-graph-card, available in hacs or see GitHub - kalkih/mini-graph-card: Minimalistic graph card for Home Assistant Lovelace UI

1 Like

Yes, @nickrout is correct these are the HACS mini graph cards in a vertical stack and the following is an example of one of these:

entities:
  - entity: sensor.meter_power
    index: 0
  - entity: sensor.energy_usage_day_std
    index: 1
    y_axis: secondary
font_size_header: 18
height: 160
hours_to_show: 24
line_width: 2
lower_bound: 0
name: Meter Power & Energy (Last Day)
points_per_hour: 6
show:
  labels: true
  labels_secondary: true
  state: true
smoothing: false
type: custom:mini-graph-card

The power and energy entities come from a D1 Mini with ESPHome and the following config:

substitutions:
  esphome_name: "Utility Meter"
 
esphome:
  name: d1mini04
  platform: ESP8266
  board: d1_mini

wifi:
  ssid: !secret esphome_ssid
  password: !secret esphome_ssid_pwd
  fast_connect: true
  reboot_timeout: 45min
  manual_ip:
    static_ip: 192.168.1.128
    gateway: 192.168.1.1
    subnet: 255.255.255.0
    dns1: 192.168.1.7
    dns2: 192.168.1.7

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "D1Mini04 Fallback Hotspot"
    password: "2Sf2UMlm2a14"

captive_portal:

# Enable logging
logger:
  level: debug

# Enable Home Assistant API
api:
  password: !secret esphome_api_pwd

ota:
  password: !secret esphome_ota_pwd

web_server:
  port: 80

time:
  - platform: homeassistant

sensor:
  - platform: pulse_meter
    pin: GPIO4
    unit_of_measurement: 'kW'
    accuracy_decimals: 1
    name: 'Meter Power'
    filters:
      - multiply: 0.06
    total:
      name: "Meter Energy"
      unit_of_measurement: "kWh"
      accuracy_decimals: 1
      filters:
        - multiply: 0.001

  - platform: wifi_signal
    name: "${esphome_name} WiFi Signal"
    update_interval: 60s

  - platform: uptime
    name: "Uptime Sensor"
    id: uptime_sensor
    internal: true
    update_interval: 60s
    on_raw_value:
      then:
        - text_sensor.template.publish:
            id: uptime_human
            state: !lambda |-
              int seconds = round(id(uptime_sensor).raw_state);
              int days = seconds / (24 * 3600);
              seconds = seconds % (24 * 3600);
              int hours = seconds / 3600;
              seconds = seconds % 3600;
              int minutes = seconds /  60;
              seconds = seconds % 60;
              return (
                (days ? String(days) + "d " : "") +
                (hours ? String(hours) + "h " : "") +
                (minutes ? String(minutes) + "m " : "") +
                (String(seconds) + "s")
              ).c_str();

text_sensor:
  - platform: template
    name: "${esphome_name} Uptime"
    id: uptime_human
    icon: mdi:clock-start

I then have 3 utlity_meter entities for hour, day, and month consumptions:

energy_usage_hour:
  source: sensor.meter_energy
  cycle: hourly
  tariffs:
    - std

energy_usage_day:
  source: sensor.meter_energy
  cycle: daily
  tariffs:
    - std

energy_usage_month:
  source: sensor.meter_energy
  cycle: monthly
  tariffs:
    - std

Finally, the cost for the last hour, day, month is calculation using templates with the Standard Tariff (p/kWh) and Standing Charge (GBP/month) being input_number helpers:

    energy_cost_current:
      friendly_name: Energy Cost Current
      unit_of_measurement: £
      value_template: "{{ ((states('sensor.meter_power') | float * states('input_number.std_tariff') | float / 100.0) | float ) | round(2) }}"
    energy_cost_last_hour:
      friendly_name: Energy Cost Last Hour
      unit_of_measurement: £
      value_template: "{{ ((state_attr('sensor.energy_usage_hour_std', 'last_period') | float * states('input_number.std_tariff') | float / 100.0) | float ) | round(2) }}"
    energy_cost_last_day:
      friendly_name: Energy Cost Last Day
      unit_of_measurement: £
      value_template: "{{ ((state_attr('sensor.energy_usage_day_std', 'last_period') | float * states('input_number.std_tariff') | float / 100.0) | float + (states('input_number.standing_charge') | float /30.0)) | round(2) }}"
    energy_cost_last_month:
      friendly_name: Energy Cost Last Month
      unit_of_measurement: £
      value_template: "{{ ((state_attr('sensor.energy_usage_month_std', 'last_period') | float * states('input_number.std_tariff') | float / 100.0) | float + states('input_number.standing_charge') | float ) | round(2) }}"

Since the Home Assistant energy monitoring features were introduced a few months ago a lot of what I did here has been kind of superceded. The one area where HA is lacking though is on the energy cost calculations and inclusion of a daily/monthly standing charge and different trariffs. This may come in time though.

Hope that is useful to you.

3 Likes

Hi, I have been using energy management for a while. Recently I noticed some warnings about two sensors (which strangely had values anyway). I had forgot to configure device_class and state_class. So I added it to configuration.yaml

    sensor.energia_exportada_kwh:
      last_reset: '1970-01-01T00:00:00+00:00'
      device_class: energy
      state_class: measurement
    sensor.yc600_producao_kwh:
      last_reset: '1970-01-01T00:00:00+00:00'
      device_class: energy
      state_class: measurement

Now the warning is gone but the values for this sensors for today is the total accumultated value (and not the delta for today).
By the way, this sensors are already in kwh and are calculated with the integration component.
What have I done wrong?

i have my sensors in sensors.yaml and the device and state class in customize.yaml:

  unit_of_measurement: kWh
  device_class: energy
  state_class: total_increasing
  last_reset: '1970-01-01T00:00:00+00:00'

how is your sensor set up i.e. rest etc

I’ve fixed the problem but probably won’t help anyone with the same problem. Something is wrong the integration platform (or at least my configuration). But the strange thing is that both were working for the last month or so. The only sensors which weren’t working were the ones from integration. Fortunately both devices already had a kwh attribute which I now used to replace those.

Here are the sensors with the problem anyway:

- platform: integration
    source: sensor.contador_potencia_ativa_exportada
    name: "Energia exportada kwh"
    unit_prefix: k
    round: 2    
  - platform: integration
    source: sensor.yc600_pow
    name: "YC600 produção kwh"
    unit_prefix: k
    round: 2

If you look around you will see many threads about issues with that integration. At this stage, as I understand it, there is no plan to modify how it works. You may have noticed that there is a configuration option for “method”. You might have better results if you use “left”

Thanks, I don’t need it right now, but it is good to know in case I need to use this component again.

I just wonder why energy statistics sometimes become crazy without visible reasons - sensor’s consumed energy (state) doesn’t changed, but energy value (sum) make a huge jump :-o

You’ll need to look at the original data,

Oh, I see. Thanks.
Probably that anomaly caused mess with energy statistic

anybody had energy panel hiccups with winter time last night? seems stats were not filled anymore until ha restart

1 Like

Possibly related - Home Assistant crashing after clocks changed?

root cause same, not quite ‘crashed’ with me… weird

Nor with me. I was still able to use HA, but CPU was high.

Same here.

My utility (Georgia Power / Southern Company) doesn’t have smart meters but someone has written an API that can extract daily power consumption (kWh) and daily cost (US$).
GitHub - apearson/southern-company-api: Node.js Library to access utility data from Southern Company power utilities (Alabama Power, Georgia Power, Gulf Power, Mississippi Power))
What is the easiest way for me to feed this into Home Assistant energy functionality? I can write a node-red node that can read this data every day and publish it to an MQTT topic, but data resets every day, so do I have to keep a running total to feed HA or is there an easier way? Thanks

While I’m waiting for my Iotawatt system to be delivered, I thought about trying to add some individual devices, like smart plugs etc. I’m not that familiar with YAML coding and can’t seem to find any resources or examples on what exactly needs to be added to the configuration.yaml file to get those devices to show up. I know that you have to define a sensor (I have both MQTT plugs and non-MQTT). There are thousands of examples on how to add the whole-house systems, but very little info on how to configure individual devices. What I have been able to find seems to have been posted before the Energy Monitor was added and doesn’t quite work with it or it is a partial example that also doesn’t work. Can anyone point me to something more definitive?

If the device was detected automatically or you have already added it then the POWER sensor should be there already. If not then this is the first step so you need to work out how to add the plug.

If you have the POWER sensor then look to see if your plug also provides an ENERGY sensor. It will have the unit of kWh or Wh. If there is no ENERGY sensor then you will have to create one using the Riemann Sum Integration. Integration - Riemann sum integral - Home Assistant

Look back through this thread and make sure your ENERGY sensor has the required attributes.

Once you have the ENERGY sensor correctly setup you will be able to add it to the energy dashboard by selecting it from the drop down list.

Is there a plan to visualize the water consumption with the energy monitor? The statistics par day with the possibility to look into the past is ingenious.