Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Warning in log: invalid literal for int() with base 10 #268

Closed
PixelPusher247 opened this issue Mar 22, 2023 · 8 comments
Closed

Warning in log: invalid literal for int() with base 10 #268

PixelPusher247 opened this issue Mar 22, 2023 · 8 comments
Labels
bug Something isn't working fixed Upcoming fix/feature already on dev

Comments

@PixelPusher247
Copy link

Since Meross LAN version 3 (currently on 3.0.3) on Home Assistant 2023.3 (currently on 2023.3.5) I get the following warning in Home Assistant logs after restarting Home Assistant:

ConsumptionSensor(energy): error(invalid literal for int() with base 10: '0.000') while trying to restore previous state
@ChristophCaina
Copy link

ChristophCaina commented Mar 22, 2023

just received the same error - and, it seems that it corrupted my statistics in the energy dashboard - which I had to recover manually.

Affected devices:
mss310, Firmware-Version 6.3.21, Hardware-Version: 6.0.0

Meros-Lan: v3.0.3
Home-Assistant: 2023.3.5

@krahabb
Copy link
Owner

krahabb commented Mar 23, 2023

I'll check this.
To be honest, the ConsumptionSensor carries int values (the native Wh from the device) so that 'float' state shouldnt really happen. Maybe you set the precision to show 3 decimal digits? This would help me investigate why this value popped up in your state.
As for @ChristophCaina losing its statistics this too shouldnt happen. The error is just logged but the sensor should work as expected. The state recovery is only needed to 'patch' the daily consumption when the device is reporting incorrect offsets.
If your device is not (which I hope are the majority) the state restoration is simply useless and any error there should be no harm. Of course this is by design and the fact it's happening means there's some bug linging around.
I would need more context in order to see what else (if any) is 'ruining' your statistics. Nevertheless I'll try to review the whole thing to try guess where things could go bad with regard to statistics

@ChristophCaina
Copy link

I had the same situation today - just after restarting HA due to an update.
It seems, that, everytime when HA is restarting, it tries to restore the previous state... and then, the statistic calculation will be messed up.

and yes... in my case - I've set the sensors to display kWh (instead of Wh) - and probably also changed the precision to 3 decimals (unfortunately, I can't 100% confirm since some time has passed since then.

what exactly do you need - or how can I further support on this?

@PixelPusher247
Copy link
Author

I have my own integration sensor for the energy tracking and I do not use the one delivered by the Meross integration, I have left it as default (and could actually disable it, I'll way to see if I can help in the search of the bug).
The estimated sensors from the integration are also disabled (per default I think?)
An example configuration of one of the normal energy sensors:
image
Also to note, I have disabled the history for this sensors (in the recorder). Could this be causing that issue?

@ChristophCaina
Copy link

Also to note, I have disabled the history for this sensors (in the recorder). Could this be causing that issue?

I don't think so, because I keep the history and recorder for them... and facing the same issue here.
I think - the change from Wh to kWh COULD be the issue here

image

When I remember right, the sensors default was Wh -> with the change to kWh, it probably also changed the precission.

@PixelPusher247
Copy link
Author

Also to note, I have disabled the history for this sensors (in the recorder). Could this be causing that issue?

I don't think so, because I keep the history and recorder for them... and facing the same issue here. I think - the change from Wh to kWh COULD be the issue here

image

When I remember right, the sensors default was Wh -> with the change to kWh, it probably also changed the precission.

You are right, when switching back to Wh the warning does not appear on restart.

@ChristophCaina
Copy link

thanks for that confirmation.
Then, I will change the sensor back to Wh until an update might fix the issue

@krahabb
Copy link
Owner

krahabb commented Mar 24, 2023

Hello @ChristophCaina and @czornikk,
Thank you for the quick check!
I've reviewed the code and I can (sadly) confirm the state restoration failure, even if not 'harming' by itself and only appearing when HA sets a display precision with decimals, could mess the statistics since the sensor starts with a default of 0 as soon as it gets registered in HA and so triggers the statistics reset.
This is a 'side' effect of making the sensor now available to HA even if the device is not connected.
Since we can't really control how HA stores the state (decimals or not) I'm anyway going to fix this for the better and make it safer

krahabb added a commit that referenced this issue Mar 26, 2023
@krahabb krahabb mentioned this issue Mar 28, 2023
@krahabb krahabb added bug Something isn't working fixed Upcoming fix/feature already on dev labels Apr 15, 2023
@krahabb krahabb closed this as completed Apr 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working fixed Upcoming fix/feature already on dev
Projects
None yet
Development

No branches or pull requests

3 participants