Recently I've been experimenting with Apple Shortcuts to interface with the new itsaSnap app. This app lets you interface with Adafruit IO feeds on your phone. With Apple Shortcuts, you can get data from your phone to Adafruit IO. You can, for example, send health data, weather data, even encoded photos.
One topic that comes up in Apple Shortcuts is not being able to easily create an automated Shortcut that loops. For example, having data be sent every 30 minutes. There is a time automation, but you have to setup an automation instance for every time you need the Shortcut to run.
I wanted to figure out a way to do this and found a helpful post on the Apple Shortcuts subreddit that describes using alarms as a workaround. I normally avoid Reddit but that particular subreddit has had very helpful posts with folks sharing their Shortcuts and tips for folks to accomplish what they're looking for.
Flow Chart
I've adapted the suggested Shortcut from the subreddit post a bit. I've found that wrapping my head around the logic can be a little tricky, so here is a visual explainer before we get into building out the Shortcuts.
Send Data to itsaSnap Shortcut
The first shortcut gets data from your phone and sends it to an IO feed via itsaSnap. For this example, you'll see I'm sending Steps data, but you can send any data you want. Search for itsaSnap under apps and select Send Value. Then send the data to your feed.
Add Alarm Shortcut
The Add Alarm Shortcut creates an alarm 30 minutes in the future. This is done by using the Adjust Date action. Insert Add 30 minutes to Current Date. The Current Date action gets the current date and time. Next, you'll choose the Create an Alarm action. You'll pass the Adjusted Date that you just calculated to create an alarm for that time. You'll also pass a name to the alarm. In this case, I'm calling it stepTimer.
Alarm Based Timer Trigger
The Alarm Based Timer Trigger Shortcut is based on the post linked above from the Shortcuts subreddit post. It will find an alarm that has a certain name, deletes that alarm and runs the Send Data to itsaSnap Shortcut. Then, it checks if its between 7AM and 9PM. If it is, it runs the Add Alarm Shortcut to create a new alarm 30 minutes from now to repeat this Shortcut.
This is done by starting with the Find Alarm Where action. You'll find All Alarms where the Label is the same name that you named the alarm in the Add Alarm Shortcut. In this case, my alarm is called stepTimer. Next, you'll use an If action to check if the Alarms has any value. Inside the If action, you'll add a Delete Alarms action. This gets rid of the alarm. Then you'll add a Run Shortcut action. You'll pass the Send Data to itsaSnap Shortcut to this action.
After this alarm check, the second part of the Shortcut occurs. You'll add a Date action and pass Current Date to it. This gets the date and time from your OS. Next, you'll add an Adjust Date action. Pass Get Start of Day from Date. Then, add a Get Time Between Dates action. Pass Adjusted Date and Date in Hours to the action. Basically, what you're doing is getting the hours since the start of the day at midnight.
You'll add an If action and pass Time Between Dates is between 7 and 21. This is checking if it is between 7AM and 9PM based on the calculation you just did. Then, add a Run Shortcut action. You'll pass the Add Alarm Shortcut.
Automations
Now that your Shortcuts are created, you'll automate them. The Add Alarm Shortcut is triggered by a Time of Day automation to run once a day. The Alarm Based Timer Trigger Shortcut is triggered by an Alarm automation.
Time of Day Automation
You'll create a Time of Day Automation. Under When, select Time of Day and enter the time. Under Repeat, select Daily. Check off Run Immediately to have it run without confirmation. On the next page, select the Add Alarm Shortcut from your list of Shortcuts.
Alarm Automation
Create an Alarm Automation. Under When, select Goes Off. Under Alarms select Any. Check off Run Immediately. Then, add the Alarm Based Timer Trigger Shortcut.
Shortcuts, Automation, Action!
Now you're setup to send data to itsaSnap every 30 minutes. After the initial alarm is set with the Time of Day automation, the loop is in motion. When the alarm goes off, its deleted and data is sent to itsaSnap. If its between a certain time of the day, a new alarm is created to keep the cycle going. This recipe is great way to get consistent data sent to your IO feed. Below, you can see the step data being sent to the feed over time.