Using Continuous Glucose Monitor (CGM) Data

Ok brilliant thank you will have to try to get this fully setup now!

So can we add Sensor age onto it, then be able to get voice prompts?
or maybe at least reminders daily would be good.

Where is this information your code added in HA?

In configuration.yaml

could it not be possible to use en-us.json code and then some how get this in HA?! { "name": { "value": "cgm tx age", "synonyms": [ "tx age", "transmitter age", "cgm transmitter age" ] } },

Thanks for this !

I see your using T1PAL whereas I’m using Heroku what do I add for my URL or the one you add your API code and link to it?
Seems a lot different to adding it into this setup! Has it also as a current,json at the end of it !

Sorry for my silly questions I’m usless on code :slight_smile:

Is the code like

YOURSITENAME https://[email protected]/api/v1/

this and then add this bit to the end of my code?

entries/current.json
scan_interval: 150

Hopfuly somthing like this?

How will I know if the code as worked ok?

Do I need to do anything else?

As I said, whatever you put into your web browser to get nightscout, so if you put https://[email protected]/ into your browser, your setup is correct.

You will know it has worked when you get entities for the setup in developer-tools/states

I don’t know what en-us.json means.

a) don’t SHOUT
b) reminders of what? or voice prompts for what?
c) sensor age can be obtained from the current.json endpoint. Here is the complete endpoint. You’ll see it has unix style date and a dateString.

[
{"_id":"6606209acd16eb6fabe12e17",
"device":"xDrip-DexcomG5",
"date":1711677590402,
"dateString":"2024-03-29T01:59:50.402Z",
"sgv":145,
"delta":-3.5,
"direction":"Flat",
"type":"sgv",
"filtered":0,
"unfiltered":0,
"rssi":100,
"noise":1,
"sysTime":"2024-03-29T01:59:50.402Z",
"utcOffset":780}
]

You could add another sensor, or an attribute to the existing sensor.

do you mind sharing all the code and details how to get this setup please?

I di done with Senes but it tends to fail i fyou have had to restart the HA system which is very annoying to have to keep finding out how to reset it.

In my case was 3 weeks ago and I sti;; not got around to reseting it!

Its good when it was doing it apart from light being stil on and I want sleep :roll_eyes: :man_shrugging: :triumph: :laughing:

Could you please check your spelling. Some of your posts are unreadable.

for it to do somthing like this to happen in HA. Ok Google Nightscout Status

The sensor was inserted a day ago
which has come from where I enter details into AAPS
the day I put my sensor onto me.

So then we can have this daily to remind us when we need to change the sensor!

Sorry was my mistake me pressing caps on keyboard :triumph: :laughing: I changed it now to lower case for you! :slight_smile:

Like this you mean?

Not fully understanding what you mean by this? But I’m meaaning to some how get this code from a Template into HA not at all sure how but this is what I’m meaning. I can give you the link to the Template if that make it easier for you to understand what I’m meaning?

Are you refering to me on this? If so then can we please have a spell checking in these replies as I have Dyslexia and I do my best! :slight_smile:

This thread does that for a sensor Frontend Panel for Diabetics using a Dexcom CGM

Also, if the info is available in Nightscout, you know how to get it. For other endpoints you can look at your Nightscout website, the SWAGGER documentation is at http://nightscouturl/api-docs. Read up on swagger if you are not familiar, it lets you try an API interactively. You’re going to learn a bit about json :slight_smile:

As for the type of display you showed with a text of what your stats are, I knocked up a quick Markdown Card.

The config is

type: markdown
content: >+
  Nick's Blood Sugar is {{states('sensor.blood_sugar')}} mmol/L. It changed by
  {{states('sensor.blood_sugar_delta')}}. 

title: Nick's Levels

Displays this

Of course you can get far more complex.

If you want a device to speak this, use one of the tts services. If you want it notified to your phone or some other service, use a notification integration.

Sorry, wasn’t trying to embarrass you.

Thanks

I’m not sure if I can use Dexcom as I have no receiver to get my reading into their clarity, when I did use my G6 receiver then I was able too! I liked using Tidepool rather than Clarity but that was not right up to date from getting your reading there was a few hour’s delay on the display of your readings! But handy to know this when I do have a receiver. Unless I can get it in with Nightscout?

