Energy Management in Home Assistant

Existing projects do give guidance, but you need an entity that measures energy in kWh and meets the definition for long term statistics Sensor Entity | Home Assistant Developer Docs and has the state_class of total_increasing.

I think that is it :slight_smile:

1 Like

Hi!
Have a look here for developer documentation: https://developers.home-assistant.io/docs/development_index

I’d not recommend to use the current Fronius integration as example as it uses some deprecated HA functions (eg. yaml configuration).
That said going through mqtt is probably a good idea as it is well supported by HA (including discovery).
With Modbus you may run into troubles when you use pymodbus and the core Modbus integration requires a different pinned Version than yours at some point.

1 Like

How can I troubleshoot the Energy dashboard if something is not working? In my case the carbon footprint is not working/not shown in the Energy dashboard.

I have setup the CO2 Signal integration and the 2 created sensors of this integration work fine and show data. Within the Energy dashboard configuration I have added the CO2 Signal integration at “Grid carbon footprint” 3 weeks ago, but the data is still not visible in the Energy dashboard.

Thanks for that. Ideally it should detect the system automatically. We have mDNS as well as uPNP. Once it has detected the device, we can connect either to MQTT or modbus-tcp. Until recently modbus-tcp was preferred because the MQTT integration was somewhat CPU heavy.

An absolutely insane amount of things can be accessed through MQTT or modbus, and not every system will have everything. For a start, I will likely have to expose the system energy counters, which is currently logged only to our own telemetry platform (VRM) and not exposed to other systems.

Have you checked your region’s availability at electricityMap | Live CO₂ emissions of electricity consumption?


Also see https://github.com/tmrowco/electricitymap-contrib/wiki/Getting-started

@dbrunt , the region is available (the Netherlands), also visible on the electricitymap website. The sensors of CO2 Signal are giving the correct values, it just doesn’t work with the Energy Dashboard and I cannot find out why…

Guys this is driving me nuts, my battery sensors won’t show up no matter what I do, is this a bug or what’s going on?
utility meters:

inverter_battery_charged_today:
  source: sensor.solar_battery_charged_today
  cycle: daily
  tariffs:
    - peak
inverter_battery_discharged_today:
  source: sensor.solar_battery_discharged_today
  cycle: daily
  tariffs:
    - peak

Sensors where data comes from:

- platform: mqtt
  name: "Solar Battery Charged Today"  
  state_topic: "home/solar/battery/charged_today"
  state_class: measurement
  unit_of_measurement: "kWh"

- platform: mqtt
  name: "Solar Battery Discharged Today"
  state_topic: "home/solar/battery/discharged_today"
  state_class: measurement
  unit_of_measurement: "kWh"

customize.yaml

      sensor.solar_battery_charged_today:
        last_reset: "2021-08-05T00:00:00+00:00"
      sensor.solar_battery_discharged_today:
        last_reset: "2021-08-05T00:00:00+00:00"

Sensors nowhere to be seen:



Any ideas?

I have a meter with 2 tariffs however step_2 is not offered as that meter is currently paused.
Not sure what your issue is…


Sorry, can’t really help since my region is unavailable.

Can you show me your source:sensors to compare? Thanks

See post 845 above…

In case you haven’t tested this since you posted last, the Smart Meter Texas integration is working again. Just need to be on 2021.9.0 at least. I currently have my setup and working in the Energy dashboard.

I’ve done some coding to take a steam from an Enphase system and feed it into HA via mqtt - you may be able to modified it to suit your Victron GX-device if it has a mqtt stream.

Hey, thanks for that. I already found the shiftr component which uses a similar way, also using paho. But I will probably not go that way. It seems far easier to just program our mqtt component, which happens to be a project I maintain, to do MQTT Discovery. Then you can either use the Mosquitto server on our GX device, or bridge the two, and it will just work.

The more challenging part now is to create the energy counters. Because our systems are insanely flexible. You can use a Carlo Gavazzi modbus-rtu connected meter to measure your energy, or you can use the inverter itself, your PV can be AC-coupled or DC-coupled, some managed batteries (those with a BMS) have their own energy counters, some people use a shunt (BMV-7xx or SmartShunt), for others we have to calculate it… and if there is a grid outage the Carlo Gavazzi loses power and you lose that counter…

So the actual interface to HA is easy now. Getting the data is now the hard part :slight_smile:

Anxiously waiting for to to get your input meter sensor!
Without knowing what’s actually under the hood, I think you definitely want Return to Grid which looks to be absolute value(s). What shows up in the Energy Panel remains to be seen but as far as dials and graphs, you can do whatever your heart desires in Lovelace! As for Solar Production, I think you want that also since Return to Grid is not necessarily just solar…could be any entities. Plus it gives you Solar Forecasting…

Can you elaborate, or give an example more detailed? I am trying to change my mqtt things but cannot even see your original message. Please advise.

this are my mqtt sensors right now:

  #sensor sonoff_pow_watts:
  - platform: mqtt
    name: Power meter 1 Current Power Usage
    state_topic: "tele/sonoff_power1/SENSOR"
    value_template: "{{value_json['ENERGY'].Power }}"
    qos: 1
    unit_of_measurement: "W"

  #sensor sonoff_pow_volts:
  - platform: mqtt
    name: Power meter 1 Current Voltage
    state_topic: "tele/sonoff_power1/SENSOR"
    value_template: "{{ value_json['ENERGY'].Voltage }}"
    qos: 1
    unit_of_measurement: "V"

  #sensor sonoff_pow_current:
  - platform: mqtt
    name: Power meter 1 Current Amps
    state_topic: "tele/sonoff_power1/SENSOR"
    value_template: "{{ value_json['ENERGY'].Current }}"
    qos: 1
    unit_of_measurement: "A"

  #sensor sonoff_pow_kwh_today:
  - platform: mqtt
    name: Power meter 1 Todays Power
    state_topic: "tele/sonoff_power1/SENSOR"
    value_template: "{{ value_json['ENERGY'].Today }}"
    qos: 1
    unit_of_measurement: "kWh"

  #sensor sonoff_pow_kwh_yesterday:
  - platform: mqtt
    name: Power meter 1 Yesterdays Power
    state_topic: "tele/sonoff_power1/SENSOR"
    value_template: "{{ value_json['ENERGY'].Yesterday }}"
    qos: 1
    unit_of_measurement: "kWh"

  #sensor sonoff_pow_kwh_total:
  - platform: mqtt
    name: Power meter 1 Total Power
    state_topic: "tele/sonoff_power1/SENSOR"
    value_template: "{{ value_json['ENERGY'].Total }}"
    qos: 1
    unit_of_measurement: "kWh"

it is the kWh you have to change :

  #sensor sonoff_pow_kwh_total:
  - platform: mqtt
    name: Power meter 1 Total Power
    state_topic: "tele/sonoff_power1/SENSOR"
    value_template: "{{ value_json['ENERGY'].Total }}"
    qos: 1
    unit_of_measurement: "kWh"
    device_class: "energy"
    state_class: "total_increasing"

I have a Homematic HM-ES-PMSw1-Pl-DN-R1 here, works fine, but i cant add this device to the energy consumption. Whats i have to do?

Apreciate any advise…

What do I have to change?

I might have had the same problem as you. Fixed by adding the CO2 sensors to the RECORDER.