Frontend Panel for Diabetics using a Dexcom CGM

As an example of the issue I’m seeing I tested the below code for just the a1c value for each child, and as noted before whichever child is first in the list their value does not get displayed while the second child in the order a1c shows every time. I feel like there is some variable I’m missing or maybe it’s just the way code is read/fed into the system that parts of it don’t work. The code for the Card’s are identical with the exception of the “entity” which is specific to each child.

I’m hoping whatever I’m not seeing is blatantly obvious to one of you.

- platform: average
  name: 'Child1 Glucose Avg 90d'
  duration:
    days: 90
  entities:
    - sensor.dexcom_child1_glucose_value

- platform: template
  sensors:
    child1_hba1c_value:
      entity_id: sensor.child1_glucose_avg_90d
      value_template: >
        {% set a = ( states("sensor.child1_glucose_avg_90d") | float + 46.7 ) %}
        {% set a1c = (a / 28.7) %}
        {{a1c | round(2) }}

- platform: average
  name: 'Child2 Glucose Avg 90d'
  duration:
    days: 90
  entities:
    - sensor.dexcom_child2_glucose_value 

- platform: template
  sensors:
   child2_hba1c_value:
      entity_id: sensor.child2_glucose_avg_90d
      value_template: >
        {% set a = ( states("sensor.child2_glucose_avg_90d") | float + 46.7 ) %}
        {% set a1c = (a / 28.7) %}
        {{a1c | round(2) }}

Card example only difference would be the entity line being child1 vs child2

color_thresholds:
  - color: '#039BE5'
    value: 2
  - color: '#0DA035'
    value: 5
  - color: '#E0B400'
    value: 10
  - color: '#E45E65'
    value: 15
detail: 1
entities:
  - entity: sensor.child1_hba1c_value
    show_fill: false
    show_state: true
    smoothing: true
hours_to_show: 2160
icon: mdi:water
line_width: 3
name: HbA1C Avg - 90 days
show:
  graph: line
type: custom:mini-graph-card

I have this working now but I’m a little confused as to why. Originally when setting up the templates for my kids I used two separate yaml files and added them into the configuration with include commands. This is where I was having problems and only the second child data would show. I decided to combine them into a single script just to see if it would work and it does now. Both kids information is now showing. I’m a little confused as to why includes would cause an issue, but maybe I just need to read up on them more to make sure I fully understand them.

#seperate templates for each child - 1st child data would not show. 
#sensor: !include sensors_child1.yaml
#sensor: !include sensors_child2.yaml

#current setup in configuration.yaml using a combined template for both kids. 
sensor: !include Dexcom_combined.yaml

In short, I love the interface and all the info it shows me, and I’m happy that it does work for more then one diabetic in the house, just requires minor adjustments for the entities to make them unique.

You have 2 kids with diabetes? Wow that will be hard going. Good luck is all I can say.

1 Like

Great work on this, thanks!
Would you happen to know how to use a sensor template to calculate the HbA1c in xx mmol/mol IFCC format please?

eg 7.4 % NGSP = 57 mmol/mol IFCC = 166 mg/dL eAG = 9.2 mmol/l eAG.

I’m after a template that gives me the 57 result above.

I know your question was a bit ago, but I noticed no one answered you. You can only have one sensor: declaration in the configuration.yaml file. The following is what I have in my configuration.yaml file so that I have a single file that contains all of my sensors:

sensor: !include sensors.yaml

You could take all of the content of your Dexcom_combined.yaml file, include any other sensors you wish, and merge them into a single sensor.yaml file (if you like). You can find more information in the docs at Splitting Up the Configuration. I hope this helps.

Hi, I’ve been using this code for a while and now the cgm sensor/transmitter expires in templates which shows the remaining days are now showing as unavailable. Has this happened to anyone else, and what can I do to resolve the issue?

I have been meaning to look into that…

I’ve just now been alerted of this. API might’ve been tweaked again, looking into it today!

I have been trying to integrate this to track my wife’s glucose levels, but have had nothing bu issues. I can get the sensors in the configuration integrated, and they show up as expected. Creating the card, however, I keep getting errors. At first, I was getting simple YAML errors, but now I am getting the following error:

Your configuration is not valid: i: At path: views – Expected an array value, but received: undefined.

Any ideas where the issue could be?

Hi there - the custom Dexcom component is no longer available, is that correct?

Yes. Remove the custom component then…

how do I get a nightscout account? I just got the Dexcom G6 and have set it up with HA :slight_smile:

https://nightscout.github.io/

Great topic!
I would like to share my dashboard, using Medtronic Guardian but I am sure it can be also used for Dexcom as well. With some automations, Home Assistant greatly helps me to notify me of things that Medtronic does not do:

  • When in the morning 7:30 my insulin cartridge is less than 30 units, it will send me a notification to consider to change it. (Always annoying when it is empty just before end of the workday)
  • It will send me a notification in the morning when my sensor needs to be exchanged.
  • Shows my SG curves for the last 4 days in one graph
  • Shows my 24hrs TiR for this week and the week before
  • Keeps a live overview of my (TiR) score for several periods in an attractive “Healt Watch like” view.

All four charts are made with the Apex Charts Card.

3 Likes

You need to have Apex Charts Card installed. Assume you know how to do that.

Code for generating SG curves:

type: custom:apexcharts-card
update_interval: 1min
header:
  show: true
  title: Guardian SG Bart
  show_states: false
  colorize_states: true
graph_span: 1d
span:
  start: day
yaxis:
  - min: 0
    max: 20
    decimals: 1
    apex_config:
      tickAmount: 5
      forceNiceScale: true