I will see if I can get thing working now, How do I get a display in Ha like Xdrips :slight_smile: :laughing:

The Markdown is good! thank you! It still shows up in mg rather than mmols though it says it in the code mmols so not sure why mines showing mg though it can be handy to have it Id still prefer mmols :triumph: :laughing:

Will it be possible then to have notifications coming from within a Markdown?

The swagger.yaml does not seem to be working on that page! But you can find it Here:

So I have gone here: Not sure if the correct place but seems it?:

I have already got Care Portal setup in Nightscout but totaly lost on this what too do its too complicated to understand it properly for me to do, would be helpful it being broken down more so it will be eaasier to understand it! :slight_smile:

These links are also not working!
The swagger.yaml does not seem to be working on that page! But you can find it Here:

Having a little play around with trying to figure the code I got this out from my browser, not totaly sure what information its given me as Its suppose to give me (BGs between 2 days:) But I not got that many in my broswer and not sure if svg means mg in the output?

Nothing embarrasses me :laughing: just frustrates me I get it wrong! :triumph: :slight_smile:
Well maybe some thing embarres me with hypos but thats another 10000 stories :slight_smile:

Thanks at least I got somthing in HA now :slight_smile:


I’ve improved it a little but not at all sure how I got mmols into my Ha think its been more luck than knowing how I did it!

And yes I’ve eaten an Apple, just takes 20mins to raise! :triumph: :rofl: :roll_eyes: but in this case might not have :slight_smile: Stay safe and don’t be me :rofl:

How would I add a sensor age one here?

either by adding it as another sensor

rest: 
  - resource: https://SECRET-upload-0-guest.t1pal.com/api/v1/entries/current.json
    scan_interval: 150
    sensor:
      - name: Blood Sugar
        value_template: '{{ (value_json[0].sgv/18)|round(1)}}'
        unit_of_measurement: mmol/L
        icon: mdi:diabetes
      - name: "Blood Sugar Delta"
        value_template: '{{ (value_json[0].delta/18)|round(2)}}'
        unit_of_measurement: mmol/L
      - name: Blood Sugar Trend
        value_template: '{{ value_json[0].direction}}'
      - name: Blood Sugar Last Time
        value_template: '{{ value_json[0].dateString}}'

Or by adding it as an attribute to the Blood Sugar one

rest: 
  - resource: https://SECRET-upload-0-guest.t1pal.com/api/v1/entries/current.json
    scan_interval: 150
    sensor:
      - name: Blood Sugar
        value_template: '{{ (value_json[0].sgv/18)|round(1)}}'
        unit_of_measurement: mmol/L
        icon: mdi:diabetes
        json_attributes:
          - dateString
      - name: "Blood Sugar Delta"
        value_template: '{{ (value_json[0].delta/18)|round(2)}}'
        unit_of_measurement: mmol/L
      - name: Blood Sugar Trend
        value_template: '{{ value_json[0].direction}}'

Yes the swagger.yaml link to the source does not work for me either.

As I said, if you take your access url (base url) and add /api-docs at the end you will get the swagger interface to try on your own data.

The sgv entries in the API response are blood sugar in mg/dL. This so even if you have told Nightscout to report in mmol/L. That setting is Nightscout only affects their web display, not the API. That is why I divide by 18 when putting them into HA as sensors.

The thread I pointed you to for sensor age shows you how to show the age of a sensor, if I recall correctly the poster basically

  1. Set a datetime helper to the time he inserted a sensor
  2. Displayed 10 minus the number of days that had passed since the change (for a 10 day sensor).

You can send notifications or whatever when it gets down to some arbitrary time, say 12 hours to go, or whatever you choose.

I think I have answered all your last batch of questions!

I think you are miss understanding me on what I’m not understanding with the code!

I’m trying to find what code I’d need for sensor age from AAPS when I insert it to then remind me daily to how long left before the sensors needs to be changed!

But you say add another sensor to the code, this will not give me that information I need doign this. And I have no clue how to get my data into the code.

I understand that it need to relate to the sensor but no clue how that will know when I have emter that onto my arm, I personaly only add data in the AAPS APP and that then goes into Nightscout.

Maybe I’m not explaining properly! :slight_smile: or Im just not getting my head around how to do it.

