Using Continuous Glucose Monitor (CGM) Data

CGM is primarily used by Type 1 Diabetics to monitor their blood sugar levels in real-time. There are a couple of threads dedicated to getting CGM data into HA (And there are some discussions in those threads around automation).

But, I wanted to start a new thread dedicated to using that data. I plan to update this thread as I discover new ways to utilize my data in HA. My first project is to begin graphing data in a useful way to keep an eye on my blood sugar level.

I came across the mini-graph-card custom Lovelace card and thought this would be a good place to start. It allows you to generate some pretty nifty graphs for displaying CGM data. I’ve been playing with it for 30 min or so and this is what I’ve come up with so far:

Here’s the code for some for the two different types of cards I’ve used above

Avg per day:

type: 'custom:mini-graph-card'
entities:
  - entity: sensor.bryan_cgm_sgv
name: Avg CGM Value Per Day
aggregate_func: avg
group_by: date
hours_to_show: 168
show:
  graph: bar
  labels: true
color_thresholds:
  - color: '#039BE5'
    value: 60
  - color: '#0da035'
    value: 100
  - color: '#e0b400'
    value: 150
  - color: '#e45e65'
    value: 200

Results graph:

type: 'custom:mini-graph-card'
entities:
  - sensor.bryan_cgm_sgv
name: CGM Graph - 36 Hours
hours_to_show: 36
points_per_hour: 60
show:
  labels: true
color_thresholds:
  - value: 60
    color: '#c0392b'
  - value: 75
    color: '#08ff2d'
  - value: 150
    color: '#f7ff08'
  - value: 200
    color: '#ff3508'

Any other diabetics doing cool stuff with your CGM data in HA?

Cheers!
-Bryan

11 Likes

Great healthcare component integration I want to try this item

Wow. Nightscout is still around? I assumed it would go away when the FDA alllowed the CGM companies to send the data to phones. I am happy to see it is still being used!

I contributed to the Nightscout project in the summer of 2014, when my neighbor asked me to setup a Nightscout website for them to monitor their young son’s CGM numbers. I made lots of user interface contributions (mobile friendly, settings menu so users could change settings easily on the front end, and other usability improvements), and I started the API.

7 Likes

Believe me you don’t want type 1 diabetes!

2 Likes

Hey Bryan_Fleming! Thank you for all of this information!!! I had setup my son’s Dexcom through HA some time ago, but never this neatly and cleanly. I have adopted your code, and am looking at your mini graphs and I will be pulling them in toofor sure! Can you post code for the other graphs above? Also, I get the CGM direction data item, but what is the CGM Trend? Are they redundant?

Thank you!!!

Here you go, this is the full code for the Lovelace page I used in my example above. This also includes an update that displays the time since the last API poll. Take a look at THIS post if you are interested in implementing that.

  - badges: []
    cards:
      - detail: 100
        entity: sensor.bryan_cgm_sgv
        graph: line
        hours_to_show: 6
        name: Bryan CGM
        theme: default
        type: sensor
        unit: mg/dl
      - entity: sensor.bryan_cgm_direction
        name: CGM Direction
        type: sensor
      - entity: sensor.bryan_cgm_trend
        name: CGM Trend
        type: sensor
      - entity: sensor.bryan_cgm_time
        type: sensor
      - aggregate_func: avg
        color_thresholds:
          - color: '#039BE5'
            value: 60
          - color: '#0da035'
            value: 100
          - color: '#e0b400'
            value: 150
          - color: '#e45e65'
            value: 200
        entities:
          - entity: sensor.bryan_cgm_sgv
        group_by: date
        hours_to_show: 168
        name: Avg CGM Value Per Day
        show:
          graph: bar
          labels: true
        type: 'custom:mini-graph-card'
      - color_thresholds:
          - color: '#c0392b'
            value: 60
          - color: '#08ff2d'
            value: 75
          - color: '#f7ff08'
            value: 150
          - color: '#ff3508'
            value: 200
        entities:
          - sensor.bryan_cgm_sgv
        hours_to_show: 12
        name: CGM Graph - 12 Hours
        points_per_hour: 60
        show:
          labels: true
        type: 'custom:mini-graph-card'
      - color_thresholds:
          - color: '#c0392b'
            value: 60
          - color: '#08ff2d'
            value: 75
          - color: '#f7ff08'
            value: 150
          - color: '#ff3508'
            value: 200
        entities:
          - sensor.bryan_cgm_sgv
        hours_to_show: 36
        name: CGM Graph - 36 Hours
        points_per_hour: 60
        show:
          labels: true
        type: 'custom:mini-graph-card'
      - color_thresholds:
          - color: '#c0392b'
            value: 60
          - color: '#08ff2d'
            value: 75
          - color: '#f7ff08'
            value: 150
          - color: '#ff3508'
            value: 200
        entities:
          - sensor.bryan_cgm_sgv
        hours_to_show: 168
        name: CGM Graph - 7 Days
        points_per_hour: 30
        show:
          labels: true
        type: 'custom:mini-graph-card'
      - aggregate_func: avg
        color_thresholds:
          - color: '#039BE5'
            value: 2
          - color: '#0da035'
            value: 4
          - color: '#e38f09'
            value: 6
        entities:
          - entity: sensor.bryan_cgm_time
        hours_to_show: 1
        name: Min Since Last Poll
        points_per_hour: 60
        show:
          graph: line
          labels: true
        type: 'custom:mini-graph-card'
    path: test
    title: CGM Info
    url: /local/mini-graph-card/dist/mini-graph-card-bundle.js
