I have these values too. Thanks. I’m looking to a HBA1C value in mmol/mol.
I found the following: hba1c-omrekentabel.pdf (diabetesfonds.nl) which show how to calculate values.
I’m using this for A1C - seems to be petty accurate
sensor:
- platform: statistics
unique_id: dexcom_glucose_90d_average_linear
name: 'dexcom_glucose_90d_average_linear'
state_characteristic: average_linear
max_age:
days: 90
# This entity_id is from the Dexcom Custom Component
entity_id: sensor.dexcom_glucose_value
# Calculate HbA1C % based off 90 day BG average sensor above
# NOTE: These calculations are based on HbA1C from mmol/L values.
# for HbA1C based off MG/DL
template:
# Calculate HbA1C % based off 90 day BG average sensor above
# NOTE: These calculations are based on HbA1C from mmol/L values.
# for HbA1C based off MG/DL
- sensor:
- unique_id: dexcom_a1c_value
name: dexcom_a1c_value
unit_of_measurement: "%"
state_class: measurement
availability: '{{ has_value("sensor.dexcom_glucose_90d_average_linear") }}'
state: >
{%- set a = ( states("sensor.dexcom_glucose_90d_average_linear") | float + 2.59 ) -%}
{%- set a1c = (a / 1.59) -%}
{{a1c}}
I just wanted to share a custom dashboard card that I designed to display Dexcom values. The code should be fairly easy to replicate, just replace your Dexcom sensor entity name and install custom button-card via HACS.
Custom button-card:
You will also need these icons (upload them into /www/icons/): Icons
type: custom:button-card
entity: sensor.dexcom_glucose_value
show_entity_picture: false
show_last_changed: false
show_icon: false
show_name: false
name: |
[[[
return `<span>${(states['sensor.dexcom_glucose_value'].state)} mg/dL</span>`
]]]
styles:
card:
- border-radius: 2%
- padding: 2.5%
- color: ivory
- font-size: 12px
- border-width: >
[[[ if (states['sensor.dexcom_glucose_status'].state === 'In Range')
return '0px';
else return '2px';
]]]
- border-color: >
[[[ if (states['sensor.dexcom_glucose_status'].state === 'Very Low')
return 'red';
if (states['sensor.dexcom_glucose_status'].state === 'Low') return 'orange';
if (states['sensor.dexcom_glucose_status'].state === 'High') return 'orange';
if (states['sensor.dexcom_glucose_status'].state === 'Very High') return 'red';
else return 'none';
]]]
grid:
- grid-template-areas: '"img img" "trend trend" "update update" "range range"'
- grid-template-columns: 1fr 1fr
- grid-template-rows: 1fr min-content min-content min-content
img_cell:
- justify-content: middle
- align-items: start
- margin: none
- padding-bottom: 5px
icon:
- width: 15%
- margin-top: 0%
- color: red
- padding-bottom: 0px
custom_fields:
state:
- align-self: start
- justify-self: end
- font-size: 17px
- padding-bottom: 5px
update:
- font-family: helvetica neue, helvetica, Arial
- font-weight: 500
- font-size: 15px
- color: grey
- align-self: middle
- justify-content: middle
- padding-bottom: 5px
- margin-top: 0px
trend:
- font-family: helvetica neue, helvetica, Arial
- color: rgba(255, 255, 255, 0.7)
- font-size: 15px
- font-weight: 300
- text-align: center
- padding-bottom: 5px
range:
- font-family: helvetica neue, helvetica, Arial
- font-size: 15px
- font-weight: 500
- text-align: center
- line-height: 30px
- color: white
- background-color: |
[[[
if ((states['sensor.dexcom_glucose_status'].state === 'Very Low'))
return "red";
if ((states['sensor.dexcom_glucose_status'].state === 'Low'))
return "orange";
if ((states['sensor.dexcom_glucose_status'].state === 'High'))
return "orange";
if ((states['sensor.dexcom_glucose_status'].state === 'Very High'))
return "red";
else
return "none";
]]]
img:
- font-weight: bold
- font-size: 15px
- color: >
[[[ if (states['sensor.dexcom_glucose_status'].state === 'In Range')
return 'grey';
if ((states['sensor.dexcom_glucose_status'].state === 'Low'))
return "orange";
if ((states['sensor.dexcom_glucose_status'].state === 'High'))
return "orange";
else return 'red';
]]]
- align-self: middle
- justify-content: middle
- padding-bottom: 65px
custom_fields:
trend: |
[[[ if (states['input_number.dexcom_change'].state > 0)
return `${(states['sensor.dexcom_glucose_trend'].state)} (+${Math.round(states['input_number.dexcom_change'].state)})`;
return `${(states['sensor.dexcom_glucose_trend'].state)} (${Math.round(states['input_number.dexcom_change'].state)})`;
]]]
update: |
[[[ return `${(states['sensor.dexcom_last_update'].state)}`; ]]]
range: |
[[[
if ((states['sensor.dexcom_glucose_status'].state === 'Very Low'))
return "VERY LOW";
if ((states['sensor.dexcom_glucose_status'].state === 'Low'))
return "LOW";
if ((states['sensor.dexcom_glucose_status'].state === 'High'))
return "HIGH";
if ((states['sensor.dexcom_glucose_status'].state === 'Very High'))
return "VERY HIGH";
if ((states['sensor.dexcom_glucose_status'].state === 'In Range'))
return "IN RANGE";
else
return "N/A";
]]]
img: |
[[[
if (states['sensor.dexcom_glucose_trend'].state == "steady")
return `<img src=/local/icons/dexcom-steady.png
style="width: 170px; height: 170px; color: #00def;">
</ha-icon><span style="font-size:30px; margin-top:-111px; display:block;">${(states['sensor.dexcom_glucose_value'].state)}</span><span style="font-size:13px; margin-top:0px; display:block;">mg/dL</span>`;
if (states['sensor.dexcom_glucose_trend'].state == "rising slightly")
return `<img src=/local/icons/dexcom-risingslightly.png
style="width: 170px; height: 170px; color: #00def;">
</ha-icon><span style="font-size:30px; margin-top:-111px; display:block;">${(states['sensor.dexcom_glucose_value'].state)}</span><span style="font-size:13px; margin-top:0px; display:block;">mg/dL</span>`;
if (states['sensor.dexcom_glucose_trend'].state == "falling slightly")
return `<img src=/local/icons/dexcom-fallingslightly.png
style="width: 170px; height: 170px; color: #00def;">
</ha-icon><span style="font-size:30px; margin-top:-111px; display:block;">${(states['sensor.dexcom_glucose_value'].state)}</span><span style="font-size:13px; margin-top:0px; display:block;">mg/dL</span>`;
if (states['sensor.dexcom_glucose_trend'].state == "falling")
return `<img src=/local/icons/dexcom-falling.png
style="width: 170px; height: 170px; color: #00def;">
</ha-icon><span style="font-size:30px; margin-top:-111px; display:block;">${(states['sensor.dexcom_glucose_value'].state)}</span><span style="font-size:13px; margin-top:0px; display:block;">mg/dL</span>`;
if (states['sensor.dexcom_glucose_trend'].state == "rising")
return `<img src=/local/icons/dexcom-rising.png
style="width: 170px; height: 170px; color: #00def;">
</ha-icon><span style="font-size:30px; margin-top:-111px; display:block;">${(states['sensor.dexcom_glucose_value'].state)}</span><span style="font-size:13px; margin-top:0px; display:block;">mg/dL</span>`;
if (states['sensor.dexcom_glucose_trend'].state == "falling quickly")
return `<img src=/local/icons/dexcom-fallingquickly1.png
style="width: 170px; height: 170px; color: #00def;">
</ha-icon><span style="font-size:30px; margin-top:-111px; display:block;">${(states['sensor.dexcom_glucose_value'].state)}</span><span style="font-size:13px; margin-top:0px; display:block;">mg/dL</span>`;
if (states['sensor.dexcom_glucose_trend'].state == "rising quickly")
return `<img src=/local/icons/dexcom-risingquickly1.png
style="width: 170px; height: 170px; color: #00def;">
</ha-icon><span style="font-size:30px; margin-top:-111px; display:block;">${(states['sensor.dexcom_glucose_value'].state)}</span><span style="font-size:13px; margin-top:0px; display:block;">mg/dL</span>`;
return `<img src=/local/icons/dexcom-steady.png
style="width: 170px; height: 170px; color: #00def;">
</ha-icon><span style="font-size:30px; margin-top:-111px; display:block;">N/A</span><span style="font-size:13px; margin-top:0px; display:block;">mg/dL</span>`;
]]]
tap_action:
action: none
Supporting template sensors:
Paste these into your template.yaml file
- sensor:
- name: "Dexcom Glucose Status"
icon: mdi:diabetes
state: >-
{% if (states('sensor.dexcom_glucose_value')|float) >= 251 %}
Very High
{% elif (states('sensor.dexcom_glucose_value')|float) >= 181 %}
High
{% elif (states('sensor.dexcom_glucose_value')|float) >= 70 %}
In Range
{% elif (states('sensor.dexcom_glucose_value')|float) >= 54 %}
Low
{% elif (states('sensor.dexcom_glucose_value')|float) >= 0.0 %}
Very Low
{% else %}
undefined
{% endif %}
- name: "Dexcom Last Update"
icon: mdi:timer
state: >
{% set value = ((as_timestamp(now()) - as_timestamp(states.sensor.dexcom_glucose_value.last_updated))) | float | round(0) %}
{% if value < 60 %}
Now
{% else %}
{{ ((value % 3600) // 60) }} min ago
{% endif %}
I finally found some time to look into this. But i’m getting stuck. I created a input number, but now i’m getting stuck at the following error"
Any thoughts?
It looks like you are linking the picture to icons.zip. Have you unzipped the icons in the correct location? It should be calling the icon from /local/icons/dexcom-steady.png.
Feel free to post the whole code for the custom button-card, I will see if I can spot any errors.
my full code:
type: custom:button-card
entity: sensor.dexcom_mhoogenbosch_glucose_value
show_entity_picture: false
show_last_changed: false
show_icon: false
show_name: false
name: |
[[[
return `<span>${(states['sensor.dexcom_mhoogenbosch_glucose_value'].state)} mg/dL</span>`
]]]
styles:
card:
- border-radius: 2%
- padding: 2.5%
- color: ivory
- font-size: 12px
- border-width: >
[[[ if (states['sensor.dexcom_glucose_status'].state === 'In Range')
return '0px';
else return '2px';
]]]
- border-color: >
[[[ if (states['sensor.dexcom_glucose_status'].state === 'Very Low')
return 'red';
if (states['sensor.dexcom_glucose_status'].state === 'Low') return 'orange';
if (states['sensor.dexcom_glucose_status'].state === 'High') return 'orange';
if (states['sensor.dexcom_glucose_status'].state === 'Very High') return 'red';
else return 'none';
]]]
grid:
- grid-template-areas: '"img img" "trend trend" "update update" "range range"'
- grid-template-columns: 1fr 1fr
- grid-template-rows: 1fr min-content min-content min-content
img_cell:
- justify-content: middle
- align-items: start
- margin: none
- padding-bottom: 5px
icon:
- width: 15%
- margin-top: 0%
- color: red
- padding-bottom: 0px
custom_fields:
state:
- align-self: start
- justify-self: end
- font-size: 17px
- padding-bottom: 5px
update:
- font-family: helvetica neue, helvetica, Arial
- font-weight: 500
- font-size: 15px
- color: grey
- align-self: middle
- justify-content: middle
- padding-bottom: 5px
- margin-top: 0px
trend:
- font-family: helvetica neue, helvetica, Arial
- color: rgba(255, 255, 255, 0.7)
- font-size: 15px
- font-weight: 300
- text-align: center
- padding-bottom: 5px
range:
- font-family: helvetica neue, helvetica, Arial
- font-size: 15px
- font-weight: 500
- text-align: center
- line-height: 30px
- color: white
- background-color: |
[[[
if ((states['sensor.dexcom_glucose_status'].state === 'Very Low'))
return "red";
if ((states['sensor.dexcom_glucose_status'].state === 'Low'))
return "orange";
if ((states['sensor.dexcom_glucose_status'].state === 'High'))
return "orange";
if ((states['sensor.dexcom_glucose_status'].state === 'Very High'))
return "red";
else
return "none";
]]]
img:
- font-weight: bold
- font-size: 15px
- color: >
[[[ if (states['sensor.dexcom_glucose_status'].state === 'In Range')
return 'grey';
if ((states['sensor.dexcom_glucose_status'].state === 'Low'))
return "orange";
if ((states['sensor.dexcom_glucose_status'].state === 'High'))
return "orange";
else return 'red';
]]]
- align-self: middle
- justify-content: middle
- padding-bottom: 65px
custom_fields:
trend: |
[[[ if (states['input_number.dexcom_change'].state > 0)
return `${(states['sensor.dexcom_mhoogenbosch_glucose_trend'].state)} (+${Math.round(states['input_number.dexcom_change'].state)})`;
return `${(states['sensor.dexcom_mhoogenbosch_glucose_trend'].state)} (${Math.round(states['input_number.dexcom_change'].state)})`;
]]]
update: |
[[[ return `${(states['sensor.dexcom_last_update'].state)}`; ]]]
range: |
[[[[Processing: icons.zip...]()
if ((states['sensor.dexcom_glucose_status'].state === 'Very Low'))
return "VERY LOW";
if ((states['sensor.dexcom_glucose_status'].state === 'Low'))
return "LOW";
if ((states['sensor.dexcom_glucose_status'].state === 'High'))
return "HIGH";
if ((states['sensor.dexcom_glucose_status'].state === 'Very High'))
return "VERY HIGH";
if ((states['sensor.dexcom_glucose_status'].state === 'In Range'))
return "IN RANGE";
else
return "N/A";
]]]
img: |
[[[
if (states['sensor.dexcom_mhoogenbosch_glucose_trend'].state == "steady")
return `<img src=/local/dexcom-steady.png
style="width: 170px; height: 170px; color: #00def;">
</ha-icon><span style="font-size:30px; margin-top:-111px; display:block;">${(states['sensor.dexcom_mhoogenbosch_glucose_value'].state)}</span><span style="font-size:13px; margin-top:0px; display:block;">mg/dL</span>`;
if (states['sensor.dexcom_mhoogenbosch_glucose_trend'].state == "rising slightly")
return `<img src=/local/dexcom-risingslightly.png
style="width: 170px; height: 170px; color: #00def;">
</ha-icon><span style="font-size:30px; margin-top:-111px; display:block;">${(states['sensor.dexcom_mhoogenbosch_glucose_value'].state)}</span><span style="font-size:13px; margin-top:0px; display:block;">mg/dL</span>`;
if (states['sensor.dexcom_mhoogenbosch_glucose_trend'].state == "falling slightly")
return `<img src=/local/dexcom-fallingslightly.png
style="width: 170px; height: 170px; color: #00def;">
</ha-icon><span style="font-size:30px; margin-top:-111px; display:block;">${(states['sensor.dexcom_mhoogenbosch_glucose_value'].state)}</span><span style="font-size:13px; margin-top:0px; display:block;">mg/dL</span>`;
if (states['sensor.dexcom_mhoogenbosch_glucose_trend'].state == "falling")
return `<img src=/local/dexcom-falling.png
style="width: 170px; height: 170px; color: #00def;">
</ha-icon><span style="font-size:30px; margin-top:-111px; display:block;">${(states['sensor.dexcom_mhoogenbosch_glucose_value'].state)}</span><span style="font-size:13px; margin-top:0px; display:block;">mg/dL</span>`;
if (states['sensor.dexcom_mhoogenbosch_glucose_trend'].state == "rising")
return `<img src=/local/dexcom-rising.png
style="width: 170px; height: 170px; color: #00def;">
</ha-icon><span style="font-size:30px; margin-top:-111px; display:block;">${(states['sensor.dexcom_mhoogenbosch_glucose_value'].state)}</span><span style="font-size:13px; margin-top:0px; display:block;">mg/dL</span>`;
if (states['sensor.dexcom_mhoogenbosch_glucose_trend'].state == "falling quickly")
return `<img src=/local/dexcom-fallingquickly1.png
style="width: 170px; height: 170px; color: #00def;">
</ha-icon><span style="font-size:30px; margin-top:-111px; display:block;">${(states['sensor.dexcom_mhoogenbosch_glucose_value'].state)}</span><span style="font-size:13px; margin-top:0px; display:block;">mg/dL</span>`;
if (states['sensor.dexcom_mhoogenbosch_glucose_trend'].state == "rising quickly")
return `<img src=/local/dexcom-risingquickly1.png
style="width: 170px; height: 170px; color: #00def;">
</ha-icon><span style="font-size:30px; margin-top:-111px; display:block;">${(states['sensor.dexcom_mhoogenbosch_glucose_value'].state)}</span><span style="font-size:13px; margin-top:0px; display:block;">mg/dL</span>`;
return `<img src=/local/dexcom-steady.png
style="width: 170px; height: 170px; color: #00def;">
</ha-icon><span style="font-size:30px; margin-top:-111px; display:block;">N/A</span><span style="font-size:13px; margin-top:0px; display:block;">mg/dL</span>`;
]]]
tap_action:
action: none
The icons are placed in /config/www directly. So without the icons folder. I changed the code accordenly.
All sensors are active and report status too.
I noticed one additional line got added to the code when I posted it in the forum - this is probably causing the error. Just remove [Processing: icons.zip...]()
. I just fixed it in my original post.
cool, this works!
thanks a lot!
Has anyone had any success… or attempted to pull the dexcom data from with in apps on a mobile phone, ie. I’ve had to remove the dexcom app. As the CamAPS apps uses the dexcom integrated in it. Thus, not able to use the dexcom share function anymore to create a sensor in HA
As I understand it, a dexcom will connect to a maximum of 2 devices. Mine connects to my pump and to my phone via xdrip+. In turn xdrip+ uploads to nightscout. Nightscout is easily incorporated with HA. Either rest or the nightscout repo.
Yes, but i think this means you have the dexcom app installed on your phone. The dexcom app connect with BLE to the sensor and uploads it to the share environment.
As I understand correctly, SrangerJona had to remove the app, thus no longer uploading to share.
No I do not have dexcom’s crap app on my phone. I have, as I said, xdrip+.
On further review, CamAPS is new on me. It doesn’t appear to be very open or interoperable.
Also I note that it uses Dexcom G6 (not the G5 that I am used to).
Does your Dexcom connect directly to your pump, or only to CamAPS? If it only connects to CamAPS you could try connecting it also to Xdrip+ → NightScout → Home assistant.
Thanks man. That’s somewhat what I ended up doing. It’s been a godsend now. I ended up installing xdrip and then using the built in dexcom server uploader, because technically I still had her setup with a share account from before. So I was able to use that to push the BS to the dexcom.
How do I change the very low / low / inrange colours? I thought I had it sorted, but after looking at it, it doesn’t add up for me.
I clearly do not understand how the percentages work.For example i’d like very low to be below 3.1, and low anything between 4.5 and 3.1.
I am using a template sensor (in the code above, it’s called sensor.dexcom_glucose_status) that looks like this:
- sensor:
- name: "Dexcom Glucose Status"
icon: mdi:diabetes
state: >-
{% if (states('sensor.dexcom_name_glucose_value')|float) >= 251 %}
Very High
{% elif (states('sensor.dexcom_name_glucose_value')|float) >= 181 %}
High
{% elif (states('sensor.dexcom_name_glucose_value')|float) >= 70 %}
In Range
{% elif (states('sensor.dexcom_name_glucose_value')|float) >= 54 %}
Low
{% elif (states('sensor.dexcom_name_glucose_value')|float) >= 0.0 %}
Very Low
{% else %}
undefined
{% endif %}
In this case, sensor.dexcom_name_glucose_value is provided by the Home Assistant Dexcom integration, so just change it for the actual name of your sensor. In the template above, everything above or equal 251 is very high, above or equal 181 is high etc.
As for the colors, that’s in the actual custom button-card. For example:
if (states['sensor.dexcom_glucose_status'].state === 'Very Low')
return 'red';
We made a simple visualization for ourselves back when Sugarmate was giving out fresh data via API. We installed a few Amazon Fire HDs in the house so we don’t have to look at our phone or watch all the time. I recently moved this visualization to Home Assistant, the setup is very simple. Would be happy if anyone likes and uses GitHub - wiltodelta/homeassistant-sugartv-card: A custom lovelace card for Home Assistant that provides a better way to display Dexcom data.
Hi @tomx101. I can’t figure out where I am going wrong. It must be something with my icons. Here is my error (sorry I am somewhat of a noob) below:
Cannot quick reload all YAML configurations because the configuration is not valid: Integration error: show_entity_picture - Integration ‘show_entity_picture’ not found. Integration error: custom_fields - Integration ‘custom_fields’ not found. Integration error: styles - Integration ‘styles’ not found. Integration error: entity - Integration ‘entity’ not found. Integration error: show_last_changed - Integration ‘show_last_changed’ not found. Integration error: show_name - Integration ‘show_name’ not found. Integration error: type - Integration ‘type’ not found. Integration error: name - Integration ‘name’ not found. Integration error: tap_action - Integration ‘tap_action’ not found. Integration error: show_icon - Integration ‘show_icon’ not found