The divide by 18 also does not work for me with the reading being mmols they still turn out mg! So its in the code the divide by 18 but my system seems to ignore it! :triumph: :roll_eyes: :man_shrugging:

You are right, I thought you wanted the age of the current reading. However you are after the time the sensor has been in your body. Sorry for the confusion.

Well for that I did give you one suggestion, and pointed you to a thread. That method does not use nightscout, but relies on you telling HA when the sensor was started.

I do not have AAPS and I struggle to find sensor age in my nightscout.

This picture seems to have found it though. However you didn’t show which query this was based on, nor the entire json. If you could tell me what API query you are referring to and the complete json output, I’ll see what I can figure out,

This would be great if we could figure this out.

Yes I did say I can post the link to it as this is what I thought from the start that might be how we find out this information to try to get into HA

I’m no coder in the least but I do try to have a go if I think it is really needed and in this case think it’s needed so I’m also looking at how to test Swagger Here:

But here is the code to help find a way into it.

Code that might help to get it into Sensor age code into Nightscout HA

Around line: 228

I have also found the /server/swagger.yaml file the link that is not working! Which also might help you!

I found it from this link!
(xdripjs plugin)

swagger.yaml

Hope this can helps!

How do you change the code that you use to add into Home Assitant? The commands? to be able to change it. like this code you showed me!

How can it be changed to have Sensor Age, date inserted and Sensor days left where it says - name: Blood Sugars.

so then like you said we can do a Notification to output the days left with notifications, I would prefer if we could use Alexa or Google for this but might be too much to get it to work this way.

Find it in swagger. At your nightscouturl/api-docs.

PS I suspect it will be in devicestatus endpoint. How about putting this in your browser and posting the json it returns. Not a picture. Copy and paste the text.

https://SECRET-upload-0-guest.t1pal.com/api/v1/devicestatus/

Substitute your own base url.