3 Likes

Thanks @Bryan_Fleming.

This is awesome! Currently just running an iframe of Nightscout for my daughter’s readings at the moment and would love to clean things up a bit more.

3 Likes

Hey diabetics!

So I was very inspired by what you are all doing here. I tried everything out and got a bit frustrated at home assistants sensor based input. As a sensor, if there isn’t a constant feed, it will show you a straight line which is kind of meh.

So I am making a very customizable, animated and minimal graph card using amcharts and pulling data directly from nightscout. This also gives me complete control over how it looks and what I can put on it. Will release the card soon. It looks a bit like this right now:


I will do one for insulin and carbs, one for sugar levels and one that combines both. Let me know if any of you would want to use this and if you have any suggestions?

Cheers!

7 Likes

Hi, I’m also using Nightscout to monitor my daughter CGM data. I haven’t used HA to automate this info just yet. But anyway, I wanted to thank the OP, @Bryan_Fleming, @lukevink and all of you to post about your findings. Fully appreciated!! Thank you!

3 Likes

A tip for medtronic pumpers! For anyone who is also using a 600 series medtronic - I highly suggest getting a raspberry pi and doing this:

I use a 670g and quickly realised using an android phone wasn’t the most… continuous idea. You basically have to charge it every day which defeats the purpose. Ideally you want your home just to sense your sugar level and be done with it. So I have now switched to using a raspberry pi, with windows IOT and a spare meter. This is the most continuous solution I have found so far for the 600 series.

For anyone using a tandem pump - I envy you. Someone tell them to launch it already in the netherlands :smiley:

Do you carry the rpi around with you?

If he did, the batteries to keep if running more than a day would be pretty heavy/bulky compared to a phone. I assume he’s using it as a base station. But would be interested in some details,
Feestyle libre is convenient to carry, uses nfc but stores 8hrs of data (pros/cons)

Yeah I have a freestyle libre with a miaomiao2. The freestyle nfc’s to the miaomiao and the miaomiao bluetooths to the phone. That way I get CGM (5 minute intervals). And if you are out of range of your phone (or it is flat) it catches up via the data stored on the libre. My phone lasts 2-3 days on a charge and I leave it on even when charging. It charges next to my bed so it stays in touch with miaomiao except when in a different room.

The phone uploads to nightscout. HA downloads from nightscout.

1 Like

Slick :+1:

Yeah but there is a long chain of information and a lot to break/go wrong. Better than finger pricking though.

Only thing worse than finger pricking is injections :face_with_symbols_over_mouth:

Yeah I still do that, haven’t got a pump as yet.

Hi @nickrout you are using exactly the same setup as my daughter (Free+miaomiamo+nightscout+no_pump), although she does not use miaomiamo always although I would like her to do so (she’s 15 now). BTW, what software do you use for getting data from miao miao and uploading it to Nightscout, maybe Glimp??

I use tomato (strange name for software! ) I think it is made by the same people as miaomiao. http://tomato.cool

Hey there so no. The intent was to have a continuous solution that I didn’t need to charge or do anything to. I was using an android phone and charging it each day, but that was silly. So I switched to a raspberry pi uploader which was tricky to install but finally got it working. Now it works like a charm :slight_smile:

The intent was to have something permanently at home that I don’t carry around with me. My Medtronic pump has the graph on it anyways.