apex_config:
  legend:
    show: true
  chart:
    height: 300px
  annotations:
    position: back
    yaxis:
      - 'y': 4
        y2: 10
        strokeDashArray: 3
        fillColor: green
        borderColor: '#00000000'
series:
  - entity: sensor.last_glucose_level_mmol_bart
    stroke_width: 5
    name: Vandaag
    curve: straight
    extend_to: now
    show:
      legend_value: false
  - entity: sensor.last_glucose_level_mmol_bart
    stroke_width: 3
    name: Gisteren
    curve: smooth
    offset: '-1d'
    opacity: 0.75
    show:
      legend_value: false
    group_by:
      func: median
      duration: 30min
  - entity: sensor.last_glucose_level_mmol_bart
    stroke_width: 1.5
    name: Eergisteren
    curve: smooth
    offset: '-2d'
    opacity: 0.75
    show:
      legend_value: false
    group_by:
      func: median
      duration: 60min
  - entity: sensor.last_glucose_level_mmol_bart
    stroke_width: 1
    name: Drie dagen
    curve: smooth
    offset: '-3d'
    opacity: 0.75
    show:
      legend_value: false
    group_by:
      func: median
      duration: 60min
  - entity: sensor.last_glucose_level_mmol_bart
    stroke_width: 1
    name: Vier dagen
    curve: smooth
    offset: '-4'
    opacity: 0.75
    show:
      legend_value: false
    group_by:
      func: median
      duration: 60min
now:
  show: true
  color: orange
  label: Nu

Code for generating daily TiR column chart:

type: custom:apexcharts-card
update_interval: 30min
header:
  show: true
  title: Dagelijkse Time-in-Range
  show_states: false
  colorize_states: true
experimental:
  color_threshold: true
graph_span: 1w
span:
  start: week
yaxis:
  - min: 25
    max: 100
apex_config:
  dataLabels:
    enabled: true
  plotOptions:
    bar:
      columnWidth: 60%
  fill:
    opacity: 0.6
  legend:
    show: true
  xaxis:
    type: datetime
    labels:
      datetimeFormatter:
        month: ddd
        day: ddd
  chart:
    height: 300px
  annotations:
    position: back
    yaxis:
      - 'y': 70
        y2: 100
        strokeDashArray: 3
        fillColor: green
        borderColor: '#00000000'
      - 'y': 70
        y2: 50
        strokeDashArray: 3
        fillColor: yellow
        borderColor: '#00000000'
series:
  - entity: sensor.bart_tir_1d
    stroke_width: 1
    type: column
    name: Deze week
    curve: stepline
    extend_to: now
    show:
      legend_value: false
    group_by:
      func: last
      duration: 1d
  - entity: sensor.bart_tir_1d
    stroke_width: 1
    type: column
    name: Vorige week
    curve: stepline
    extend_to: now
    offset: '-1week'
    show:
      legend_value: false
    group_by:
      func: median
      duration: 1d

Code for radial Smart Watch like overview:

type: custom:apexcharts-card
update_interval: 15min
view_layout:
  position: sidebar
apex_config:
  legend:
    show: true
    floating: true
    fontSize: 16px
    position: left
    offsetX: 0
    offsetY: 10
    labels:
      useSeriesColors: true
    markers:
      size: 0
    itemMargin:
      vertical: 3
  chart:
    height: 370px
  plotOptions:
    radialBar:
      offsetY: 0
      startAngle: 0
      endAngle: 270
      hollow:
        margin: 5,
        size: 30%
        background: transparent
      dataLabels:
        name:
          show: false
        value:
          show: false
header:
  title: Time in Range
  show: true
  show_states: false
  colorize_states: false
chart_type: radialBar
experimental:
  color_threshold: true
series:
  - entity: sensor.bart_tir_maand
    name: 30d
    color: '#9B59B6'
    float_precision: 0
  - entity: sensor.bart_tir_14d
    name: 14d
    color: '#E74C3C'
    float_precision: 0
  - entity: sensor.bart_tir_7d
    name: 7d
    color: '#3498DB'
    float_precision: 0
  - entity: sensor.bart_tir_1d
    name: 1d
    color: '#FF9800'
    float_precision: 0

On the top is a horizontal stack using mushroom entity cards.

3 Likes

Nice @Bart_Huitsing, I’m curious how you obtain and store the time in range data in home assistant. Are you using separate template and statistics sensors?

Curious about this too Bart. Would these be sensors of the Medtronic Guardian or are these manually created sensors. @Bart_Huitsing

Did you ever find a solution to this?

I have been thinking on this. I don’t have code for you, but a method may be like this:

  1. With a sensor for cgm, say sensor.cgm, create a template sensor which has three states, low, inrange and high. Like
If <4 return low, elseif ≥ 4 < 10 return inrange else return high
  1. Use History Stats - Home Assistant to get time in each category.

If using mg/dl instead of mmol/L the figures will be different.

1 Like

This is something I am using now @mhoogenbosch


  - trigger:
    - id: to_valid
      for:
        seconds: 5
      platform: state
      not_to:
      - unknown
      - unavailable
      entity_id: sensor.dexcom_glucose_value
    binary_sensor:
    - unique_id: dexcom_glucose_in_range
      name: dexcom_glucose_in_range
      state: >
        {%- set v = ( states("sensor.dexcom_glucose_value") | float ) -%}
        {%- set h = ( states("input_number.dexcom_range_upper") | float ) -%}
        {%- set l = ( states("input_number.dexcom_range_lower") | float ) -%}
        {%- set b = (v >= l and v <= h) -%}
        {{b}}

And I just discovered this new device when I upgraded to 2023.9.0

1 Like