[{“_id”:“660b3994bbfe1e00029bb184”,“created_at”:“2024-04-01T22:47:27.089Z”,“device”:“openaps://samsung SM-X906B”,“pump”:{“battery”:{“percent”:50},“status”:{“status”:“normal”,“timestamp”:“2024-04-01T22:47:27.089Z”},“extended”:{“Version”:“3.1.0.3-1de236a602-2022.09.17-22:42”,“ActiveProfile”:“Dave”},“reservoir”:50,“clock”:“2024-04-01T22:47:27.089Z”},“openaps”:{“suggested”:{“reason”:“Error: CGM data is unchanged for the past ~45m. Temp 0 <= current basal 1U/hr; doing nothing. “,“timestamp”:“2024-04-01T22:47:27.087Z”},“iob”:{“iob”:1.294,“basaliob”:0,“activity”:0.0244,“time”:“2024-04-01T22:47:27.087Z”}},“uploaderBattery”:85,“configuration”:{},“mills”:1712011647089},{”_id”:“660b3935bbfe1e00029bb183”,“created_at”:“2024-04-01T22:46:11.839Z”,“device”:“openaps://samsung SM-N975F”,“pump”:{“battery”:{“percent”:50},“status”:{“status”:“normal”,“timestamp”:“2024-04-01T22:46:11.839Z”},“extended”:{“Version”:“3.2.0.3-bb1a276078-2024.01.08”,“ActiveProfile”:“Dave”,“TempBasalAbsoluteRate”:0.7,“TempBasalStart”:“01/04/2024 11:36pm”,“TempBasalRemaining”:20},“reservoir”:50,“clock”:“2024-04-01T22:46:11.839Z”},“openaps”:{“suggested”:{“temp”:“absolute”,“bg”:83,“tick”:“+3”,“eventualBG”:110,“targetBG”:136,“insulinReq”:0,“deliverAt”:“2024-04-01T22:46:11.569Z”,“sensitivityRatio”:0.7,“predBGs”:{“IOB”:[83,86,88,90,93,95,97,98,100,101,103,104,105,106,107,107,108,109,110,110,111,112,112,113,113,114,114,115,115,115,116,116,116,116,117,117,117,117,117,117,117,118],“ZT”:[83,84,85,87,88,89,91,92,93,95,96,98,99,101,103,105,107,108,110,112,115,117,119,121,123,125,128,130,132,134,136]},“COB”:0,“IOB”:-0.463,“reason”:“COB: 0, Dev: 0.5, BGI: 0.1, ISF: 3.1, CR: 10.8, Target: 7.6, minPredBG 6.1, minGuardBG 4.8, IOBpredBG 6.6; 6.1-6.1 in range: no temp required, temp 0.7 ~ req 0.7U/hr. “,“timestamp”:“2024-04-01T22:46:11.835Z”},“iob”:{“iob”:-0.463,“basaliob”:-0.463,“activity”:-0.0043,“time”:“2024-04-01T22:46:11.835Z”}},“uploaderBattery”:100,“isCharging”:true,“configuration”:{},“mills”:1712011571839},{”_id”:“660b392dbbfe1e00029bb181”,“created_at”:“2024-04-01T22:46:05.341Z”,“device”:“openaps://samsung SM-N976B”,“pump”:{“battery”:{“percent”:50},“status”:{“status”:“normal”,“timestamp”:“2024-04-01T22:46:05.341Z”},“extended”:{“Version”:“3.2.0.3-bb1a276078-2024.02.13”,“ActiveProfile”:“Dave”,“TempBasalAbsoluteRate”:0,“TempBasalStart”:“01/04/2024 23:41”,“TempBasalRemaining”:115},“reservoir”:50,“clock”:“2024-04-01T22:46:05.341Z”},“openaps”:{“suggested”:{“temp”:“absolute”,“bg”:83,“tick”:“+3”,“eventualBG”:93,“targetBG”:118,“insulinReq”:0,“deliverAt”:“2024-04-01T22:46:05.231Z”,“sensitivityRatio”:0.89,“predBGs”:{“IOB”:[83,85,87,89,90,91,92,92,92,91,91,89,88,86,85,84,83,82,81,80,80,79,79,79,79,79,79,79,79,80,80,80,81,81,82,83,83,83,84,84,85,85,85,85,86],“ZT”:[83,78,74,70,66,63,60,58,55,53,52,51,50,49,48,48,48,48,49,50,50,52,53,54,56,57,59,61,63,66,68,70,73,75,78,81,83,86,88,91,93,96,98,100,103,105,108,110]},“COB”:0,“IOB”:0.786,“reason”:“COB: 0, Dev: 2.5, BGI: -0.3, ISF: 2.5, CR: 10.8, Target: 6.6, minPredBG 4.4, minGuardBG 4.4, IOBpredBG 4.8; 5.2-4.4 in range: no temp required; setting current basal of 0.89 as temp. “,“duration”:30,“rate”:0.89,“timestamp”:“2024-04-01T22:46:05.338Z”},“iob”:{“iob”:0.786,“basaliob”:-1.246,“activity”:0.0213,“time”:“2024-04-01T22:46:05.338Z”}},“uploaderBattery”:61,“isCharging”:false,“configuration”:{},“mills”:1712011565341},{”_id”:“660b3928bbfe1e00029bb180”,“created_at”:“2024-04-01T22:45:59.691Z”,“device”:“openaps://samsung SM-G960F”,“pump”:{“battery”:{“percent”:50},“status”:{“status”:“normal”,“timestamp”:“2024-04-01T22:45:59.691Z”},“extended”:{“Version”:“3.1.0.3-1de236a602-2022.09.17-22:42”,“ActiveProfile”:“Daves “},“reservoir”:50,“clock”:“2024-04-01T22:45:59.691Z”},“openaps”:{“suggested”:{“temp”:“absolute”,“bg”:83,“tick”:”+3”,“eventualBG”:99,“targetBG”:113.4,“insulinReq”:0,“deliverAt”:“2024-04-01T22:45:59.620Z”,“sensitivityRatio”:1,“predBGs”:{“IOB”:[83,85,88,90,92,93,94,96,97,97,98,98,98],“ZT”:[83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83,83]},“COB”:0,“IOB”:0,“reason”:“COB: 0, Dev: 0.9, BGI: 0.0, ISF: 2.2, CR: 10.8, Target: 6.3, minPredBG 5.4, minGuardBG 4.7, IOBpredBG 5.4; 5.5-5.4 in range: no temp required; setting current basal of 1 as temp. . Setting neutral temp basal of 1U/hr”,“duration”:30,“rate”:1,“timestamp”:“2024-04-01T22:45:59.687Z”},“iob”:{“iob”:0,“basaliob”:0,“activity”:0,“time”:“2024-04-01T22:45:59.687Z”}},“uploaderBattery”:100,“configuration”:{},“mills”:1712011559691},{“_id”:“660b3923bbfe1e00029bb17f”,“device”:“samsung SM-N975F”,“uploader”:{“battery”:100,“type”:“PHONE”},“created_at”:“2024-04-01T22:45:55.533Z”,“utcOffset”:0,“mills”:1712011555533},{“_id”:“660b3922bbfe1e00029bb17e”,“device”:“samsung SM-N976B”,“uploader”:{“battery”:61,“type”:“PHONE”},“created_at”:“2024-04-01T22:45:54.286Z”,“utcOffset”:0,“mills”:1712011554286},{“_id”:“660b3866bbfe1e00029bb17c”,“created_at”:“2024-04-01T22:42:26.996Z”,“device”:“openaps://samsung SM-X906B”,“pump”:{“battery”:{“percent”:50},“status”:{“status”:“normal”,“timestamp”:“2024-04-01T22:42:26.996Z”},“extended”:{“Version”:“3.1.0.3-1de236a602-2022.09.17-22:42”,“ActiveProfile”:“Dave”},“reservoir”:50,“clock”:“2024-04-01T22:42:26.996Z”},“openaps”:{“suggested”:{“reason”:“Error: CGM data is unchanged for the past ~45m. Temp 0 <= current basal 1U/hr; doing nothing. “,“timestamp”:“2024-04-01T22:42:26.994Z”},“iob”:{“iob”:1.421,“basaliob”:0,“activity”:0.0262,“time”:“2024-04-01T22:42:26.994Z”}},“uploaderBattery”:85,“configuration”:{},“mills”:1712011346996},{”_id”:“660b3809bbfe1e00029bb17a”,“created_at”:“2024-04-01T22:41:12.072Z”,“device”:“openaps://samsung SM-N975F”,“pump”:{“battery”:{“percent”:50},“status”:{“status”:“normal”,“timestamp”:“2024-04-01T22:41:12.072Z”},“extended”:{“Version”:“3.2.0.3-bb1a276078-2024.01.08”,“ActiveProfile”:“Dave”,“TempBasalAbsoluteRate”:0.7,“TempBasalStart”:“01/04/2024 11:36pm”,“TempBasalRemaining”:25},“reservoir”:50,“clock”:“2024-04-01T22:41:12.072Z”},“openaps”:{“suggested”:{“temp”:“absolute”,“bg”:80,“tick”:“+2”,“eventualBG”:104,“targetBG”:136,“insulinReq”:0,“deliverAt”:“2024-04-01T22:41:11.776Z”,“sensitivityRatio”:0.7,“predBGs”:{“IOB”:[80,82,84,86,87,89,91,92,93,95,96,97,98,99,100,101,102,103,103,104,105,105,106,107,107,108,108,108,109,109,110,110,110,110,111,111,111,111,111,112],“ZT”:[80,81,82,84,85,86,88,89,90,92,93,95,97,98,100,102,104,106,108,110,112,114,117,119,121,123,126,128,130,132,135]},“COB”:0,“IOB”:-0.485,“reason”:“COB: 0, Dev: 0.3, BGI: 0.1, ISF: 3.1, CR: 10.8, Target: 7.6, minPredBG 5.7, minGuardBG 4.6, IOBpredBG 6.2; Eventual BG 5.8 > 5.0 but Min. Delta 2.00 < Exp. Delta 0.1, temp 0.7 ~ req 0.7U/hr. “,“timestamp”:“2024-04-01T22:41:12.068Z”},“iob”:{“iob”:-0.485,“basaliob”:-0.485,“activity”:-0.0043,“time”:“2024-04-01T22:41:12.068Z”}},“uploaderBattery”:100,“isCharging”:true,“configuration”:{},“mills”:1712011272072},{”_id”:“660b3801bbfe1e00029bb178”,“created_at”:“2024-04-01T22:41:05.413Z”,“device”:“openaps://samsung SM-N976B”,“pump”:{“battery”:{“percent”:50},“status”:{“status”:“normal”,“timestamp”:“2024-04-01T22:41:05.413Z”},“extended”:{“Version”:“3.2.0.3-bb1a276078-2024.02.13”,“ActiveProfile”:“Dave”,“TempBasalAbsoluteRate”:0,“TempBasalStart”:“01/04/2024 23:06”,“TempBasalRemaining”:85},“reservoir”:50,“clock”:“2024-04-01T22:41:05.413Z”},“openaps”:{“suggested”:{“temp”:“absolute”,“bg”:80,“tick”:“+2”,“eventualBG”:80,“targetBG”:118,“insulinReq”:0,“deliverAt”:“2024-04-01T22:41:05.281Z”,“sensitivityRatio”:0.89,“predBGs”:{“IOB”:[80,81,83,84,84,85,85,84,84,83,82,80,79,77,75,74,72,71,70,69,69,68,68,67,67,67,67,67,67,67,67,67,68,68,69,69,70,70,70,71,71,71,72,72,72,72,72,73],“ZT”:[80,75,70,66,62,58,55,52,49,47,45,44,42,41,41,40,40,40,40,41,42,42,43,45,46,48,49,51,53,55,58,60,62,65,67,70,73,75,78,80,83,85,88,90,93,95,97,100]},“COB”:0,“IOB”:0.97,“reason”:“COB: 0, Dev: 2.4, BGI: -0.3, ISF: 2.5, CR: 10.8, Target: 6.6, minPredBG 3.7, minGuardBG 3.7, IOBpredBG 4.1; Eventual BG 4.4 < 4.7, setting 120m zero temp. “,“duration”:120,“rate”:0,“timestamp”:“2024-04-01T22:41:05.409Z”},“iob”:{“iob”:0.97,“basaliob”:-1.22,“activity”:0.0229,“time”:“2024-04-01T22:41:05.409Z”}},“uploaderBattery”:61,“isCharging”:false,“configuration”:{},“mills”:1712011265413},{”_id”:“660b3814bbfe1e00029bb17b”,“created_at”:“2024-04-01T22:40:59.251Z”,“device”:“openaps://samsung SM-G960F”,“pump”:{“battery”:{“percent”:50},“status”:{“status”:“normal”,“timestamp”:“2024-04-01T22:40:59.251Z”},“extended”:{“Version”:“3.1.0.3-1de236a602-2022.09.17-22:42”,“ActiveProfile”:“Daves “},“reservoir”:50,“clock”:“2024-04-01T22:40:59.251Z”},“openaps”:{“suggested”:{“temp”:“absolute”,“bg”:80,“tick”:”+2”,“eventualBG”:92,“targetBG”:113.4,“insulinReq”:0,“deliverAt”:“2024-04-01T22:40:59.185Z”,“sensitivityRatio”:1,“predBGs”:{“IOB”:[80,82,84,85,86,88,89,89,90,91,91,91,91],“ZT”:[80,80,80,80,80,80,80,80,80,80,80,80,80,80,80,80,80,80,80,80,80,80,80,80,80,80,80,80,80,80,80,80,80,80,80,80,80,80,80,80,80,80,80,80,80,80,80,80]},“COB”:0,“IOB”:0,“reason”:“COB: 0, Dev: 0.7, BGI: 0.0, ISF: 2.2, CR: 10.8, Target: 6.3, minPredBG 5.1, minGuardBG 4.6, IOBpredBG 5.1; 5.1-5.1 in range: no temp required; setting current basal of 1 as temp. . Setting neutral temp basal of 1U/hr”,“duration”:30,“rate”:1,“timestamp”:“2024-04-01T22:40:59.250Z”},“iob”:{“iob”:0,“basaliob”:0,“activity”:0,“time”:“2024-04-01T22:40:59.250Z”}},“uploaderBattery”:100,“configuration”:{},“mills”:1712011259251}]

Nothing here seems to be mentioning about Sensor age of insertion or how many days, unless it only buts a time stamp on it the day I inserted it which was 29th March 2024 not sure how to do I date onto the end of:

https://SECRET-upload-0-guest.t1pal.com/api/v1/devicestatus/

to see if it can find anything to do with sensor