Hi there,
I have a number of Tasmota flashed LB smart plugs I use for energy monitoring. As I have a number of other ESPHome devices I am reflashing the plugs with ESPHome so I can retire Tasmota and simplify my HA setup (a bit).
As part of doing this I will need to move the sensor long term statistics from the existing Tasmota sensors so the new ESPhome sensors so that I can see old and new data seamlessly in the Energy dashboard. I’m OK with the SQL to do this but in getting ready to move the first plug’s data across I have identified a problem.
Specifically the sensors are reporting a spurious amount of decimal places of power data back to HA. HA is then faithfully storing this data in the long term statistics tables which all fills up the database unnecessarily.
It is happening on Tasmota as well, but its particularly bad on ESPHome.
e.g.
daily_energy (from ESPHome):
id created created_ts metadata_id start start_ts mean min max last_reset last_reset_ts state sum mean_weight
60648469 NULL 1756848910.4715693 720 NULL 1756848600.0 NULL NULL NULL NULL NULL 0.48187193274498 0.5298719327449801 NULL
60648770 NULL 1756849210.4559257 720 NULL 1756848900.0 NULL NULL NULL NULL NULL 0.481945276260376 0.529945276260376 NULL
60649071 NULL 1756849510.4542525 720 NULL 1756849200.0 NULL NULL NULL NULL NULL 0.482019782066345 0.530019782066345 NULL
The state and sum are both captured with 10 decimal places of data, e.g. 0.48187193274498 !
daily_energy from Tasmota:
id created created_ts metadata_id start start_ts mean min max last_reset last_reset_ts state sum mean_weight
5019596 NULL 1753322410.417633 213 NULL 1753318800.0 NULL NULL NULL NULL NULL 0.0 95.60300000000208 NULL
5019903 NULL 1753326010.4176698 213 NULL 1753322400.0 NULL NULL NULL NULL NULL 0.001 95.60400000000209 NULL
5020210 NULL 1753329610.4309297 213 NULL 1753326000.0 NULL NULL NULL NULL NULL 0.001 95.60400000000209 NULL
State is returned with 3 decimal places. Sum has gained a lot of decimal places but this is due to floating point rounding errors in HA so is unavoidable.
Power (from ESPHome):
id created created_ts metadata_id start start_ts mean min max last_reset last_reset_ts state sum mean_weight
5316881 NULL 1756843210.51355 722 NULL 1756839600.0 0.8432221859959365 0.641993522644043 0.917133629322052 NULL NULL NULL NULL NULL
5317206 NULL 1756846810.5085099 722 NULL 1756843200.0 73.88444220760194 0.825420260429382 2942.57690429688 NULL NULL NULL NULL NULL
5317507 NULL 1756850410.523198 722 NULL 1756846800.0 0.8898624693616567 0.825420260429382 0.96299022436142 NULL NULL NULL NULL NULL
Mean min and max all have stupid number of decimal places
Power (from Tasmota):
id created created_ts metadata_id start start_ts mean min max last_reset last_reset_ts state sum mean_weight
5026665 NULL 1753405211.015667 214 NULL 1753401600.0 0.0 0.0 0.0 NULL NULL NULL NULL NULL
5026972 NULL 1753408810.4102542 214 NULL 1753405200.0 0.21413377749999998 0.0 1.0 NULL NULL NULL NULL NULL
5027279 NULL 1753412410.3892372 214 NULL 1753408800.0 0.0 0.0 0.0 NULL NULL NULL NULL NULL
5028506 NULL 1753426810.4009042 214 NULL 1753423200.0 0.0 0.0 0.0 NULL NULL NULL NULL NULL
5028812 NULL 1753430410.5007527 214 NULL 1753426800.0 833.9618132332233 3.0 2254.0 NULL NULL NULL NULL NULL
5029109 NULL 1753434010.4462683 214 NULL 1753430400.0 165.48498334833334 8.0 2254.0 NULL NULL NULL NULL NULL
Some big numbers of decimal places but only affecting mean. Zero power is being returned as zero.
To be clear, this is nothing to do with the entity display precision you can change in HA, all that does is change what level of precision you see in the HA UI. This is about how the sensors return data to HA and that they haven’t been configured with a reduced number of decimal places of precision. As a result we get stupidly long values returned and stored in HA.
The config in ESPHome should be something like this which is for a Temperature and Humidity sensor but all the sensors are similarly configured, its the accuracy_decimals that is missing in the LB plug
# BMP280 Temperature & Pressure Sensor
- platform: bmp280_i2c
temperature:
name: "Loft Temperature"
oversampling: 16x
accuracy_decimals: 1
filters:
- offset: 0.0
pressure:
name: "Loft Pressure"
accuracy_decimals: 0
address: 0x76
update_interval: 5min