[SOLVED] Dexcom G6 Notifcation not triggering - numeric_state

Now this wont be the first time i have asked about anb automation not triggering so apologies about that. Even though i have been using HA for a while now i do find that everyday is still a school day.

Now i was wanting to setup some automations based on the sugar levels of my wife who is Type1 Diabetic, and after reading through the following link i managed to get everything setup and reporting to sensors as i needed.

Now i don’t want to repeat all the effort in that post so i wont, however if anyone wants to know the effort so far then please let me know and i will be happy to share.

Anyway down to my question … i have the following automation setup that should trigger a warning of the blood levels are too high or too low, but for whatever reason they just aren’t trigger.

#Notify When Blood Sugars Low / High
- alias: 'Blood Sugars Warning'
  initial_state: true
  trigger:
    platform: numeric_state
    entity_id: sensor.last_blood_sugars
    above: 0
  condition: 
    condition: or
    conditions:
      - condition: numeric_state
        entity_id: sensor.last_blood_sugars
        above: 10
      - condition: numeric_state
        entity_id: sensor.last_blood_sugars
        below: 4
  action:
    - service: notify.all
      data:
        message: "Blood Sugars are at {{states('sensor.last_blood_sugars')}} and are {{states('sensor.last_blood_sugars_direction')}}"
    - service: script.audio_notify
      data_template:
        tts_msg: "Blood Sugars are at {{states('sensor.last_blood_sugars')}} and are {{states('sensor.last_blood_sugars_direction')}}"

I would be grateful if some fresh eyes could be cast over this and advise if i am doing something wrong.

Thanks in advance

I believe I understand what you are trying to do. The reason it fails to trigger is because of the way above works.

Think of above (and below) like thresholds. You have cross the threshold for something to happen.

So if the value is already above 0, it won’t trigger. The value has to decrease to less than 0 and then when it increases above 0 (crosses the threshold) it will trigger. Further increases beyond 0 won’t cause additional triggering.

Obviously, this behavior is ill-suited for your purposes (monitoring blood sugar levels within a narrow range).

I suggest you change the trigger’s platform from numeric_state to state and have it trigger on any change. For the condition, I suggest using a template instead of numeric_state.

@123 please excuse my ignorance but how would I start with building a template ?

I used a Template Trigger in order to combine both trigger and conditions.

- alias: 'Blood Sugars Warning'
  initial_state: true
  trigger:
    platform: template
    value_template: >
      {% set last = states('sensor.last_blood_sugars') | float %}
      {{ last <= 4 or last >= 10 }}
  action:
    - service: notify.all
      data:
        message: "Blood Sugars are at {{states('sensor.last_blood_sugars')}} and are {{states('sensor.last_blood_sugars_direction')}}"
    - service: script.audio_notify
      data_template:
        tts_msg: "Blood Sugars are at {{states('sensor.last_blood_sugars')}} and are {{states('sensor.last_blood_sugars_direction')}}"

For testing purposes, I recommend you replace sensor.last_blood_sugars with some other entity whose value you can easily adjust (manually). You obviously need to confirm all of this works properly before relying on it for its intended purpose.

@123 your template works perfectly, thank you so much.

3 Likes

Glad to hear it works for you. Please mark my post with the ‘Solution’ tag so it will easily found by other members seeking the solution.

This is the preferred method as opposed to prepending the word [SOLVED] to the the topic’s title. Tagging it as ‘Solution’ places a checkmark icon next to the topic’s title and places a link below the first post leading to the solution.

1 Like

thanks @123 as i said earlier everyday is a school day.

Will do that from now on

2 Likes

@andrew.vint if you are still using this, is there any chance you can post the complete setup and components you are using?
I’m having an issues trying to have it read out my wife’s numbers, am i missing something?
I have changed the sensor information to what hers polls with, but seem to be missing something.

This thread is four years old and the Dexcom integration has changed. If you are having Dexcom issues then start a new, fresh thread.

1 Like