Automating hypo & hyper temp targets – a quick hack

If you’re using eany of the DIY looping systems, you’ll be aware of the idea of setting a low temporary target when you are running high, to allow the loop to be more aggressive when delivering insulin, or a high temp target when you are low, or heading low, to encourage the loop to be more aggressive at suspending insulin to head off the low. But what if you could do that automatically, without needing to intervene?

Well IFTTT now has tools that can help you do that. What I’ll go through here is how to set something up for AndroidAPS and OpenAPS. At the moment there aren’t thetools available for iOS that would allow you to do the same with Loop.

What do I need?

This is one of the solutions that requires you to use NightScout. So far it’s not integrated with any of the systems (although no doubt it could be) so you’ll need to have set up a compatible NightScout site.

You’ll also need IFTTT (If This, Then That) on the phone that runs your Continuous Glucose Monitor. Then it’s on to how to set it up. The example I’ll provide is based on using xDrip+ on an Android phone with AndroidAPS, however, the same logic applies for the Dexcom app on an Android phone, and this will also work with OpenAPS. 

For this example, I’m going to describe a tool that enables a low target when glucose levels get higher, which will automatically trigger the system to understand that the user has become less insulin sensitive alongside the high glucose level.

Configuring AndroidAPS and xDrip+

Before you get started, you’ll need AndroidAPS to be able to read data from NightScout and you’ll need to have the correct handling of treatments in place between AndroidAPS and xDrip+ to allow the use of xDrip+ low prediction and avoid dual posting treatment.

You can ignore the first three steps and screenshots if you don’t intend to use the xDrip+ predictive low alerts.

Firstly, you’ll disable treatment uploads from xDrip+. The following screenshot shows the settings for xDrip+, in Cloud Upload/REST API/Extra Options:

It’s important that treatments can’t be uploaded.

Then you’ll need to accept treatments from AndroidAPS, in Inter-app Settings:

You’ll also need the following set up in AndroidAPS to allow AAPS to broadcast treatments and accept data from NightScout, under Preferences/NSClient/Advanced Settings:

You’ll also need to enable AAPS to adjust sensitivity when high and low targets are set, in Preferences:

In order to trigger IFTTT, you’ll need an appropriate alert. In this case, we have a High alert, which I’ve set to 9.8mmol/l in xDrip. It doesn’t need to make any noise as it’s simply a mechanism to trigger IFTTT.

You can also set Persistent High alerts to maintain your lowering target, and Forecast Low Alerts, using xDrip+’s predictive tools pulling in food and bolus data from AndroidAPS (or NightScout if using OpenAPS) however, you should be aware that SMBs can trigger incorrect low predictions in xDrip.

Once all these are in place, the next step is to set up IFTTT.

IFTTT Configuration

Within IFTTT, you’ll need to use the ‘Android Device” trigger, which looks like the following:

Within this “This” trigger, you should select the option for “Notifications received from a specific app”, and then name the app you want it to look for. In this case that is xDrip+ (which should be written exactly the same as the app name in the list of apps on the phone).

You then need to enter the notification keyword you want it to look out for. Remember that the fewer keywords the better. I’m simply using “High” which works with both the High Alert and the Persistent High alert. With this in place, the next thing to do is follow the instructions in the OpenAPS documents to set up the Webhooks you need to interact with NightScout for temp targets. I won’t repeat them here.

As this is an automated trigger, it’s sensible to set your temp target period to no more than 30 mins, and allow the persistent high alert to trigger after 30 mins of persistent high, so that you’re not maintaining a more aggressive mode unnecessarily for too long.

And that’s it. You can test your configuration out by setting a high alert which is somewhere near your current glucose level and watching everything trigger. 

For Low and forecast low alerts triggering high temp targets, you’d obviously need to use different keywords and different temp target values.

Profile Switching – AAPS Only

You can also use this approach to do a profile switch, with parameters similar to those set as in the images below. A word of caution though. Because you are reacting to a glucose level change, while you should set a duration to allow the profile switch to timeout, you should also identify when the glucose level comes back in range and switch back to your standard profile, probably with another IFTTT notification. 

The key here is that you are using Event Type “Profile Switch” and specifying the profile in Nightscout in the profile field.

This automatically feeds through to AAPS.

***WARNING*** Frequent profile switches will stop Autosens from working properly

The below image shows the content of the required Web Request for someone using the Token security method.

The next image shows the content required for a person using the API Secret instead:

What about Loop?

Obviously Loop a) Runs on an iPhone and b) Doesn’t adjust sensitivity with temp targets. More importantly, there isn’t currently an IFTTT integration for iOS notifications, however, it can’t be too difficult for someone to create a Spike or NightScout IFTTT integration that could be used as a trigger.

With the Katie Disimone branches of Loop, you can then allow interaction with NightScout. This means that with highs or lows you could trigger high and low temp targets automatically. In theory, you could also script something that worked with Shortcuts, but that’s not something I’ve experience of.

 

So there you have it. A fairly straightforward way to automatically create a variety of Temp Targets in OpenAPS and AndroidAPS when using an Android phone, for whichever purpose you choose.

 

Be the first to comment

Leave a Reply

Your email address will not be published.


*