Shelly Bulb Energy issue in HA

Hi All,

i have multiple Shelly Duo bulbs in my home. Some of them and always on and some of them are switched on lamp button so they go offline.

The problem I have with all of these is that the energy consumption sort of resets and goes to zero each time the bulb loose power. So every time the bulb is turned on and get power, connect to wifi and i start with 0KWh in stats of energy for those bulbs. This way i am not able to track total Energy consumption in HA. It like HA is not saving energy usage and start over again when device get electricity.

Other Shelly devices like smart switches, plugs or blinds controllers show their KWh increasingly all the time so it seems to be only Shelly Duo issue.

I am attaching graph how it looks like:


Is there anything i can do to force HA to remember how many KWh was used by those devices so i could track total consuption?

reseting counters (ie energy) is natural thing in IoT.
HA has support for that. The entity tracking such values has to have the state class set to total increasing.

What integration do you use to connect Shelly bulbs with HA?
If it’s core integration - then it’s the integration bug, you may report it in GitHub… and wait for the fix.

If it’s registered using Maciek’s discovery script - raise an issue to its repo. You can modify meta data in mqtt manually if you know where to look at

If you use manually configured mqtt you need to set state class of the entity in entity declaration.

Thanks for your reply. Forgive my questions. I am dealing with HA since 3 days so its all quite new to me.

How do i set entity state class to total increasing?

The integration i used is the "official’ Shelly integration available out of box in HA.

Regarding “Maciek’s script”. Could you please point me to that script?

I do not have MQTT enabled in those Shelly bulbs. I enabled CoIoT as advised in:

as this is 1gen device.

Here is the forum thread for the discovery script: Shellies Discovery Script

Note, I have no experience with this way. I know it exists, but I always preferred using manual (yaml) configuration,n having 100% control over it.

Anyway, it uses the MQTT way, which I prefer. It’s more reliable than the core, and I prefer the architecture where the clients (Shelly and HA) connect to the established broker (mqtt), instead of connecting directly.

For gen2+, I wrote a Shelly script that makes the Shelly registers using MQTT discovery (similarly to the discovery script above)

@maxym thanks for pointing me to those scripts.

@Bieniu is there any chance you could share some information why using default Shelly integration in HA is reseting Energy counters for Shelly DUO bulbs and if there is anything i can do about it to fix it?

Before Beniu answers you (BTW tagging people not yet involved into discussion is treated on this forum as improper behavior ), I already answered that question. You can report this issue to the HA core github. Nothing you can do more to fix it.

However you you can create a template sensor based on your Shelly energy one, setting its state_class to total_increasing. You can achieve it in yaml and likely in GUI too. Such new entity will return what you expect. Such entity can be added to original device too.

I do apologize for tagging person which is not involved. I don’t mean to be rude or anything…

I think i just misunderstood you. If I added affected device by Shelly integration I thought that reporting it HA core github will not help as this seems to be issue with that particular Integration.

The reason why I invited Bieniu to the conversation is that he is Shelly Integration Dev so most likely no one knows more that him about the Shelly integration. Would be nice to know from the core if this a bug or this is by design.

Can you please tell me @maxym, if I understand correctly now, Shelly integration belongs under HA Core? Is that correct?

Yes, the core Shelly integration belongs to the HA Core.
Now I understand why you called Bieniu. Yes, coincidently he is author of the mentioned scripts (as a 3rd party) as well as maintainer of core Shelly integration.
Still, it’s unussual in this community to talk with HA developers about this development on the forum.
IMO the best way is to ask/report in GItHub.

Shelly integration does not reset the Shelly DUO energy counter, Shelly DUO does it on every restart.

Thanks @maxym, I do stand corrected. Once more i would like to apologize for the inproper behaviour.

Man, this template sensor you just suggested to me is ultra cool thing especially that it can be showed in the device info like it would be native entity of that device.

However I am missing something. My understanding is that i am creating here virtual sensor. I thought it will be converting Power (W) to Energy (kWh) but i get info that power cannot be total increasing class:

When i do Energy as total increasing (which i don’t understand how it would add up in that virutal sensor as it zeros everytime it looses power but perhaps there is mathematical way to do that) then i get error like this:

@maxym i would like to stress out that i really appreciate your patience toward my person. Would you be so kind and help me figure out this one?

Have you added the bulbs to your energy dashboard? I think their energy consumption should be tracked there correctly even with resetting counter.

I suspect then that Shelly Duo keeps all values only in RAM and that is why it resets counters every restart.

May I ask why Shelly integration does not fix that by creating/adding virtual component by default which would remember total energy consumption?

My guess would be that you leave that part for the users to decide if they want that and only get real values from the device. Just curious about this one…

I thnk you mixes 2 different things.
You can convert power to energy using integral sensors. Such created energy sensor will be total_increasing. Yes, it’s the way.

I suggested to create helper teplate sensor out of existing energy sensor. But ensure that new template sensor state class is total_increasing. In gui it might be called differently (like reset zero or something like this)

It’s obvious that shelly resets the energy value.
He asks why Shelly integration creates energy sensor without total_increasing class set.

1 Like

Yes, so i think in the second screenshot i am trying to create the template sensor based on existing energy sensor of my lamp. However the error which i don’t understand is preventing me from get it to work. As you can see on the screenshot state class is total increasing.

Why do you think it’s not total_increasing? I have a shelly plug and it has also such sensor and it is total_increasing.

Not sure if you’ve seen my post above, but HA already tracks this and knows the total consumption. The easiest way to view this is through energy dashboard, if you add this sensor to the individual devices part, then you can see its energy use in any selected period.

I think the assumption may be on screnshots from my 1st post where graphs going to 0 after restart.

Yes on the “individual devices total usage” it is increasing. But this show only last 24h. When i click from there on my lamp i get graph like this:

Where kWh being resset to 0 after each restart so for tracking historical data it seem to be imposible.

But that’s what total_increasing class allows AFAIK.This is normal. Resetting to zero are allowed, the sensor cannot go down to any other value though.