-
Notifications
You must be signed in to change notification settings - Fork 33
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
Issues with pet weight sensors #95
Comments
Turn on debug logging and share the file with me. |
I may know what is going on (on the Home Assistant side of things), but it will require additional logging.
Side note: Don't worry about the errors in the logs from the petkit integration - I added those in the file I have uploaded to help distinguish the temporary things I am logging from the regular debug logs. File can be downloaded here: https://easyupload.io/05ifda |
Hi @RobertD502 , here's the log. Could it be related to the reload of the last state? home-assistant_petkit_2024-11-13T08-53-02.512Z.log these are showing up in the HA log as well:
where does the latest_weight come from? It looks like a more precise version of pet weight (not rounded to hg) |
Maybe this is a similar issue, if not I can make a new one. My two cats don't have any entities anymore. It says they are disabled by the component. I am running the latest .24 version via HACS though. |
At a quick glance, this looks to be a Home Assistant units problem. The way weight is handled (in order to preserve last non-zero weight at midnight until the litter box statistics page identifies a pet having a non-zero weight for the current day) is that Home Assistant, during boot or when the integration is reloaded, sets the state of the sensor to the last state recorded in the HA database. Then, during the first poll, the weight is fixed because it uses the weight that is returned by the PetKit API to set the state of the sensor. The default unit used by the integration is For example, when the PetKit API is polled:
Now, for some reason, Home Assistant seems to be saving the state in its database in the unit you selected (in grams) instead of respecting the default native unit of measurement (KG). What ends up happening, during HA start or reload of the integration, is that 3200 is seen as the last state (instead of 3.2KG) and Home Assistant says "oh wait the native unit of measurement is KG, so the state is 3200KG...the user selected a unit of grams so let's convert 3200KG to Grams", which is how you'd end up with a high weight like 3,200,000 Grams. One way to test this theory is to have your sensors set to a unit of KG instead of Grams. Let the integration run for a few polling cycles (~10 minutes) and then reload the integration and see if you get whacky values. The only potential issue you may see is with Pets that haven't used the litter box yet. |
It is not related to this issue. Based on your logs, the PetKit API doesn't seem to be returning any Pets at the endpoint that is used to fetch pets for an account. Shoot me a private message on discord as I'll need to investigate why your account isn't returning any pets. |
How do i do it :)? |
For each of the latest weight sensors, click on it, select the settings gear icon in the upper right hand corner, and then, in the unit of measurement field, select kilograms. |
Seems like it's working! I just set the unit to kg. I will leave it like this and do some more tests. One last question: I always get readings rounded to hg (4.200, 3.800...). Is there a way to get a more precise reading (up to grams, like 4.287 or 3.845)? Or is it a limit on the api side? |
I believe I've tracked down the issue. As I suspected, the way I am pulling in the last state is what causes the issue - there are two ways to do it: One way pulls in the state that reflects the value that is obtained after the conversion is done (if the user selected a unit different from KG), the other way pulls the "native value" (the pre-conversion value). I'll get a fix out that should resolve the issue for anyone that chooses to use a non-KG unit of measurement. Essentially: Way 1 pulls the last state while Way 2 pulls the last native_value. |
@RobertD502 thank you very much! |
On what Discord can I find you? Sorry to spam this unrelated issue. |
Same username as here. |
Hi @RobertD502 ,
I'm having a weird issue in the last few days:
For some reason i get spot updates in the weight sensor for my cats with really out of range values, it looks like they are 1000x the pet weight. Could it be related to latest updates? Weird values gets added to the DB (first line, which corresponds to latest peak, max is 3400):
This seems to happen upon Integration load/reload (in fact, i can replicate it forcing a reload, this is the value immediately after reloading:
pretty huge cats here :)
The weight goes back to normal (like 4.200g) after a few minutes.
The text was updated successfully, but these errors were encountered: