Set Initial value for entity

I have a balcony power plant that has been running for several days. So far, I have tracked the total generated energy using the inverter integration in the Energy Dashboard. However, this value is only updated every five minutes, the same as the current power output.

Now, I want to use a smart plug to measure the energy production, but it naturally starts from zero. The entity from the standard integration has already recorded a few kWh. Is it possible to set this value as an initial value for the entity of the smart plug?

The smart Plug ist working via zigbee2mqtt

Thx
Dan

There is a simple solution to your problem as posed, but first I wanted to mention that there really isn’t a good solution here because hardware is imperfect. Are you confident that the smart plug is from now on until the end of time of interest going to capture every kWh?

Regardless of that question, one way to approach this problem is to create a state-based template sensor that adds the offset of what was generated before the smart plug started recording energy generation.

You will want to read the linked doc to learn how to set up the right unit_of_measurement and state_class, but, assuming that your smartplug provides a sensor entity with the arbitrary name sensor.smartplug_kwh, and that the amount of kWh generated before your plug started logging was 1.5, your state could be something like:

state:  " {{ states('sensor.smartplug_kwh')|float(0) + 1.5 }} "
1 Like

Oh, and to answer the exact question you asked, I think, directly – I don’t think you can tell Z2M or HA to use a different “initial value” for the plug. If I’m wrong, someone on the forum will probably correct me. The suggestion I propose creates a new entity that will add an offset to the smartplug’s output.

1 Like