Energy consumption "dip" every restart

I have a weird problem … every time I restart HA the energy values from my Xiaomi Aqara Plugs (connected to zigbee2mqtt) make a “dip” and go down a couple of kWh and imediately up again… this confuses the utility_meter, which then adds these kWh to the total consumption - even though I’ve set it to net_consumption: true … (I also use tariffs with this one, if that makes any difference)

I only have 3 Aqara Plugs, but all of them make a dip each restart … how can I prevent this?! is it a Zigbee2MQTT, Aqara, or a Home Assistant issue?!

I have no Idea where to start with this problem

Here are two pictures:


that’s the energy value of the Aqara plug - each of the dips are restarts of HA


and this is one of the 3 tariffs of the utility meter which is set to “net_consumption: true” (same thing when set to “false” btw)

No one ever experienced anything like that?!
I can understand that the kWh values are wrong for a moment at reboot, but why does “net_consumption: true” not compensate for that?
Is there any other way to ignore negative changes - for example with a template_sensor?

Hi Farnsworth,

I’m facing the same problem with an Shelly 3em.
Every time I restart HA there is a dip as well.

Any ideas??

Cheers
Altbau

Are you using the core Shelly integration?

I am and I don’t see any glitches.

No, not via the core integration.
I handle the data vis MQTT

Maybe you should try it then.

@altbau9944 did this solve your problem?

maybe ZHA is better in this case?! … I just REALLY don’t want to port every thing over there from Z2M xD

Thanks for feedback!

I’m calculation the total energy consumption. Maybe this will cause this behaviour…

Here my “code”

      meter_energy_haus_aktuell_unknown:
        friendly_name: "Aktueller Energieverbrauch (Hausanschluss)"
        unit_of_measurement: 'kWh'
        value_template: "{{ 
						(((
						    states('sensor.shelly_3em_hausanschluss_meter_energy_0') | float +
                            states('sensor.shelly_3em_hausanschluss_meter_energy_1') | float +
                            states('sensor.shelly_3em_hausanschluss_meter_energy_2') | float +
                            (0)) |round(3)) | float)
                        }}"

Is there a way to solve this problem with the calculation???

Cheers

I’m pretty sure it’s not a Zigbee2Mqtt issue, because simply restarting the Addon doesn’t result in any dip or other weird behaviour …

Home Assistant probably stores wrong values before restarting and applies them until it gets the right ones from Z2M … I have no idea how all of this works, but it sounds plausible

And the Utility Meter ist probably just broken - “net_consumption: true” works when not using tariffs, but not when using them.

The problem is that when home assistant starts the sensor states are 'unavailable' this string is converted to 0 by the |float filter. This reduction in value is interpreted by the total_increasing sensor state class as a reset.

To fix this issue include an availability_template to reject these values. If you are not sure how to do this search the forum. I have answered this question many times.

Awesome, now I know what I’m looking for!

Thanks

it’s not working :frowning:

  - platform: template
    sensors:

      klimaanlage_energy_template:
            friendly_name: "Klimaanlage energy Template"
            unique_id: "klimaanlage_energy_template_w4f432tgffaen"
            unit_of_measurement: 'kWh'
            value_template: "{{states('sensor.plug_on_off_klimaanlage_energy')}}"
            availability_template: >-
              {%- if is_state("sensor.plug_on_off_klimaanlage_energy", "unavailable") %}
                false
              {%- elif is_state("sensor.plug_on_off_klimaanlage_energy", "unknown") %}
                false
              {% else %}
                true
              {%- endif %}

this doesn’t either

            availability_template: "{{ states('sensor.plug_on_off_klimaanlage_energy') not in ['unknown', 'unavailable', 'none'] }}"

or this:

            availability_template: "{{ states('sensor.plug_on_off_klimaanlage_energy') != 'unavailable' }}"

Also the values don’t go down all the way to 0 - they just drop a bit (as you can see in the pictures)

Look at your source energy entity. I rebooted this HA instance around 14:15, there is a hole in the line :

(Not an aqara sensor, but zigbee2mqtt too)

The first picture of my first post is already the source - it’s the energy entity of the Xiaomi plug.


Here I rebootet a couple of times trying the template sensors as around 15:30

The energy sensor(s) drop each reboot, but the temperature sensor(s) just show holes where the reboots are (they are all Zigbee2MQTT)

Life can be so easy
… if you have the right support!!!

Works like charm!!!

Thanks a lot!

1 Like

That actually looks like an issue with the integration. You might have to open an issue on github.

Nachricht 2 empfangen auf zigbee2mqtt/plug_on-off_klimaanlage um 16:44:
{
    "auto_off": false,
    "consumer_connected": true,
    "consumption": 402.88,
    "current": 0.0766,
    "energy": 402.88, #<---------------------------
    "led_disabled_night": false,
    "linkquality": 141,
    "power": 17.7,
    "power_outage_memory": true,
    "state": "ON",
    "temperature": 27,
    "voltage": 231
}
QoS: 0 - Retain: false
Nachricht 1 empfangen auf zigbee2mqtt/plug_on-off_klimaanlage um 16:42:
{
    "auto_off": false,
    "consumer_connected": true,
    "consumption": 391.39,
    "current": 0.0766,
    "energy": 391.39, #<---------------------------
    "led_disabled_night": false,
    "linkquality": 147,
    "power": 17.7,
    "power_outage_memory": true,
    "state": "ON",
    "temperature": 29,
    "voltage": 231
}
QoS: 0 - Retain: true

jep - looks like it is a Z2M (or Xiaomi?!) problem after all…

Hey,

its sounds like the same problem which i posted as issues on deconz GitHub.

https://github.com/dresden-elektronik/deconz-rest-plugin/issues/5397

do you use Deconz?