Writing an iOS Shortcut to Track Inhaler Usage

Jason Dudash
5 min readDec 9, 2020

--

When shortcuts were first announced by Apple I was excited to create one and hook it into Siri. But when I initially tried doing that, my reaction was “nope, too complicated to do on a small screen.” I also didn’t find any examples that seemed useful. So I completely ignored shortcuts.

Fast forward to this year. My wife recently asked me to help her figure out a better way to track her asthma inhaler usage — she was concerned she might be skipping doses and needed a way to track her puffs. A quick scan of the app store had some apps but nothing looked all that nice or easy (except this which looks amazing but requires a hardware sensor). In digging around I found out that Apple Health supports tracking inhaler usage, but the process of manually entering data into the Apple Health app isn’t user friendly. So I decided to take a second more serious look at shortcuts. And I was able to quickly build this simple automation in about an hour.

I’m going to walk through how this shortcut works, and if you want to use it too (or tweak it), you should be able to download it to your iOS device by tapping here.

The first thing I do before building any technology (like this shortcut), is decide how it should work with the person using it. For something simple like this, I’ll just jot down some notes on what that person wants to do and how the tech will help them do it. In this case it was simple:

  • Wife will puff once a day — and she wants to know if she already puffed
  • She’d also like to have a history of how often and when she used her inhaler
  • The shortcut will track if a puff occurred for the day and, if so, alert you so you don’t puff too many times
  • The shortcut will record the date/time of each puff
  • Bonus: The shortcut will track how many puffs remain

The Shortcuts app works simply by executing a bunch of predefined steps in the background so you don’t have to. Shortcuts refers to each step as an “action.” The way you build a shortcut is to define a bunch of these actions in the order you want them to run — top to bottom. With that information I was able to build the following set of steps (note some actions only run if a condition being evaluated is true):

Action 1 —This shortcut step searches in the Reminders app for one where the Title is Inhaler Count. I wasn’t sure where I should store info so I just chose Reminders app because all phones have that.

Action 2,3 (only runs if the last step didn’t find anything) — The shortcut needs to create that reminder since it doesn’t exist the first time this shortcut runs. These steps give us a nice easy prompt to ask for the info the shortcut doesn’t know and create a reminder with that info in it.

Action 4 — This step checks in the Apple Health app to get all the inhaler puffs already logged for today. It will use that data in later steps.

Action 5 —(only runs if it found inhaler puffs for today) Shows a popup with the times the inhaler was used today. This popup also gives the option to cancel out and stop running the shortcut.

Action 6 — Now this step finds that reminder again that has our inhaler count in it.

Action 7,8,9 — The next step gets the value of the inhaler count (that’s in the Notes section of the reminder created earlier). A popup says “Go ahead and puff.” It also says how many puffs are left so you can get that warm fuzzy feeling by seeing that the inhaler shows the same number. Once the popup is dismissed, another step does basic math to decrease the inhaler count by one.

Action 10 — This step logs the inhaler usage in the Apple Health app along with the exact date and time.

Step 11 — Shows a popup to notify how many puffs are left. This is just a little more user trust building that the puff tracking is working.

Action 12,13 — The last two steps are to delete the existing reminder (the one with out inhaler puff count) and add a new reminder with the new inhaler count as a note.

Finally, to tie it all nicely together, I set the double tap on the back of the phone to trigger the shortcut, so it’s super easy to run.

And that’s it. If you’re getting started with shortcuts, check out Apple’s user guide and maybe watch some WWDC videos. Hopefully, you found this useful — please let me know in the comments.

--

--

Jason Dudash
Jason Dudash

Written by Jason Dudash

An engineer, a gamer, open source coder, food lover, dog owner, rock climber, and a half-decent mixologist… https://linktr.ee/dudash

No responses yet