Automation - Diabetes triggers for Medtronic

As a person with two people who have diabetes at home ( wife and son), both using the Medtronic pump and Carelink app ( which has been disconnected from the Carelink integration with the new security patch). I have had to find a solution to trigger home warnings of any dangerous situation that might occur due to diabetes ( high sugar levels and more importantly low sugar).
My previous Solution:

  • Using the Carelink integration to get info via Carelink, showed every detail needed to have accurate management ( sensor expiry, connection loss, low battery pump or sensor, high sugar, low sugar…etc ) and based on that accurate triggers to accurate automation and actions based on each case.
    Unfortunately due to Medtronic’s change in its security protocols, the connection was not possible anymore unless there was a way to bypass the security check.

My current solution was :

  • Last notification and last removed notifications from Android phones that are connected to the diabetes devices ( sensor and pump) via the home assistant app.
    Unfortunately, the notifications from the Android aren’t always up-to-date and more accurate I have to base it on both last and last remove notifications as triggers additionally the triggers are limited to keywords that are found in those notifications based on a value template trigger.

My testing solution I am currently doing:

  • On any phone ( the current Android phone), install Xdrip+ connect via Carelink to get the information and upload it to a private server that has Nightscout, then use the Nightscout integration to upload Glucose levels to trigger anything.
    Unfortunately, I haven’t been able to get any other value pushed from Nightscout to the Nightscout integration in Home Assistant with the only value provided being blood glucose.

If anyone wants to work on this together, be my guest. here is the code for the current solution:
( the actions → telegram message + google speakers voice notifications)
( triggers → NightScout Glucose level + Last notification + last removed notifications)

alias: "Diabetes: Yousef Sensor "
description: Diabetes Update via Android Notifications Lists and last removed Notifications
trigger:
  - platform: template
    value_template: >-
      {{ 'glucose approaching Low' in
      states('sensor.medtronic_pixel_last_notification') }}
    id: lowsugar
    alias: Approaching Low
  - alias: Enter Blood Glucose
    platform: template
    value_template: >-
      {{ 'Enter BG to continue in SmartGuard.' in
      states('sensor.medtronic_pixel_last_notification') }}
    id: test
  - platform: template
    value_template: >-
      {{ 'High sensor glucose' in
      states('sensor.medtronic_pixel_last_notification') }}
    id: highbg
    alias: High Blood Glucose
  - platform: template
    value_template: >-
      {{ 'Glucose was 250 mg/dL or higher' in
      states('sensor.medtronic_pixel_last_notification') }}
    id: vhighbg
    alias: Very High Blood Glucose
  - platform: template
    value_template: "{{ 'Uknown' in states('sensor.medtronic_pixel_last_notification') }}"
    id: notconnected
    alias: Not Connected
  - platform: template
    value_template: >-
      {{ 'change the infusion set' in
      states('sensor.medtronic_pixel_last_notification') }}
    id: infusionset
    alias: Time to Change Infusion Set
  - platform: template
    value_template: >-
      {{ 'Change reservoir' in
      states('sensor.medtronic_pixel_last_notification') }}
    id: lowresvoir
    alias: 10.0 units remaining. Change reservoir
  - alias: Approaching Low
    platform: template
    value_template: >-
      {{ 'glucose approaching Low' in
      states('sensor.medtronic_pixel_last_removed_notification') }}
    id: lowsugar
  - alias: Enter Blood Glucose
    platform: template
    value_template: >-
      {{ 'Enter BG to continue in SmartGuard' in
      states('sensor.medtronic_pixel_last_removed_notification') }}
    id: test
  - alias: High Blood Glucose
    platform: template
    value_template: >-
      {{ 'High sensor glucose' in
      states('sensor.medtronic_pixel_last_removed_notification') }}
    id: highbg
  - alias: Very High Blood Glucose
    platform: template
    value_template: >-
      {{ 'Glucose was 250 mg/dL or higher' in
      states('sensor.medtronic_pixel_last_removed_notification') }}
    id: vhighbg
  - alias: Not Connected
    platform: template
    value_template: >-
      {{ 'Uknown' in states('sensor.medtronic_pixel_last_removed_notification')
      }}
    id: notconnected
  - alias: Time to Change Infusion Set
    platform: template
    value_template: >-
      {{ 'change the infusion set' in
      states('sensor.medtronic_pixel_last_removed_notification') }}
    id: infusionset
  - alias: 10.0 units remaining. Change reservoir
    platform: template
    value_template: >-
      {{ 'Change reservoir' in
      states('sensor.medtronic_pixel_last_removed_notification') }}
    id: lowresvoir
  - platform: numeric_state
    entity_id: sensor.blood_sugar
    for:
      hours: 0
      minutes: 5
      seconds: 0
    above: 200
    below: 299
    alias: Blood Glucose Above 200 and below 299
    id: highbg
  - alias: Blood Glucose under 85
    platform: numeric_state
    entity_id: sensor.blood_sugar
    for:
      hours: 0
      minutes: 5
      seconds: 0
    id: vlowsugar
    below: 85
  - alias: Blood Glucose Above 300+
    platform: numeric_state
    entity_id: sensor.blood_sugar
    for:
      hours: 0
      minutes: 5
      seconds: 0
    above: 300
    id: vhighbg
  - alias: Loss of Connection
    platform: template
    value_template: >-
      {{ 'transmitter and sensor connection is secure' in
      states('sensor.medtronic_pixel_last_notification') }}
    id: sensorconnect
  - alias: Loss of Connection
    platform: template
    value_template: >-
      {{ 'transmitter and sensor connection is secure' in
      states('sensor.medtronic_pixel_last_removed_notification') }}
    id: sensorconnect
  - alias: Low Sugar
    platform: template
    value_template: >-
      {{ 'changed to Low sensor glucose' in
      states('sensor.medtronic_pixel_last_removed_notification') }}
    id: vlowsugar
  - alias: Low Sugar
    platform: template
    value_template: >-
      {{ 'changed to Low sensor glucose' in
      states('sensor.medtronic_pixel_last_notification') }}
    id: vlowsugar
