Blockly has been slowly worming it's way into Adafruit IO, with a first edition replicating the old Action forms.
Now the latest release brings the wealth of features we've been dreaming of, allowing great complexity!
Will you be the first to bring down the house of cards/servers? Let us know in the forums if you do (or run into other issues)! Let's start off withย something simple, how to subtract one from a feed value (as a countdown)...
We'll explore a quick yet complex multi-action example, changing LED colour based on air quality, and additionally a Utility Light mode using the onboard button to request 30seconds of Bright White Light (useful in a kitchen).
Setup a Wippersnapper device
Adafruit IO has a devices page, which shows the special "Wippersnapper" devices, these run the arduino firmware that allows wifi connected boards to easily connect and configure components (inputs/outputs/sensors) with no code. Each component then has associated feeds for interacting with, so using the on board button becomes child's play.
Install wippersnapper, you're best off finding the learn guide for your board and then locate the Wippersnapper pages. Alternatively there is a quick start guide, or just do the usual hacky thing and have a go with no prior knowledge...
Visit this link (https://io.adafruit.com/devices/new) when signed in to be taken to the New Device setup page, then select your board and follow the onscreen instructions.
(You need an IO page open when the board first connects to accept the registration request).
Once setup you can visit the devices page and select the device to be taken to the Device overview page. You'll see there are no components configured, so use theย Auto Config button followed by the Magic Config option to easily add the on-board components. Most boards have at least an LED/NeoPixel, and a user button (but not all).
As shown in the previous image, you can see I have already added the boot button and pin D32 (NeoPixel strip), so warnings are displayed when revisiting the Magic Config page suggesting that those components won't import successfully (unselecting the two components means the automatic configuration of the remaining components can continue).
Actions
First things first, you need a sensor or something supplying fresh data. Heck these days you can even use the Weatherkit powerup block to feed regularly updated weather data in to a feed using a Schedule trigger block.ย
For now I've got an SCD40 Carbon Dioxide (CO2) sensor connected, reporting at 5second intervals (good for demos).
Next we need to goto the Feeds page, and create a new feed called counter which we'll use in the actions.
Now we can create the Actions, but first be aware that there is currently a cooldown period of 5seconds (meaning actions won't trigger more frequently than 5seconds or 0.2Hz). As a result, I've split my complex action into multiple actions, that way each time the CO2 data arrives it won't affect the cooldown of the Button feed being listened too (the CO2 arriving would mean all other triggers were ignored for 5seconds).
So for super simplicity, I've got 3 actions:
- If on-board button pressed, setย
counterfeed to desired Bright White Light time divided by sensor period
e.g. for 30seconds of white light at 5seconds CO2 period then counter would be set to 6 (or 60 = 5mins).
- If
counterfeed is greater than one, set NeoPixel strip to Bright White Light (i.e. html colour code #ffffff )
- Whenever CO2 data arrives check if
counteris less than one, if so then change LED based on CO2 levels, otherwise just decreasecounterby 1.
Action 1: Button pressed => reset counter
Picking the Trigger block that checks when a certain value is received is the first (and most challenging step) for this action. Select the Boot button feed from the feeds dropdown inside the trigger block you've placed in the Triggers section of the block diagram.
Then we use the Feeds blocks toย set a value for a feed, in this case theย counter feed.
We use the value that represents how many CO2 readings to count down before allowing the light to change back from white to the air indication colour. I've used 5 in this demo.
Here it might be appropriate to use the Settings cog on the Triggers: section of the block diagram, where an optionally resettable delay can be configured, allowing a form of debouncing (ignore rapidly repeated signals).
Action 2: If counter is active, set LEDs to White
Another simple action, where we check the value of the counter is at least 1 in the trigger. By doing this instead of triggering on each data point the action will not be affected by the cooldown if the counter reached zero and then was instantly reset. The output feed is obviously the NeoPixel feed (I'm using a Sparkle Motion mini board).
Action 3: The Big One - Counting down and Colours
It's not as bad as it sounds, we check if the counter is greater than 0, if so we decrement it by 1 because a countdown is obviously taking place.
Alternatively if the counter is 0 then we can use the current air quality to set an appropriate LED colour.
This requires the Maths blocks (change the addition/plus operator to a minus), and some Logic blocks for the If/Else-If/Else sections along with the conditionals (checking if a value meets a condition like "is less than"). Note that there are two types of conditional checking blocks, one for numbers and one for strings/text.
Get it set up:
Trigger every time your sensor gets new data, as this should be a stable polling period and will be used as our counter's tick period.ย
Then there is one block of IF/ELSE and the first IF section checks the counter is greater than 1, and decrements it if so, otherwise (ELSE) we use another (nested) IF/ELSE-IF/ELSE block examine the CO2 level is less than 1200 (or 900, or finally is above 1200 in the final Else block).ย
Based on those last 3 checks we publish different colours to the NeoPixel feed.
Testing
Press the button and expect the light to change, otherwise let us know (after you've verified connectivity).
It's worth checking the counter feed too. Also manually add data to the triggering feed if the button is not behaving as expected or you wish to test alternative CO2 values.
Did mine work first time? Yes! Did it work reliably afterwards... not so much, well at least not 100% of the time.
It appears my USB cable from the PC is underpowering the device + NeoPixels, an easy fix (more USB power).
For now I'll create a dashboard to reset the counter too. Maybe I should have a button for 5mins and another for 30mins etc, as each button would just set a different counter value. The dashboards work well on the phone once you realise about resizing the dashboard to a small size before editing.
When creating the buttons, don't forget to clear out the Release value, so it only sends data as the button is depressed rather than also when released.
The RUN button on the Edit Action pages will show you the actions output and last few attempts which can help.
That's all for now folks!
This page (Countdown Complete: It's finally here! ๐ Upgraded Actions on IO - How to do Math(ematics)) was last updated on May 01, 2025.
Text editor powered by tinymce.