Any Diabetics in the house? Got a template question

Ok, so I’m monitoring my glucose levels via a dexcom CGM custom component. That works great! But now I’m trying to calculate my HbA1C percentage. My math is a bit rusty… does this seem right?

FYI, its in moml/L

``````
- platform: template
sensors:
jons_hba1c_value:
entity_id: sensor.glucose_avg_90d
value_template: >
{% set a = ( states("sensor.glucose_avg_90d") | float * 18 ) | float %}
{% set b = ((a + 46.7) / 28.7) | float %}
{% set c = ((b * 18) + 46.7) | float %}
{% set hba1c = ((c / 28.7)) | float | round(2) %}
{{hba1c}}

``````

I haven’t been tracking for 90 days yet, but the currrent average is 6.96 moo/L and those calculations above spit out an HbA1C value of 5.39%. I’m not sure if that’s correct.

So I did some quick research on your problem. First, besides the initial float for converting the state of sensor.glucose_avg_90d to a real number all the rest of the floats are not necessary. Second, the hba1c is the value of b. I don’t think the rest of the template is necessary as it just reapplies the same calculation to the hba1c value you just solved for which seems wrong. So a 90 day average of 7 mmol/l should result in an ca1c of 6.02. Your example of 6.96 mmol/l results in 5.99 which is the value of b.

Thanks. Yeah i don’t know why i had all those Floats in there; probably an aftermath of my cutting and pasting habbit. But the problem i actually had was the math itself. The equation i was following was for the new standard “eAG” from “HBA1C”. That’s why everything was so screwed up. So now i have this to just calculate the HbA1C. Then ill either add to this template to do the final eAG convention or just display both with another sensor template.

``````
{% set a = ( states("sensor.glucose_avg_90d") | float + 2.59 ) %}
{% set a1c = (a / 1.59) %}
{{a1c}}

``````

My mom/L average over 90 days is 7.27. This results in a HbA1C value of 6.2%. Which seems about right according to online calculators for it.

eAG would be: 1.59 x HbA1C − 2.59 = eAG
Which is a stupid unit of measurement since it’s basically the exact same as the average glucose over 90 days value. Doctors love to complicate things

2 Likes

How are you displaying the a1c? I’d like to also use it in an automation but am unsure how.

``````    action:
- service: notify.mobile_app_iphone
data_template:
message: |
A1C is  {% set a = ( states("sensor.dexcom_glucose_avg_90d") | float + 2.59 ) %}
{% set a1c = (a / 1.59) %}
{{a1c | round(2)}}
``````

There’s a 90 day “average” sensor which that template pulls from and does the math. Look for the average component and set that up. Then the code you posted above can be adapted with your sensor names.

But as you probably know, you can’t get an accurate A1C from BG data alone; a blood test is required for accuracy. Also, this is only truly a decent reference to your A1C after at least 60 days. Anything before that isn’t very accurate as an A1C level