Problem with new Energy dashboard (Home Assistant 2021.8)

I an trying to configure the new Energy settings in Home Assistant 2021.8.
I have a ShellyEm as a meter for the energy coming from the grid and a ShellyPM as a meter for the energy coming from the photovoltaic panels.
I have been using these meters for several weeks in a dashboard implemented resorting to Grafana/InfluxDB. They have been working fine:

No, when trying to select these 2 Shelly devices to configure the Energy dashboard of Home Assistant 2021.8 they are not visible but other devices are:

I would be very grateful if someone could help me solving this problem.
Thank you

Hello, what i have read on others thread, the sensor needs to have

  • device_class: energy
  • state_class: measurement
  • be a true energy kwh instant or accumulating counter.

Are you using base Shelly integration or the custom SheelyForHass?

In my case with Shelly 3EM and PM, ShellyforHassdoesn’t provide yet a directly usable kwh sensor.
First step, create in configuration.yaml an integration sensor, to get kWh from shelly current_consumption (W)

  - platform: integration
    source : sensor.shelly_compteur_current_consumption
    name: sensor.shelly_compteur_current_energy
    unit_prefix: k

Second step i have customized the device_class: energy in the configuraiton UI

That may not be the best way to do it.

1 Like

Thank you for your prompt reply.
I am using SheelyForHass integration.
(I tried your suggestion and added the following to the Configuration.yaml file:

  - platform: integration
    source: Shelly1PM.current_power
    name: PV_production
    unit_prefix: k
    round: 2

Unfortunately, it did no change the situation.
I thank you anyway.
I reckon that I am very unexperient with these things but It also seems that this new “Energy Dashboard” is still very incipient.
If there is something else that you think that I should do, I will try it. Otherwise I will be waiting until “the dust settles”.
Best regards

There’s also an issue with the devices that forget their total when turned off (e.g. the PM1, but not the EM). A fix has been merged for the next release.

Hello Manuel,
did you follow the second step of my previous message ?
What are the attributes of the entity with developper tools ?

Hello erggosum,

Thank you once again for your support.

I took good notice of the other steps of your previous message but I do not know how to do what you recommended:
the sensor needs to have:

  • device_class: energy
  • state_class: measurement
  • be a true energy kwh instant or accumulating counter.

My limited knowledge of HA and my fear of spoiling what I have been able to put working ( a dashboard implemented resorting to Grafana/InfluxDB showing produced energy and energy exchanged with the grid) makes any attempt of changing the “configuration.yaml” file very difficult for me.
But taking advantage of your patience, I will try to explain how things are.
Using the “overview” button of HA what I get is this:

Taking the case of the device that I use to measure the energy produced by my photovoltaic panels, Shelly1PM, as you can see, it appears under different categories:

  • Switch
  • Sensor
  • Binary sensor

Is this normal?

What should I do, now, in order to guarantee that…
"…the sensor needs to have:

  • device_class: energy
  • state_class: measurement
  • be a true energy kwh instant or accumulating counter.

Thank you again for your support.

Yes it’s normal, shelly1pm is a switch with power measurement, in home assistant you get :
A switch : to command to turn it on or off
A binary sensor : to know it state, is it on or off
A sensor : to know other numeric values, current power or more.

As you said earlier, you can wait for a shellyforhass update which should put the correct attributes to the sensors.

If you want to try, first you can do a snapshot of your current config and no fear anymore ( supervisor/ snapshot).

Then go to developper tools, entities and check the attributes of the sensors you want to have in the energy dashboards.

If the class is missing, you can add it in the configuration/customize menu.

Dear erggosum,
I followed your instructions and for the Photovoltaic power measuring sensor, Shelly1PM, I got this:

It seems that the 3 attributes that you pointed out…

  • device_class: energy
  • state_class: measurement
  • be a true energy kwh instant or accumulating counter.
    …are all properly set.
    However, for some reason that I do not understand, the “state” appears as "unavailable.
    The fact is that, at this very moment,it is pumping energy into my home grid:
    Am I missing something or doing some stupid mistake?
    Once again, thank you very much for your support.

I was going to give up and then I saw that this sensor is in W not kw/h.
You need to add an integration sensor, what you have done on post 2 to have kWh.
And recheck class.

Ps: I am confused too, first screenshot says kwh, second screenshot shows W.

Pps : see also Shelly 3EM 3-phases Energy sensor maybe a better solution but not clear if it’s base Shelly or shellyforhass

The main problem here seems to be that one cannot add those attributes to a power integration sensor. AT least I didn’t find any explanation on how to achieve this. HA refuses those attributes in sensors of type integration.

I had a similar issue yesterday, using the integration platform (with a configuration like the one described above), even if in the past a similar configuration worked properly (and it still does, on different sensors).

From the developer tools, all the configured sensors looked similar and had all the proper attributes (state_class, device_class) but I discovered that the only one that didn’t work had an empty unit_of_measurement in the statistics_meta table of the database (it should have been kWh, like all the others). I fixed that manually and now it appears in the energy configuration. I couldn’t find a way to fix/identify this issue from the Home Assistant interface.

My gut feeling is that this specific sensor was “born” that way (ie. broken) because the sensor on which the integration was performed was not properly populated the first time it was created.

1 Like

Changing the database was the solution for a couple of my problems too, thanks!

I had a utility meter and integration sensor which did not get the unit of measurement applied to the db. Interestingly enough the utility meter was for the 3rd tariff - the other two worked perfectly.

I had a similar problem and your solution worked for me! Thanks!