In Adafruit IO, an Action is a way to add triggered, automated logic to your IoT projects without writing code. This project will require two Actions: one to control the MagTag, and one to wait an hour before resetting the flag's position.
Create Swimming Feed
Before you can track the swimming activity, you'll need to set up a feed in Adafruit IO to store this data. A feed in Adafruit IO acts as storage for data. In this case, create a feed that stores a boolean value indicating whether you're currently swimming or not.
Navigate to your feed page, click New Feed, and name it swimming.
Create Swimming Action
Next, create an action to control the MagTag. If swimming, the Action will tell the servo to raise the flag and write a message to the MagTag e-ink display. If no longer swimming, the Action will tell the servo to lower the flag and write a message to the display.
Navigate to the Adafruit IO Actions page and click New Action.
Name the action and optionally give it a description.
You'll be brought to the editor page for the action.
From the editor, click the Triggers label on the toolbox.
Select the Any Data Block. This block runs your Action every single time ANY new data arrives at a feed, regardless of what the value is.
Drag and drop this block into the Triggers section of your root block.
Configure the Any Data Block to run the Action when the swimming feed gets new data by selecting the swimming feed from the dropdown.
Next, add a conditional block - this block helps you create smart decision-making logic for your Actions using if/then/else statements.
From the toolbox, select Logic . Under logic, select the conditional block
Drag and drop the conditional block to your root block, placing it underneath Actions.
Now to configure the conditional block to read the value of the swimming feed and perform an action based on its decision.
From the toolbox, select Math. Select the Compare Numbers block.
Drag and drop the Compare Numbers block to the conditional block's if connector.
From the toolbox, select the Get Feeds block.
Drag and drop the block into the compare numbers block's left slot.
Using the Get Feeds block's dropdown, change the feed to swimming.
Change the value on the right-hand side of the compare numbers block to 1.
Now to create a step to write text to the MagTag display.
From the toolbox, select Set Feed Value. Drag this block to the diagram
Change the Feed to: Adafruit MagTag 2.9" E-Ink Display.
From the toolbox, select the Multiline Text Block.
Connect this block to the Set Feed Value block
Change the text in the block to something like: "We are swimming. Come join us!".
Tip: The multiline text block allows you to hit Enter to create a new line. New lines will automatically show up on the MagTag display.
Create a step to write the servo's angle to 90 degrees (or 2500uS) to raise the flag.
From the toolbox, select the Set Feed Value block
Drag this block to the diagram
From the toolbox, select the Math blocks, select the Number Block
Drag this block to the right-hand-side of the Set Feed Value block on the diagram
Set the number to 2500, representing the maximum angle the servo can raise the flag to.
Next, the conditional block needs to be expanded for the else step (when the swimming feed is not equal to 1).
To do this:, click the "+" symbol next to the else step. The else step should expand and display a slot underneath it.
Instead of configuring the next two steps from scratch, duplicate the two existing blocks, since the functionality is similar.
Duplicate the Set Feed block so you only need to change the text:
Click the Set MagTag E-Ink display block, selecting it. Copy this block and paste it, creating a duplicate block.
Drag the duplicate block underneath the else step. Change the text on the right-hand-side of the block to reflect the pool is closed.
Next replicate the step above, but for the Set Servo step. Make sure to change the servo's value from 2500 to 500.
The action should look like the following diagram:
Save and enable the action.
Above the diagram, click the Save and Run button.
On the pop-up, click Enable, Save and Run. The action will run.
Verify that the output shows a string indicating the pool status as well as the servo value (in microseconds).
Create Timer Action
Next, crate a tiny action to reset the swimming feed, to indicating that you are no longer swimming.
Navigate to the Adafruit IO Actions page and click New Action.
Name the new feed and click Create.
Configure the workflow to wait one hour after swimming before running this action to reset the feed's value. This prevents scheduling another swim session too quickly.
Click the ⚙️ cog on the diagram's root block. This brings up the root block's delay settings.
Change the delay to 1 hour by selecting the 1 hours block and dragging it to the Delay's input slot.
From the toolbox, select Triggers.
Select the Data Matching Block and drag it into the diagram's Triggers slot.
Change the data matching block's feed to the swimming feed
Change the value on the right-hand side of the data matching block to 1
At this point, the action will execute every hour to check if the data on the feed is 1.
Open the feeds section of the toolbox.
Select, drag, and drop the Set Feed Value block underneath the Actions slot.
Open the math section of the toolbox. Select, drag, and drop the Number block underneath the Actions slot. Set the number to 0.
Double-check that the workflow looks like the following screenshot, then click Save and Run.
The action should run immediately, and set the swimming feed to 0.
Finally, validate that both actions are enabled before proceeding.
Page last edited November 03, 2025
Text editor powered by tinymce.