REST question

Before I embark on my most ambitious Home Assistant project yet - has anyone created a component for the Dexcom CGM? I can get the Dexcom API and developer credentials, but I know next to nothing about REST and Curl.

Any tips to get started besides take a deep breath and dive in?

3 Likes

Yeah Hover to openhab2 and search there. They have accomplished something like that but with nightscout as bridge.

My son has a Dexcom G6, which I have the night-scout website set up for. I use home assistant to pull json data from the night-scout website. The BG reading then shows up as a sensor in home assistant.

I have started working on automations with node red and the custom Alexa component.

Currently I am able to turn on a LIFX light, send a TTS message to Alexa (wake up!, BG reading is xx), and turn on my magic mirror (which displays the BG reading via night-scout) all when its 10PM-530AM and the BG reading is out of a certain window.

I am still working on the logic (I could use help) but it think its pretty neat and the wife is amazed.

The logic needs the ability to change the light color based on if the BG is high or low, needs to be able to determine if the BG reading is current or old (can be determined from night-scout json data I think). Also, I want to be able to tell Alexa I have addressed the concern and have it stop running the node red automation for a certain amount of time.

Also the automation currently turns off the LIFX light if the BG reading goes back within range.

I will try to post my .yaml code in the next day or so if you are interested.

1 Like

Definitely interested. I am also on a G6 and want to have HA turn on my bedroom light when my BS gets low. I never heard of Night Scout- I use the Dexcom Clarity app but I am disappointed with the limited data.

Is there much of a delay with pulling the JSON data from the NightScout website? It may then a simple problem of making an automation from that data.

I think the delay is about 30 seconds maybe longer but not long enough for a major concern for me. The initial setup takes a bit, but its worth it once complete.

I used the below link for my initial setup.

Once complete I used the following link to find out how to get the data in json format.

Then I used rest to pull the BG data in as a sensor. I will post my config when i get home.

After thinking about it, i bet it wouldn’t be to hard to make a home assistant component that simply asks for your night-scout herokuapp website and then pulls all the info and posts it as sensor data. I may try that one day when i get time.

2 Likes

configuration.yaml

- platform: rest
    name: JSON sgv
    resource: https://yoursitehere.herokuapp.com/api/v1/entries/current.json
    value_template: '{{ value_json[0].sgv }}'

scripts.yaml (using custom alexa component)

  bg_tts_alarm:
    alias: BG TTS Alarm
    sequence:
      - service: media_player.alexa_tts
        entity_id: media_player.bedroom_echo_dot
        data_template:
          message: "Wake up. yournamehere blood sugar is {{states('sensor.json_sgv')}}."

  bg_tts_current:
    alias: BG TTS Current
    sequence:
      - service: media_player.alexa_tts
        entity_id: media_player.bedroom_echo_dot
        data_template:
          message: "{{states('sensor.json_sgv')}}."

  monitoron_mirror:
    alias: Mirror Monitor On
    sequence:
      - service: shell_command.monitoron_mirror

shell_commands.yaml

monitoron_mirror: curl -s http://192.168.1.42:9411/remote?action=MONITORON

1 Like

Any comments or suggestions are welcome. This is my first automation.

Thanks. Step one was easy since I already had a Git account. Things got more difficult from there.
Anyway, I have a accounts on Nightscout, Heroku and UptimeRobot.
When I finished the setup of my Heroku account, I went to my dashboard and saw the past 12 hours of my data and it looks right. So Heroku was able to get my data from my Dexcom account.

But, the data hasn’t updated in almost an hour. Can you think of what I may have missed?

(Thanks for the scripts, and flows etc. I’ll jump into those when I am confident that Heroku is working).

EDIT- I had to log in on my phone again. Now my Heroku dashboard readings are up to date. Just curious, what are those diverging datapoints in the future?

Honestly I don’t know. I assumed they were projected BG paths for hi/ lo. There are a million things you can do with night-scout and I have barely scratched the surface.

I have never had an issue with the heroku website or app not being up to date (unless the G6 sensor is down) since getting it going. Its been rock solid.

I also recommend sugarmate for an official supported app that works with iOS and the Dexcom. Be sure to check it out, and also keep me clued in if you discover any new tricks or a better way of doing things.

Do you have NightScout on your phone? I do use Sugarmate to ask Alexa what my BS is.
I like the idea of a “Wake Up” on Alexa, but my TTS stopped working a few days ago and I haven’t looked into why.

I also found the “API v1.0.0 beta Endpoints” on the git, so there is a lot for me to absorb.

Thanks again.

I do but we mostly use Sugarmate for the phone. I had to reauthorize Sugarmate the other day as it stopped working with Alexa but its been pretty solid also. I have only been using the custom component for Alexa a few days so I am not sure how reliable its going to be.

There is a lot more that we can do with the API, probably be easier to handle that with a custom (night-scout) component.

I am going to start another thread about losing all of my Alexa devices in the <> Entities page.

I love it when things work. Even though setting up all the different accounts (Heroki, NightScout, UptimeRobot) was a bit tedious, at least I only have to do it once. Now I need to get Alexa TTS to work again.

So, using your template as a guide, I now see my current BG as a sensor in Home Assistant.
Would you be so kind as to share an export of your Node-Red flow?

Thanks again.

Glad it works for you!
Let me know of this export works. I don’t think I did it right.

BGauto.yaml (6.2 KB)

This is cool.
I wrote a script for a NodeMCU connected to an I2C character display, and from Node-Red I publish an MQTT message with the BG level. Now I have a “real-time” display of my BG level without having to open the app on the phone.

Next, I will template the “direction” and put an arrow up or down on the display.
I also need to determine if the sensor hasn’t been read for more than ten minutes so that I can display that the reading is old.

I’m not sure how you did it, but I was able to import it. Thanks

Oh, Finity helped me find my TTS problem, so a “Wake up” message is in the queue as well.

Sounds good. I forgot to mention that I had updated the automation so there are some changes from the flow I posted first. Let me know if you have any suggestions or ideas!

I do something similar, I use a magicmirror and use the MMM-HASS module to display the homeassistant BG sensor data on the screen.

I was displaying the nightscout webpage on the magicmirror and it would tell me the reading was old. Unfortunately i updated my nightscout repo and the mirror and the webpage display stopped working (not sure what caused that?). The only way I could get the BG value back was the MMM-HASS module. I think if there was a nightscout component things would be a lot smoother.

example…

nightscout:

  • weburl: xxxxxxx
    settings: xxxxxxx

then it could scrub the API and post all the available data to HA already in the correct template.

Maybe one day.

I use the below to grab the last time the sensor was read.

  - platform: rest
    name: bg_dateString
    resource: https://yoursitehere.herokuapp.com/api/v1/entries/current.json
    value_template: "{{ as_timestamp(value_json[0].dateString) | timestamp_custom('%D %I:%M %p') }}"

I’ve been using date instead of datestring because it’s in epoch time and I can do simple math on it. All I am looking for is, if the date doesn’t change after ten minutes then the reading is stale. My target hardware is a NodeMCU with a four-character, 14-segment LED display (from Adafruit). I thought about using an LCD display because I could show more detail, but I wanted something you could read at a glance from a few feet away. (And without finding my glasses). The first three characters are the last bg value and the last character is the trend. If the reading is stale I will put an asterisk * in the last character.

Can you explain the template to me? I am not familiar with the syntax there.