yo-han / Home-Assistant-Carelink

Unofficial Home Assistant Carelink Component
MIT License
19 stars 8 forks source link

Carelink Download Interval #63

Closed Trenar closed 2 months ago

Trenar commented 3 months ago

Hi, I currently use the rc1 beta (including the nightscout updater). It works nicely, but I noticed that the new sensor values do not get fetched in regular intervals. To see this, I added a template-sensor with the following definition:

{{ ( as_timestamp(states.sensor.last_glucose_update.last_changed) - as_timestamp(states.sensor.last_glucose_update.state) ) | round(0)}}

and what I observe is this:

image

This means that the delay between the SGV reading (as reported by Carelink) and the download time (as the time of entering the HA database) vary between roughly 40 and 100 seconds.

1st question: Is there some logic behind the fetching/downloading time of this integration? 2nd: Why is it not a fixed interval of 300 sec, as we know that the data comes in at that rate? 3rd: somehow related, I'd also like to see #4 being implemented.

Thanks for your time spend on this extension :)

yo-han commented 3 months ago

Hi @Trenar I think I can answer all these questions at once. The interval is fixed right now and is about 3/4 minutes. This is because the same interval is used by the pump and app to upload new data to Carelink. We would unnecessary stress the Carelink api if we fetch with a higher interval rate. When there are gaps this is 99% of the time because there was a hiccup with the sync between pump en Carelink somewhere is my experience. And so for your last question, I still not sure if it's worth the time implementing this feature as it will not make the experience better.

Trenar commented 3 months ago

Hi @yo-han , how do you know that the pump/app upload happens every 3 or 4 minutes? I think it's rather "every time a new value arrives from the pump", which is (roughly) every 300 sec then. From my experience, when using the official Carelink Connect App you see the new SGV every 5 minutes with only a little delay. Also from experimenting with xDrip+, the values could be downloaded with a constant rate of 300 sec and an SGV receive delay (measurement vs. download time) below one minute. I think this should also be possible here? Thanks for your time!

Trenar commented 3 months ago

And (just a little note): Isn't the download rate right now at 60 seconds? https://github.com/yo-han/Home-Assistant-Carelink/blob/8dfee4fa594ab6114b200ef11cf896061a33d4c3/custom_components/carelink/__init__.py#L85C1-L85C14

yo-han commented 3 months ago

The download speed is indeed 60 seconds. We made adjustments somewhere along the line but completely forgot about it. What I recall is that even with this download speed, Carelink only provides new data every 4 to 5 minutes. However, it's possible that things have changed since last year.

Another change is that my wife, for whom I created this component, is no longer using it and has switched to using the Carelink app and the Apple Watch complication. Additionally, I'm currently occupied with other fun projects and work, which means my time to address these issues is very limited. On the other hand, @sedy89 has made some excellent contributions, so I'm confident that development will continue.

For now, I'll keep this issue open and revisit it when I have more time available.

sedy89 commented 3 months ago

the integration is currently configured to scan for updates every 60 seconds. The "last_update" sensor will show the time the integration got the last lifesign from the pump, which usually is ~5min. ***

On the other hand, the "last_glucose_update" sensor will only be updated once there is a new and valid SG reading available. If the pump owner is too far away from the smartphone, there won't be an update on this sensor, but on the "last_update". ***

*** this was changed/introduced in the beta release

Personally, I don't see a reason why the value should be changed. The 60 seconds scan timer of the integration will start as soon as the integration was sucessfully initialized. In my understanding, the biggest possible delay until the integration finally has the latest information is more or less equal to the scan interval, because the smartphone could have just reported the latest values right after we tried to check for them. This gap would increase the higher we configure the scan interval value. In my opinion, a smaller cycle time is better. At least it should be smaller than the update cycle of the pump.

But once I have some time, I can check if I can make it configurable on the integration setup page.

Trenar commented 2 months ago

Hi @sedy89 , I think I understood correctly, what "last_glucose_update" and "last_update" mean, and that's why I was confused about the pattern in the figure of my original post. If the integration actually checks for data every 60 seconds, that curve should show a constant "sgv receive delay" of any value < 60 seconds. To me, it looks like it is actually executing every ~75 seconds. Could that be possible?

I agree, that a configurable delay setting is not really needed, when fetching every 60 seconds.