Utility meter / integration sensor manual input

Is there anyway to set the initial state and correct the state of a utility meter or integration sensor manually?
When I add a utility meter it starts counting now and so the daily, monthly and yearly consumption starts at zero. Waiting a year to have a correct consumption for yearly energy use seems a waste when you have a “smart” home.

My heat pump energy meter is currently at about 3200 kWh and I whould like my HA energy sensor to start there. The I could correct it monthly if there readings are slightly off and there’s a difference between the sensor and the meter

I feel I have searched everywhere and tried every component I can find but have not found a solution. Setting the sensors state in developer tools gets overridden on next sensor update from my esphome pulse counter sensor.

You could create a template sensor that adds 3200 to the yearly utility meter sensor and use the resulting sensor in your frontend.

1 Like

I could do that, but in my experience these power sensors are not 100% accurate so to do a manual reading for correction later I would have to calculate the difference between the meter and the energy sensor and update the 3200 offset in configuration.yaml and reboot HA. Or I could make the offset an input number to avoid reboot, but I would still have to calculate the offset manually or via a script.

I really hope I missed something easy or that somebody made a custom component that allows manual state changes after initialisation.

You can just manually edit your mysql db and set the value to whatever you want

You mean I can edit my “home-assistant_v2.db”?
Or is data stored elsewhere?
Can I just open it or do I have to shut down HA first?

Yes, I’ve also shut down the db as I’d rather avoid issues, but in theory, a db like mysql can accept simultaneous writes from thousands of sources in high performance environments…

I just use an adminer docker

I tried to edit the db, but still no change…

Changing the db is not changing the value. Maybe we should also change the persistent value in the .storage core persistent file.

EDIT: Did it. First stop HA instance. Change the last state value of the sensor in the database. Then open config/.storage/core.restore_state file and find the relevant sensor. Change the state value to the same value you did in the db. Then start HA again…

3 Likes

does this still apply in 2021 and how do you stop HA, so you can restore the figure that you want ?

Thanks Martyn

There is a service utility_meter.calibrate to set the state manually

4 Likes

Hi. Thank you. I found this and it sorted my needs.

Martyn

1 Like