action:
  - alias: Send outbound message based on inbound trigger message
    choose:
      - conditions:
          - condition: trigger
            id:
              - lowsugar
        sequence:
          - data:
              volume_level: 1
            service: media_player.volume_set
            target:
              entity_id: media_player.all
          - delay:
              hours: 0
              minutes: 0
              seconds: 3
              milliseconds: 0
          - service: tts.google_say
            data:
              message: Yousef is Approaching Low, Please Check on him!
              entity_id: media_player.all
              cache: true
          - delay:
              hours: 0
              minutes: 0
              seconds: 10
              milliseconds: 0
          - data:
              volume_level: 0.8
            service: media_player.volume_set
            target:
              entity_id: media_player.all
          - service: notify.everyone
            data:
              message: Yousef is Approaching Low, Please Check on him!
              title: Approaching Low!
      - conditions:
          - condition: trigger
            id:
              - test
        sequence:
          - data:
              volume_level: 1
            service: media_player.volume_set
            target:
              entity_id: media_player.all
          - delay:
              hours: 0
              minutes: 0
              seconds: 3
              milliseconds: 0
          - service: tts.google_say
            data:
              message: >-
                Yousef Needs to Enter Blood Glucose to continue in SmartGuard.
                Please Test Him!
              entity_id: media_player.all
              cache: true
          - delay:
              hours: 0
              minutes: 0
              seconds: 10
              milliseconds: 0
          - data:
              volume_level: 0.8
            service: media_player.volume_set
            target:
              entity_id: media_player.all
          - service: notify.everyone
            data:
              message: >-
                Yousef Needs to Enter Blood Glucose to continue in SmartGuard.
                Please Test Him!
              title: Test Blood Glucose
      - conditions:
          - condition: trigger
            id:
              - highbg
        sequence:
          - data:
              volume_level: 1
            service: media_player.volume_set
            target:
              entity_id: media_player.all
          - delay:
              hours: 0
              minutes: 0
              seconds: 3
              milliseconds: 0
          - service: tts.google_say
            data:
              message: Yousef is High on Glucose sensor. Please check Blood Glucose!
              entity_id: media_player.all
              cache: true
          - delay:
              hours: 0
              minutes: 0
              seconds: 10
              milliseconds: 0
          - data:
              volume_level: 0.8
            service: media_player.volume_set
            target:
              entity_id: media_player.all
          - service: notify.everyone
            data:
              message: Yousef is High on Glucose sensor. Please check Blood Glucose!
              title: Yousef High!
      - conditions:
          - condition: trigger
            id:
              - vhighbg
        sequence:
          - data:
              volume_level: 1
            service: media_player.volume_set
            target:
              entity_id: media_player.all
          - delay:
              hours: 0
              minutes: 0
              seconds: 3
              milliseconds: 0
          - service: tts.google_say
            data:
              message: >-
                Yousefs Sugar Level was 250 mg/dL or higher for more than 3
                hours.  Please Check Pump Infusion Set!
              entity_id: media_player.all
              cache: true
          - delay:
              hours: 0
              minutes: 0
              seconds: 10
              milliseconds: 0
          - data:
              volume_level: 0.8
            service: media_player.volume_set
            target:
              entity_id: media_player.all
          - service: notify.everyone
            data:
              message: >-
                Yousefs Sugar Level was 250 mg/dL or higher for more than 3
                hours.  Please Check Pump Infusion Set!
              title: Yousef Very HIGH!
      - conditions:
          - condition: trigger
            id:
              - notconnected
          - condition: time
            after: "21:00:00"
            before: "08:00:00"
        sequence:
          - data:
              volume_level: 1
            service: media_player.volume_set
            target:
              entity_id: media_player.all
          - delay:
              hours: 0
              minutes: 0
              seconds: 3
              milliseconds: 0
          - service: tts.google_say
            data:
              message: >-
                Yousefs Pump and Sensor arent connected to the Phone Please
                Check on Him
              entity_id: media_player.all
              cache: true
          - delay:
              hours: 0
              minutes: 0
              seconds: 10
              milliseconds: 0
          - data:
              volume_level: 0.8
            service: media_player.volume_set
            target:
              entity_id: media_player.all
          - service: notify.everyone
            data:
              message: >-
                Yousefs Pump and Sensor arent connected to the Phone Please
                Check on Him
              title: No Connection at BedTime!
      - conditions:
          - condition: trigger
            id:
              - infusionset
        sequence:
          - data:
              volume_level: 1
            service: media_player.volume_set
            target:
              entity_id: media_player.all
          - delay:
              hours: 0
              minutes: 0
              seconds: 3
              milliseconds: 0
          - service: tts.google_say
            data:
              message: >-
                Its been three days since the last infusion set change for
                Yousef. Time to change the infusion set!
              entity_id: media_player.all
              cache: true
          - delay:
              hours: 0
              minutes: 0
              seconds: 10
              milliseconds: 0
          - data:
              volume_level: 0.8
            service: media_player.volume_set
            target:
              entity_id: media_player.all
          - service: notify.everyone
            data:
              message: >-
                Its been three days since the last infusion set change for
                Yousef. Time to change the infusion set.
              title: Change Infusion Set!
      - conditions:
          - condition: trigger
            id:
              - lowresvoir
        sequence:
          - data:
              volume_level: 1
            service: media_player.volume_set
            target:
              entity_id: media_player.all
          - delay:
              hours: 0
              minutes: 0
              seconds: 3
              milliseconds: 0
          - service: tts.google_say
            data:
              message: >-
                The amount of insulin in yousefs pump is low, please change the
                resvior!
              entity_id: media_player.all
              cache: true
          - delay:
              hours: 0
              minutes: 0
              seconds: 10
              milliseconds: 0
          - data:
              volume_level: 0.8
            service: media_player.volume_set
            target:
              entity_id: media_player.all
          - service: notify.everyone
            data:
              message: >-
                The amount of insulin in yousefs pump is low, please change the
                resvior!
              title: Change Infusion Set!
      - conditions:
          - condition: trigger
            id:
              - vlowsugar
        sequence:
          - data:
              volume_level: 1
            service: media_player.volume_set
            target:
              entity_id: media_player.all
          - delay:
              hours: 0
              minutes: 0
              seconds: 3
              milliseconds: 0
          - service: tts.google_say
            data:
              message: Yousef is Low, please check on him URGENTLY!
              entity_id: media_player.all
              cache: true
          - delay:
              hours: 0
              minutes: 0
              seconds: 10
              milliseconds: 0
          - data:
              volume_level: 0.8
            service: media_player.volume_set
            target:
              entity_id: media_player.all
          - service: notify.everyone
            data:
              message: Yousef is Low! please check on him NOW!
              title: Yousef is Low!
      - conditions:
          - condition: trigger
            id:
              - sensorconnect
        sequence:
          - data:
              volume_level: 1
            service: media_player.volume_set
            target:
              entity_id: media_player.all
          - delay:
              hours: 0
              minutes: 0
              seconds: 3
              milliseconds: 0
          - service: tts.google_say
            data:
              message: >-
                Ensure transmitter and sensor connection is secure, Check your
                pump.!
              entity_id: media_player.all
              cache: true
          - delay:
              hours: 0
              minutes: 0
              seconds: 10
              milliseconds: 0
          - data:
              volume_level: 0.8
            service: media_player.volume_set
            target:
              entity_id: media_player.all
          - service: notify.everyone
            data:
              message: >-
                Ensure transmitter and sensor connection is secure, Check your
                pump.
              title: Transmitter and sensor connection
    enabled: true
mode: single

I’ll post later. I use the nightscout api to get some info.

1 Like

The new plugin work perfect… Download firefox and plugin just to do this… save the install files for later even… it uses a auth token so it is working like the carelink follower app… you should also download the carelink follower app on your phone and make a user account (This is just so Carelink expects constant interaction with their API’s). Do the steps on GitHub - ondrej1024/carelink-python-client: Experimental Medtronic CareLink Client in Python and if you did it right you should have the carelink integration running exactly like the old one…

Just noticed… After you get firefox and the plugin then login to carelink while your in the plugin, instead of saving it to file, copy the actual token code in the box then paste it into home assistant’s “add integration” wizard… then you are done…