Now that the Components are set up, it's time to make them do stuff using Actions.
Each Action will tell the QT Py to perform one function. There is a lot you can do with Actions, mostly things like:
- Turn your relay on
- Turn your relay off
- Read data from the PIR (passive infrared sensor)
- Turn your NeoPixel color LED strip on in a specific color
To plan out Actions, break down exactly what you want the project to do.
Action Plan
- When the PIR sensor gets triggered, turn on the relay (start button)
- When the PIR sensor gets triggered, turn on the NeoPixels in red
- When the PIR sensor resets, turn off the relay and turn on relay 2 (stop button)
- When the PIR sensor resets, turn off the NeoPixels
- After 10 seconds, turn off relay 2
This covers my basic actions.
Adafruit IO has two different kind of triggers for actions. We can pick from various trigger blocks that react to incoming data:
- if (component) is in a certain state, then do (x).
Or Schedule blocks, where something happens at a specific time of day, so you can turn your project off when it's time for trick-or-treaters to go to bed.
It's possible to use multiple trigger blocks, and when any of them are triggered then the action will fire, although repeated executions are subject to a cooldown period (currently 5 seconds).
Lastly, there is a Settings option for the Root action block which allows delaying the execution of the action for a specified amount of time after receiving a trigger condition:
- if (component) is in a certain state, then do (x) after a set amount of time
Action Setup
Start by visiting the Actions page, using the link in the navigation menu bar.
Here all of your actions are displayed, showing names and descriptions along with the enabled state (Off/On toggle button), and the information icon at the end of each row.
Click "Create Action", and enter a suitable name and optional description. Make it obvious what the action does.
Now you'll be presented with the Actions workspace, with one Root block in the diagram, and a toolbox full of blocks to craft your action.
Start with the Triggers category, and drag the block labelled When feed
gets data matching =
0
onto the Triggers:
section of the root block. It will snap into place when the notches line up.
Select the PIR component from the Feed dropdown in the newly placed block.
Change the value in the block from zero to one (1
).
This checks the state: enter 1 for on, or 0 for off for the relays and sensors.
Now from the Feeds category in the toolbox, drag a Set Feed block into the Actions:
section of the root block.
Select the your target component from the feed dropdown in the placed block.
This will set the component state to whatever value you enter. Again, enter 1 for on, or 0 for off for the relays.
For the NeoPixel strip, things work much the same, only instead of using a 1 or a 0 in the "with" box, put a hex code indicating the color you'd like to see. I wanted red, so I entered #FF0000.
To turn the pixels back off, use a hex code of black: #000000
Tweaking the User Experience
These relays and switches are also not 100% reliable -- they sometimes get a little confused and don't turn off. After some testing and playing around, I ended up adding a few more actions as a failsafe, turning the relays and lights to "off" after a set amount of time with no triggers, so that the smoke or lights never get stuck in an "on" state.
Using the delay setting option for the Action, accessed with the Grey Cog in a Blue Background button, it's possible to set the action to run after a 3-4 second delay.
Creating an action to turn off the smoke relay, based on the relay receiving an On trigger first, but with a 3 second delay should act as a fail-safe.
Our PIR sensor can also help us out here. It has two screws on the side. One of them controls the sensor's sensitivity, and the other controls the amount of time that elapses before the sensor resets after it's been triggered. By creating Reactive actions based on the reset time of the PIR sensor (i.e. When the PIR sensor's state resets to 0, do "x") we get a little more control over the trigger time. Just turn your screw to adjust.
Here is my final setup, with fail-safe actions included.
Page last edited June 23, 2025
Text editor powered by tinymce.