home-assistant / core

:house_with_garden: Open source home automation that puts local control and privacy first.
https://www.home-assistant.io
Apache License 2.0
73.71k stars 30.83k forks source link

state_class missing for Android battery sensors after Home Assistant core update or restart #83716

Closed J3173 closed 7 months ago

J3173 commented 1 year ago

The problem

The state_class attribute for the battery_level, battery_temperature and battery_power sensors of my Android phone has disappeared since Home Assistant 2022.12.

This causes the sensor data to be now longer recorded into the long term statistics.

afbeelding

I have confirmed that the state_class attribute reappears when downgrading Home Assistant to 2022.11.5.

What version of Home Assistant Core has the issue?

core-2022.12.1

What was the last working version of Home Assistant Core?

core-2022.11.5

What type of installation are you running?

Home Assistant Container

Integration causing the issue

Mobile App

Link to integration documentation on our website

https://www.home-assistant.io/integrations/mobile_app

Diagnostics information

No response

Example YAML snippet

No response

Anything in the logs that might be useful for us?

No response

Additional information

No response

home-assistant[bot] commented 1 year ago

Hey there @home-assistant/core, mind taking a look at this issue as it has been labeled with an integration (mobile_app) you are listed as a code owner for? Thanks!

Code owner commands Code owners of `mobile_app` can trigger bot actions by commenting: - `@home-assistant close` Closes the issue. - `@home-assistant rename Awesome new title` Change the title of the issue. - `@home-assistant reopen` Reopen the issue. - `@home-assistant unassign mobile_app` Removes the current integration label and assignees on the issue, add the integration domain after the command.

(message by CodeOwnersMention)


mobile_app documentation mobile_app source (message by IssueLinks)

dshokouhi commented 1 year ago

Sounds like a duplicate of https://github.com/home-assistant/core/issues/71065

Did you wait up to 4 hours after the upgrade? What we discovered in the other bug is that upon a HA core update the state class goes missing until the app re-registers the sensors which happens about 4 hours after the update. It can happen anytime between the update and 4 hours so its possible you didnt wait long enough for that to happen.

In order to continue here we will need the logs as mentioned in the other issue.

https://github.com/home-assistant/core/issues/71065#issuecomment-1113657883

J3173 commented 1 year ago

I didn't wait. I checked now and about half an hour after the upgrade the state class attribute appeared again.

I have enabled the debug logging. If it happens again, I'll upload the logging.

bcutter commented 1 year ago

See plenty of those errors too, not limited to battery entities only, see https://github.com/home-assistant/android/issues/2847#issuecomment-1345649375.

Still on HA Core 2022.9.7. Watching this issue now as all previous ones have been closed as solved...

J3173 commented 1 year ago

Yesterday I have updated my Home Assistant to 2022.12.6 and later did a restart. It looks like the state class also disappeared after a normal restart, not only after an update. I have attached the logging and the states of the level, power and temperature entities (query: select s.last_updated, s.entity_id, s.state, sa.shared_attrs from states s join state_attributes sa on s.attributes_id = sa.attributes_id where s.entity_id = 'sensor.pixel_4a_battery_level';)

The state_class seems to disappear when the first update_sensor_states is received after an update/restart and appears again when register_sensor is received.

I suspect that self._config.get(ATTR_SENSOR_STATE_CLASS) of the sensors is not correctly restored after a restart as it is not mentioned in https://github.com/home-assistant/core/blob/cc40c6d16a09978aba5fbdcb3ded048a72a4c8c8/homeassistant/components/mobile_app/sensor.py#L48-L58

bcutter commented 1 year ago

Can this please get fixed?

Suffering from this for months, being redirected from https://github.com/home-assistant/android/issues/2847#issuecomment-1346869360.

Now that the entity popup only shows statistics and not the raw data anymore, thanks to this bug NOTHING is shown for affected entities (in short: things got worse):

image

image

dshokouhi commented 1 year ago

I believe this is now fixed in the latest HA core release? May also need latest android app version too

DAVe3283 commented 1 year ago

@dshokouhi this is not fixed on the latest HA core release for me

dshokouhi commented 1 year ago

@dshokouhi this is not fixed on the latest HA core release for me

I think you first need to wait for the app to re-register the sensors after updating HA core and then on the next restart it should work.

DAVe3283 commented 1 year ago

I think you first need to wait for the app to re-register the sensors after updating HA core and then on the next restart it should work.

I will try waiting for a re-register (4 hours?) then restart. But what do I restart, HA core or the android app/phone?

dshokouhi commented 1 year ago

I will try waiting for a re-register (4 hours?) then restart.

might be more frequent than that, when it re-registers the sensors the error will go away in Statistics.

But what do I restart, HA core or the android app/phone?

restart HA core like this issue states :)

bschatzow commented 1 year ago

Just came back for me after the latest core update - 2023.4.6.

bcutter commented 1 year ago

It never was gone completely. Or when should it be fixed? Still see this for few devices. E. g. for one entity:

image

image

nicolaasuni commented 1 year ago

For a long time, including the last version I am getting the following warnings in the logs:

2023-04-24 14:52:11.795 WARNING (MainThread) [homeassistant.components.sensor] Sensor sensor.mobile_battery_state has device class battery, state class None and unit None thus indicating it has a numeric value; however, it has the non-numeric value: full (<class 'str'>); Please update your configuration if your entity is manually configured, otherwise create a bug report at https://github.com/home-assistant/core/issues?q=is%3Aopen+is%3Aissue+label%3A%22integration%3A+mobile_app%22

I am using:

bschatzow commented 1 year ago

Cave back on 2023.6 for me.

fliespl commented 1 year ago

Seeing same issue again.

Last date for getting state was just prior update: https://ss.codeone.pl/ss-2023-06-13-22-30-49-1686688249-aTMenRla.png And after that: https://ss.codeone.pl/ss-2023-06-13-22-31-26-1686688286-EfruXX0W.png

Same for battery temperature as well as other sensors from phone (OnePlus LE2123)

issue-triage-workflows[bot] commented 1 year ago

There hasn't been any activity on this issue recently. Due to the high number of incoming GitHub notifications, we have to clean some of the old issues, as many of them have already been resolved with the latest updates. Please make sure to update to the latest Home Assistant version and check if that solves the issue. Let us know if that works for you by adding a comment 👍 This issue has now been marked as stale and will be closed if no further activity occurs. Thank you for your contributions.

bcutter commented 1 year ago

Not fixed, still exists.

bryanyork commented 1 year ago

Happened to me as well. The fix was to disable/re-enable the sensor in the companion app, set the refresh time to always, and then set the refresh time to normal.

bcutter commented 1 year ago

Happened to me as well. The fix was to disable/re-enable the sensor in the companion app, set the refresh time to always, and then set the refresh time to normal.

I doubt it. Have you restarted HA and/or the devices meanwhile? It will come back...

emilianogetino commented 1 year ago

The same thing happens to me currently, both with the battery sensors of the phones and the battery and temperature sensors of the Xiaomi door sensors.

grimreaper38uk commented 12 months ago

Still happening. Noticed it just after a server reboot. Is there a workaround? Manually adding a 'state class' in? I can't find any documentation for state classes (and I'm not a HA developer).

dziban303 commented 10 months ago

This has been going on for months with me. In fact, this may never have worked since I installed Home Assistant about six months ago. I'm using the latest version of Home Assistant and the Android app. Restarting core or the app does nothing.

image

endyb66 commented 9 months ago

Same issue here with some sensors of my phone and also some of my Pixel Watch 2.

kmoser77 commented 9 months ago

For me it helped to set the state_class manually in the configuration.yaml. It took some time but now i have statistics for my android devices:

homeassistant:
  customize:
    sensor.redmi10_battery_level:
      state_class: measurement

83716-statistics-for-android

robinhood-code commented 9 months ago

I have the same issue for my Lenovo tablet.

brianjmurrell commented 8 months ago

I'm having this issue for all of my mobile devices. Clicking "Fix Issue" in Statistics clears the issue there but then I am not able to graph the battery level of my devices. The entity simply doesn't exist when I try to create a Statistics Graph for it.

I have no idea if this is related to any upgrades on my part. My last upgrade was weeks ago so any of this "wait 4 hours" suggestion is not the case here.

How do I fix all of these broken statistics without completely deleting them so that they are not even graphable any more?

brianjmurrell commented 8 months ago

I just added a new mobile device and it has immediately gotten into this state:

image

No upgrade of HA, etc. Just adding a new mobile device. I don't dare click the DELETE button or else I will never again be able to add it to a statistics graph as the entity just never shows up again for that card despite the device showing data for that entity.

I did enable debug logging for homeassistant.components.mobile_app before adding this new device. What can I extract from the log to debug this issue? Is it this:

2024-02-23 10:08:47.507 DEBUG (MainThread) [homeassistant.components.mobile_app.webhook] Received webhook payload from Redmi Note 4 for type register_sensor: {'unique_id': 'battery_level', 'state': 100, 'type': 'sensor', 'icon': 'mdi:battery-charging', 'attributes': {}, 'name': 'Battery level', 'device_class': 'battery', 'unit_of_measurement': '%', 'state_class': 'measurement', 'entity_category': 'diagnostic', 'disabled': False}

I'm running: Core: 2024.1.6 Frontend: 20240104.0

dshokouhi commented 8 months ago

@brianjmurrell what app version are you running?

brianjmurrell commented 8 months ago

@dshokouhi It should be the latest. I always keep all of my apps up-to-date. It says it's 2024.1.5-full (12102)

dshokouhi commented 8 months ago

and this was on a device that never had the app installed?

brianjmurrell commented 8 months ago

Yep. I logged it into my HA just a few minutes before that registration.

dshokouhi commented 8 months ago

ok well your debug log shows the correct state class being passed which is what we have always seen since the start of the issue. Sensors do get re-registered the next time HA core or the app has an update. Can you try updating to 2024.2 for HA core as it looks like there are some changes to the integration there. Once you update open the app and check to see if the state class is there.

brianjmurrell commented 8 months ago

Apologies for my ignorance but where in the app am I looking for the state class? And is that the app on Android or the webUI of HA you are referring to?

brianjmurrell commented 8 months ago

ok well your debug log shows the correct state class being passed which is what we have always seen since the start of the issue. Sensors do get re-registered the next time HA core or the app has an update. Can you try updating to 2024.2 for HA core as it looks like there are some changes to the integration there.

I have updated, a number of days ago and the graphs are still not showing any useful data.

Once you update open the app and check to see if the state class is there.

Where and what am I looking for exactly to see if the state class is there or not?

ViscountHermit commented 8 months ago

This has been going on for months with me. In fact, this may never have worked since I installed Home Assistant about six months ago. I'm using the latest version of Home Assistant and the Android app. Restarting core or the app does nothing.

image

I've got the same issues with all the mobiles in our family. For example the RX/TX values work fine when a phone is added, but after a restart of HA I get the same errors for every item I am graphing with statistics. The stats stop being generated, with the same errors as above.

532910 commented 7 months ago

please remove "battery" from the title as almost all sensors are broken:

light_sensor mobile_rx_gb mobile_tx_gb total_rx_gb total_tx_gb wifi_link_speed wifi_signal_strength wifi_frequency

mad-tunes commented 7 months ago

I've found similar for months with these: image

image

I'm using HA OS Core 2024.4.3 Supervisor 2024.04.0 Operating System 12.2 Frontend 20240404.2

I've toggling the sensor on/off in the android app, cleared the apps cache and then data. Clicking fix/delete removes the message, until it comes back again a while later