Skip to content

Instantly share code, notes, and snippets.

@bartclone
Forked from langestefan/HA_energy_FAQ.md
Last active September 22, 2023 22:25
Show Gist options
  • Save bartclone/eaaee4666cf452c38c8cf69a62e5d864 to your computer and use it in GitHub Desktop.
Save bartclone/eaaee4666cf452c38c8cf69a62e5d864 to your computer and use it in GitHub Desktop.
HA Energy Dashboard FAQ

Frequently Asked Questions for the Home Assistant Energy Dashboard

Yes, this beautiful thing:

image

Home Assistant introduces the Energy Dashboard here.

1. I'm replacing my [solar inverter, energy meter, ...], how can I retain my energy dashboard data?

Answer

Home Assistant stores energy dashboard related data in long term statistics, frequently referred to as LTS. In order to retain your energy dashboard data you must ensure the LTS are transferred from your old entity ID to the new one. To do so, follow these steps:

  1. Backup your Home Assistant, in case something goes wrong.
  2. Remove the old entity or remove the integration this entity is associated with.
  3. Reboot HA OS, or reload your docker container if you run core.
  4. Verify that the old entity ID has been removed in dev-tools->states.
  5. Change the entity ID of the new entity to be identical to the old one (the one you just removed): (sensor.my_new_energy_device -> sensor.my_old_energy_device)
  6. Check that statistics have carried over. One way to do this is by checking that the energy dashboard still shows your old graphs.
  7. (optional, only from HA version >= 2023.4) Change the new entity ID to whatever you like, the statistics should carry over. This feature was added in Home Assistant 2023.4 so this does not work on older versions.
  8. (optional, only if you completed step 7) Update your Energy Dashboard config to the new entity IDs.

2. My entity is not listed when I try to add it to the energy dashboard. How can I make it visible?

Answer

First of all, make sure you are adding an energy [kWh or Wh] entity and not power [kW or W]. In case you have a device which provides instantaneous power only, read question #3 for instructions on how to convert power to energy.

For an entity to be visible in the dropdown menu it must have the following attributes, which you can verify in dev-tools->states.

  • state_class: total_increasing or state_class: total
  • unit_of_measurement: kWh or unit_of_measurement: Wh
  • device_class: energy

If all of these attributes are set correctly check dev-tools->statistics to see if there is any issue that needs your attention. Simply pressing FIX ISSUE is enough in many cases.

  • If your entity is provided by an integration please create an issue on their GitHub page and refer to this FAQ.

  • If your entity is provided by a template sensor, you can specify the correct device_class, unit_of_measurement and state_class attributes directly in the template sensor YAML config. See the template sensor docs on how to do this. An example config of a correct energy sensor could be:

template:
  - sensor:
      - name: 'My Energy Sensor'
        device_class: energy
        unit_of_measurement: kWh
        state_class: total_increasing
        state: {{ states.sensor.my_energy_sensor.attributes["energy"] }}

Note that this option is not available in the legacy sensor configuration format, so if you are still using this you will have to move over your YAML config to the more modern format to make these attributes available.

3. I have a power entity, but the energy dashboard only accepts energy entities. How can I use it?

Answer

Power in W is the rate at which energy in Wh is consumed. For example, if a 1kW load is on continuously for 1 hour it will have consumed 1 kWh. Thus to compute energy from power we need to integrate it over time. Luckily for us HA provides a convenient integration for this: Integration - Riemann sum integral, named after the famous German mathematician who first formulated it.

If you have a sensor that provides you with power readings in Watts (uses W as unit_of_measurement, device_class of power), then you can use the integration sensor to track how much energy is being spent. Take the next manual YAML configuration as an example:

sensor:
 - platform: integration
   source: sensor.current_power
   name: energy_spent
   unit_prefix: k
   round: 2

This configuration will provide you with sensor.energy_spent which will have your energy in kWh, as a device_class of energy.

image

See also this explanation for a more detailed discussion on power and energy.

4. My energy dashboard shows a weird spike of x kWh. How can I correct it?

Answer

To understand where this weird spike comes from, you need to understand how changes to the state of the sensor are interpreted by Home Assistant.

If the state_class of the sensor is total_increasing, a lower state (even from e.g. 1000 to 999) will be interpreted as a reset of the sensor. So in the example above, HA will think the sensor has been reset to 0 and then increased to 999 again. So the value used for the long term statistics will then be 1999 (1000 + 999). That means if for some reason your sensor will be 0 temporarily, and then go back the the correct state, the value will be doubled. Therefor it is really important to avoid decreases of the sensor value, which can be avoided by using a proper availability template in case you are using template sensors.

On the other hand, if the state_class is total a decrease of the sensor value will cause a decrease of the value in the long term statistics. So in case such a sensor drops to 0, you will see a negative spike, unless the last_reset attribute is set to the date and time of the reset, in that case it will be interpreted the same as for the total_increasing sensor, and new values after the reset will be added to the existing value.

If you have a spike in your data, you can correct this in dev-tools->statistics. Find the sensor there, and press the icon at the end of the line. You then can either:

  • Find the faulty value, and set it to 0.

  • Add a correction value in the same hour, which is the opposite of your faulty value.

    NOTE: The states in this view are reported at an interval of 15 minutes, so it might take some effort to find the faulty value.

5. My energy dashboard is not visible, and I can't configure it. How can I fix this?

Answer

Most likely you are not using default_config: in your configuration.yaml file. To make the energy dashboard visible add the following line to your config: energy:

6. I want feature x in the energy dashboard or I want to customize item y to my liking, how can I achieve this?

Answer

Unfortunately the frontend of the energy dashboard is currently not configurable. Customization will likely become possible in the future as functionalitity is constantly added to Home Assistant and the energy dashboard is very popular. In the meantime you can either:

7. I want finer time range control in the energy dashboard, is there a way to do this?

Answer

There is a popular feature request for this and the HA core PR for it is still open. In the meantime you can use the energy cards with a custom dashboard and combine it with the awesome energy-selector-period-plus community integration, available in HACS.

8. How can I access the calculated cost and compensation data calculated by the energy dashboard?

Answer

The energy dashboard automatically calculates the cost for grid consumption entities and the compensation for return to grid entities by writing the result to internally created entities. These monetary entities are named automatically according to the following format:

  • '<entity_id>_compensation' for return to grid entities.
  • '<entity_id>_cost' for grid consumption entities.

Where <entity_id> is the entity ID of the input sensor. For example, if your grid consumption entity has entity ID sensor.energy_consumption_tarif_2 then the cost entity will have the entity ID sensor.energy_consumption_tarif_2_cost. You can find these entities by navigating to dev-tools->states and searching for *_compensation or *_cost.

NOTE: Any modification to these entities outside the energy dashboard will likely break things, so be careful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment