android icon indicating copy to clipboard operation
android copied to clipboard

Healtconnect steps are lagging behind in the companion app

Open wiedsee opened this issue 6 months ago • 11 comments

Home Assistant Android app version(s): 2025.4.3-full Android version(s): Android 15 + one UI 7.0 Device model(s): Samsung S22 Home Assistant version: 2025.5.1 Last working Home Assistant release (if known): dont know Description of problem, include YAML if issue is related to notifications: I've been trying to sync my step count from Samsung Health into Home Assistant.

Currently, Samsung Health reports the step count to Health Connect, and I can verify that the value shown in Health Connect is accurate and up-to-date. However, in the Home Assistant Companion App, the value lags behind significantly.

Throughout the day, the step count in Home Assistant continues to increase gradually — even during periods when I'm not moving at all. Just before the daily reset at midnight, the value finally matches the correct step total as shown in the Samsung Health app.

In the Home Assistant Developer Tools, the step sensor shows the following: Image

At the same time, Health Connect reports the following: Image

And the companion app show: Image

It seems like the Companion App interprets the data from Health Connect as a predicted or interpolated value over the entire day, rather than using the current cumulative step count.

Could this be a bug in how the Companion App handles the endTime in Health Connect data? Or is there a setting I’m missing?

Any help or clarification would be appreciated!

Companion App Logs:


Screenshot or video of problem:

Additional information:

wiedsee avatar May 09 '25 18:05 wiedsee

So for us we use an aggregated value from health connect. The last time this caused an issue for a user it turned out to be a local time zone issue. Can you check that your time zones are in sync? Also check the time zone the app is adding the steps to add that may cause an issue.

dshokouhi avatar May 10 '25 18:05 dshokouhi

Okay thanks for the help. I checked my phone that's on Amsterdam (GMT+2). And homeassistantant server is at Europe/Amsterdam (GMT+1) (same as the Homeassistant user). Both homeassistant and my phone show the same time so i dont think the GMT+1 or +2 is doing something here. or should I look somewhere else? Or is there a way for me to change the timezone for the timestamp that is send with my steps counter thrue the companion app since that is in UTC and not UTC/GMT +2?

wiedsee avatar May 10 '25 19:05 wiedsee

So just to confirm eventually the 2 are in sync? But only at the end of the day? It's possible the aggregated value is not calculated immediately

dshokouhi avatar May 10 '25 21:05 dshokouhi

Yes that's correct the last read before midnight is correct with the health services report after that it will reset to 0 exactly at midnight. The sensor updates at least every minute sometimes twice a minute so that's not the problem. It only keeps incrementing to the right amount just before midnight. All the other values before that are short. In the morning it's way short and the closer we get to midnight the more accurate it gets. (As far as I can see). The companion app on my watch does report it correctly only it doesn't update that often to home assistant (only once an hour). But it updates more frequently to my phone (Samsung health). So that's why I'm trying to get it working this way.

wiedsee avatar May 10 '25 21:05 wiedsee

about how far off would you say the numbers are? I can see the 2 time zones you listed are an hour apart. Would that maybe correlate to the data you see? Its indeed strange that its correct at the end of the day. The data from the watch is raw data, the data from health connects is an aggregate value we get from health connect

https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/StepsRecord#COUNT_TOTAL()

dshokouhi avatar May 17 '25 19:05 dshokouhi

It depends in the morning there far off it does start counting the minute i wake up in the morning but it looks like it is thinks the value is the predicted value for the end of the day.

So in the morning it could say I did 5 steps but i already dit like 40 and in the middle of the day it would be like ha saus I did 2000 steps but in reality I did 40000 and than just before midnight it might be off from Samsung health with a few steps (10 at most) but that could be up to how frequently samsung updates the value. So basically its corrrect at midnight before the reset. That's why I think it's to do with how the value is presented in health connect since it's one value for 00:00 till 23:59 that updates thrueout the day so maybe that's why homeassistant thinks it's a prediction and calculates accordingly to that prediction.

You can also see the value in home assistant rising quickly when I go for a run or something almost directly when it's happening. So that's why I think that this is the problem but I have no idea how I can fix this.

wiedsee avatar May 21 '25 16:05 wiedsee

do you see any rate limit errors in the companion app logs?

settings > companion app > troubleshooting > show and share logs. The logs will contain GPS and URL data so be careful with sharing but you should be able to see rate limit errors as I have seen them before. If you dont see them or any health connect related error then that may just be the value the API is returning.

FWIW on my pixel watch with fitbit I always see the 2 in sync when I check, if the data is in Health Connect we should be able to pull it unless there is an error.

I am still a bit suspicious about the time zones only because of the last issue that was caused by it ref: https://github.com/home-assistant/android/issues/5189

dshokouhi avatar May 21 '25 16:05 dshokouhi

No rate limit errors or health connect errors to be found only a lot of these:

05-21 18:30:42.147 23458 23458 I View    : setRequestedFrameRate frameRate=-4.0, this=android.webkit.WebView{6ea91e5 VFEDHVC.. .F...... 0,0-1080,2259 #7f0a0298 app:id/webview aid=1073741824}, caller=WV.p6.b:1 WV.P6.onDraw:103 com.android.webview.chromium.WebViewChromium.onDraw:40 android.webkit.WebView.onDraw:2959 android.view.View.draw:26148 
05-21 18:30:42.157 23458 23458 D SurfaceView: 240129666 updateSurface: has no frame

The weird thing is that it resets exactly (sometimes just 2 sec late) at midnight and that it is correct or 99.9% correct just before that.Screenshot_20250521_183945_Samsung Health.jpg

Screenshot_20250521_184014_HealthConnect.jpg

Screenshot_20250521_183755_Home Assistant.jpg

wiedsee avatar May 21 '25 16:05 wiedsee

This is surprisingly accurate to what I am seeing with Samsung Health and Health Connect to Home Assistant via the Companion App. For example, this morning I walked ~7200 steps, then around noon I got in another ~3000 steps to hit 10k. The graph was surprisingly accurate up to about 2300 steps then slowed considerably and has just now (around 4 PM) reached where I was at 7:30 AM this morning. Given the history, I think it will continue to rise until the full 10k are accounted for, at least that's what the past few days of testing has shown.

Timezones all match on my side, Central US (and times match between my Android and HA). Same reset at midnight as well, which makes sense.

I've noticed that Samsung Health does not have an option for running in the background (not that I've found, at least) and my heart rate (which is real-time in the Samsung Health app via my fit3) seems to only update sporadically, likely when I open the app to see what's going on.

I suppose as a test I could leave my phone charging with the Samsung Health app open while I work and report back the results so we could determine whether or not this is a Samsung Health specific issue?

Edit - In Health Connect there is an option to perform a daily export of the data it records, so I set that up and will report back if I can provide any insight into the order of data insertion and access. Images for reference:

Image

Image

rocket357 avatar Jun 13 '25 21:06 rocket357

Actually, disregard the data export. I recently swapped off of Fitbit to Samsung Health, so I got a chance to compare the data of the two in Health Connect (I didn't experience this issue with Health Connect, but I was using the Fitbit Integration and only started playing around with Health Connect and Fitbit a few days ago as a way to test migrating off of Fitbit to Samsung Health).

Fitbit does data such as:

12:32 - 12:33: 10 steps 12:33 - 12:34: 12 steps etc...

Samsung Health bulks it all under one heading "00:00 - 23:59" and just repeatedly updates that number.

It looks like the Companion App is trying to smooth out the data across the entire day because it's a single entry. It begins at zero at midnight, and as of a bit ago hit 11,041 steps. That's about 11,041/24 steps per hour (460), which multiplied by 16.5 gives 7590 (pretty close to what's being graphed by Home Assistant).

Maybe this could be templated instead of making changes to the companion app, since the app is just taking whatever garbage Samsung Health is recording?

A few images of how HA is interpreting the data (note, I've been sitting at my desk since my last update):

Image

Image

rocket357 avatar Jun 13 '25 22:06 rocket357

I'm seeing the same result (2 phones connected). Seems like it's trying to "smooth" out the data by the end of the day. We can be sitting still and/or not bringing our watches or phones with us as we move around and it will keep adding steps trying to "close" the gap. Time zone wise I'm in Europe/Oslo (CEST which is not an option in HA). I can select my time zone manually, but it will say GMT+1, while if I change from automatic to manual on my phone it says GMT+2. Both for the same location (Europe/Oslo) and both will portray the time correctly. Timewise HA is accurate with Europe/Oslo. I just started using it the other day, so I can't comment on when it was last working accurately.

dugongballs avatar Jun 20 '25 21:06 dugongballs

Fitbit does data such as:

12:32 - 12:33: 10 steps 12:33 - 12:34: 12 steps etc...

Samsung Health bulks it all under one heading "00:00 - 23:59" and just repeatedly updates that number.

It looks like the Companion App is trying to smooth out the data across the entire day because it's a single entry.

A few more days of testing gives the same results. The rate changes as steps are added to the number, but I think Samsung Health logging it all under a single heading is causing the oddity in graphing.

Unfortunately this doesn't appear to be something we can adjust from the dashboard side, since the raw number of steps isn't available in HA (just the calculated value).

Is there another option here @dshokouhi ? Is there a way to grab the "raw" data from Health Connect as opposed to a calculated value?

rocket357 avatar Jun 22 '25 13:06 rocket357

I have the same issue. Daily steps always lag behind.

Image

It looks like it updates every 15min - but I have strange curves (always connected in this time to home server) as well as the data lags behind even at the end of the day. Timezone and connection to home server look fine.

Jeetah avatar Jul 22 '25 13:07 Jeetah

Yeah this issue is 100% because Home assistant uses the aggregated approach:

private suspend fun updateStepsSensor(context: Context) { val healthConnectClient = getOrCreateHealthConnectClient(context) ?: return val stepsRequest = healthConnectClient.aggregateOrNull(buildAggregationRequest(StepsRecord.COUNT_TOTAL)) ?: return val totalSteps = stepsRequest[StepsRecord.COUNT_TOTAL] ?: 0 onSensorUpdated( context, steps, totalSteps, steps.statelessIcon, attributes = buildAggregationAttributes(stepsRequest), ) }

Can we get a toggle to use healthConnectClient.readRecords instead of healthConnectClient.aggregate?

jacobcapper avatar Aug 24 '25 13:08 jacobcapper

Hello, this same thing is still happening for me with my Oura ring which is writing to Health Connect. This doesn't seem to be fixed as of today, am I missing something?

digitalseth avatar Oct 07 '25 03:10 digitalseth

No for me it is also still doing the same thing as before.

wiedsee avatar Oct 07 '25 18:10 wiedsee

Please make sure you are on version 2025.9.2 which is in the beta and still waiting for Googles approval to be live, that is the version that contains the fix

dshokouhi avatar Oct 07 '25 18:10 dshokouhi

Aaah i see i downloaded the beta and everything seems fine now thx

wiedsee avatar Oct 08 '25 10:10 wiedsee

Hello, this same thing is still happening for me with my Oura ring which is writing to Health Connect. This doesn't seem to be fixed as of today, am I missing something?

Downloading the beta app fixes it for me as well. Thank you!

digitalseth avatar Oct 12 '25 21:10 digitalseth

Hi all I have enabled my daily steps on my samsung android HA Android app but the sensor remains at 0.0 steps. Am I missing something? Health connect is working fine.

Is there a sensor that shows the current steps on HA from my samsung ?

bachoo786 avatar Oct 28 '25 16:10 bachoo786

Did you enable health connect in the Samsung Health app under settings

wiedsee avatar Oct 28 '25 16:10 wiedsee

Yes I have see the screenshot attached

Image

bachoo786 avatar Oct 28 '25 16:10 bachoo786

Ok i see it now I restarted HA however its true that the steps are lagging behind.

EDIT: updated it to the beta and everything works fine now thanks.

bachoo786 avatar Oct 28 '25 16:10 bachoo786