# Holiday IoT Switch

## Overview

![](https://cdn-learn.adafruit.com/assets/assets/000/134/228/medium800thumb/3d_printing_cat-thumb.jpg?1734659352)

https://youtu.be/-Bj3ce8MCts

## Smart Outlet Controller

Build a custom controller to trigger a smart outlet using a Feather ESP32-S2, CircuitPython, Adafruit IO and the itsaSNAP app for iOS.

You'll use a large arcade button with an LED to toggle the lights on or off on a holiday tree or anything connected to a [TP-Link Tapo Matter](https://www.amazon.com/gp/product/B0CVN3CNCD/) Smart Outlet.

3D print a festive candy cane inspired enclosure to house the arcade button and the Feather ESP32-S2.

![3d_printing_pusheen.gif](https://cdn-learn.adafruit.com/assets/assets/000/134/229/medium640thumb/3d_printing_pusheen.jpg?1734699043)

# Parts
### Adafruit ESP32-S2 Feather - 4 MB Flash + 2 MB PSRAM

[Adafruit ESP32-S2 Feather - 4 MB Flash + 2 MB PSRAM](https://www.adafruit.com/product/5000)
What's Feather-shaped and has an ESP32-S2 WiFi module? What has a STEMMA QT connector for I2C devices? What has your favorite Espressif WiFi microcontroller and lots of Flash and RAM memory for your next IoT project? What will make your next IoT project flyyyyy?

That's right -...

In Stock
[Buy Now](https://www.adafruit.com/product/5000)
[Related Guides to the Product](https://learn.adafruit.com/products/5000/guides)
![Angled shot of rectangular microcontroller.](https://cdn-shop.adafruit.com/640x480/5000-12.jpg)

### Massive Arcade Button with LED - 100mm White

[Massive Arcade Button with LED - 100mm White](https://www.adafruit.com/product/1187)
OMG WATCH OUT! This 100mm diameter arcade button with a **10mm deep plastic base** is so massive and inviting it may collapse upon itself and form a black hole from which not even light can escape! Until it does, however, it ready for all sorts of pressing and pushing. Science...

In Stock
[Buy Now](https://www.adafruit.com/product/1187)
[Related Guides to the Product](https://learn.adafruit.com/products/1187/guides)
![Head-on shot of illuminated massive white 100mm arcade button.](https://cdn-shop.adafruit.com/640x480/1187-00.jpg)

### Arcade Button and Switch Quick-Connect Wires - 0.187" (10-pack)

[Arcade Button and Switch Quick-Connect Wires - 0.187" (10-pack)](https://www.adafruit.com/product/3835)
Quick connector wire sets make wiring up our arcade-style or metal buttons quicky-quick. Each wire comes as a 'pair' with two 0.187" quick-connects pre-crimped. The wires are terminated together in a JST 2.5mm 2-pin connector. This connector will fit in 0.1" headers,...

In Stock
[Buy Now](https://www.adafruit.com/product/3835)
[Related Guides to the Product](https://learn.adafruit.com/products/3835/guides)
![Angled shot of Arcade Button and Switch Quick-Connect Wires - 0.187" (10-pack)](https://cdn-shop.adafruit.com/640x480/3835-08.jpg)

### Pink and Purple Woven USB A to USB C Cable - 2 meters long

[Pink and Purple Woven USB A to USB C Cable - 2 meters long](https://www.adafruit.com/product/5044)
This cable is not only super-fashionable, with a woven pink and purple Blinka-like pattern, it's also made for USB C for our modernized breakout boards, Feathers and more.&nbsp; [If you want something just like it but for Micro B, we have a B...](https://www.adafruit.com/product/4111)

Out of Stock
[Buy Now](https://www.adafruit.com/product/5044)
[Related Guides to the Product](https://learn.adafruit.com/products/5044/guides)
![Angled shot of a pink/purple woven USB cable plugged into a laptop port and a small dev board.](https://cdn-shop.adafruit.com/640x480/5044-04.jpg)

### 5V 1A (1000mA) USB port power supply - UL Listed

[5V 1A (1000mA) USB port power supply - UL Listed](https://www.adafruit.com/product/501)
Need a USB jack for charging or powering a project, but don't want to lug around a computer? This switching supply gives a clean regulated output at up to 1000mA! 110 or 240 input, so it works in any country. The plugs are "US 2-prong" style so you may need a plug adapter, but...

In Stock
[Buy Now](https://www.adafruit.com/product/501)
[Related Guides to the Product](https://learn.adafruit.com/products/501/guides)
![Wall wart power supply with 2 US prong power](https://cdn-shop.adafruit.com/640x480/501-05.jpg)

### Adafruit IO+ 1 Year Subscription Card

[Adafruit IO+ 1 Year Subscription Card](https://www.adafruit.com/product/3980)
It's the Internet of the Things!&nbsp;[Adafruit IO+](https://io.adafruit.com/plus) is the easiest way to stream, log, and interact with your data. Whether you're interesting in&nbsp;datalogging or communicating with your microcontroller over the web, Adafruit IO is our cloud...

In Stock
[Buy Now](https://www.adafruit.com/product/3980)
[Related Guides to the Product](https://learn.adafruit.com/products/3980/guides)
![ Credit card sized Adafruit IO+ Subscription Card $99."ONE FULL YEAR" against circuit board paper backing.](https://cdn-shop.adafruit.com/640x480/3980-03.jpg)

### Part: Outdoor Smart Plug
quantity: 1
2 Individual outlets works with Apple Home
[Outdoor Smart Plug](https://www.amazon.com/Tapo-Individual-Resistance-Certified-P400M/dp/B0CVN3CNCD)

# Holiday IoT Switch

## Circuit Diagram

The diagram below provides a general visual reference for wiring of the components once you get to the **Assembly** page. This diagram was created using the software package [Fritzing](http://fritzing.org/download/).

## Adafruit Library for Fritzing

Adafruit uses the Adafruit's Fritzing parts library to create circuit diagrams for projects. You can download the library or just grab individual parts. Get the library and parts from [GitHub - Adafruit Fritzing Parts](https://github.com/adafruit/Fritzing-Library/tree/master/parts).

![](https://cdn-learn.adafruit.com/assets/assets/000/134/184/medium800/3d_printing_Circuit-Diagram.jpg?1734623358)

## Wired Connections

- **Cathode** from LED connects to **GND** pin&nbsp;on **Feather**
- **Anode** from LED strip connects to **3V** pin on&nbsp; **Feather**
- **Pin 1** from Button connects to **D5** &nbsp;pin on&nbsp; **Feather**
- **Pin 2** from Button connects to **GND** pin on **Feather**

The Feather ESP32-S2 is powered by a 5V 1A power supply.

# Holiday IoT Switch

## CAD Files

## 3D Printed Parts

STL files for 3D printing are oriented to print "as-is" on FDM style machines. Parts are designed to 3D print without any support material using PLA filament. Original design source may be downloaded using the links below.

![3d_printing_3d-parts.jpg](https://cdn-learn.adafruit.com/assets/assets/000/134/236/medium640/3d_printing_3d-parts.jpg?1734705976)

## Build Volume

The parts require a 3D printer with a minimum build volume of:

- 140mm (X) x 140mm (Y) x 78mm (Z)

![3d_printing_bambu-slice.jpg](https://cdn-learn.adafruit.com/assets/assets/000/134/230/medium640/3d_printing_bambu-slice.jpg?1734703425)

[Download CAD Source Files](https://cdn-learn.adafruit.com/assets/assets/000/134/231/original/CAD.zip?1734703493)
[Download 3MF Files](https://cdn-learn.adafruit.com/assets/assets/000/134/232/original/STLs.zip?1734703501)
## Multicolor Part (Optional)

The Top Cover can be 3D printed using a multi-material capable machine. Import the **Top Cover Multicolor.3mf** file into your slicer and choose your preferred colors for each body in the part.

![3d_printing_bambu-multicolor.jpg](https://cdn-learn.adafruit.com/assets/assets/000/134/233/medium640/3d_printing_bambu-multicolor.jpg?1734705123)

## Design Source Files

The project assembly was designed in Fusion 360. This can be downloaded in different formats like STEP, STL and more.

Electronic components like Adafruit's boards, displays, connectors and more can be downloaded from the&nbsp;[Adafruit CAD parts GitHub Repo](https://github.com/adafruit/Adafruit_CAD_Parts/).

![3d_printing_5303_Feather_ESP32-S2.jpg](https://cdn-learn.adafruit.com/assets/assets/000/134/234/medium640/3d_printing_5303_Feather_ESP32-S2.jpg?1734705369)

# Holiday IoT Switch

## Get Started with Adafruit IO

Adafruit IO is integrated with your&nbsp;[adafruit.com account](https://accounts.adafruit.com/)&nbsp;so you don't need to create yet another online account! You need an Adafruit account to use Adafruit IO because we want to make sure the data you upload is available to only you (unless you decide to publish your data).

## I have an Adafruit.com Account already

**If you already have an Adafruit account, then you already have access to Adafruit IO**. It doesn't matter how you signed up, your account will make all three available.

To access Adafruit IO, simply visit [https://io.adafruit.com](https://io.adafruit.com) to start streaming, logging, and interacting with your data.

## Create an Adafruit Account (for Adafruit IO)

An Adafruit account makes Adafruit content and services available to you in one place. Your account provides access to the [Adafruit shop](https://www.adafruit.com/), the [Adafruit Learning System](https://learn.adafruit.com/), and [Adafruit IO](https://io.adafruit.com/). This means only one account, one username, and one password are necessary to engage with the content and services that Adafruit offers.

If you do not have an Adafruit account, signing up for a new Adafruit account only takes a couple of steps.

Begin by visiting [https://accounts.adafruit.com](https://accounts.adafruit.com).

**Click the Sign Up button** under the "Need An Adafruit Account?" title, below the Sign In section.

![](https://cdn-learn.adafruit.com/assets/assets/000/125/220/medium800/adafruit_io_Create_account_sign_in_up_page.png?1697479894)

This will take you to the **Sign Up** page.

**Fill in the requested information,** and **click the Create Account button.**

![](https://cdn-learn.adafruit.com/assets/assets/000/125/219/medium800/adafruit_io_Create_Account_info_entered.png?1697479894)

This takes you to your Adafruit Account home page. From here, you can access all the features of your account.

You can also access the Adafruit content and services right from this page. Along the top of the page, you'll see a series of links beginning with "Shop". To access any of these, simply click the link.

![](https://cdn-learn.adafruit.com/assets/assets/000/125/217/medium800/adafruit_io_Create_account_home_page.png?1697479894)

For example, **to begin working with Adafruit IO, click the IO link** to the right of the rest of the links. This is the same for the other links as well.

That's all there is to creating a new Adafruit account, and navigating to Adafruit IO.

![](https://cdn-learn.adafruit.com/assets/assets/000/125/218/medium800/adafruit_io_Create_Account_io_homepage.png?1697479770)

# Holiday IoT Switch

## Download the ItsaSnap by Adafruit App

This section will guide you through downloading and installing the ItsaSnap by Adafruit app.

## Download and Install ItsaSnap

To install and download ItsaSnap for your iOS device,

1. **Open the App Store**.
2. **Tap** on the **"Search" icon** at the bottom of the screen.
3. **Type "ItsaSnap by Adafruit" or "ItsaSnap"** in the search bar and **tap "Search".**
4. Locate the **ItsaSnap**** &nbsp;app** in the search results and tap on it

![](https://cdn-learn.adafruit.com/assets/assets/000/130/658/medium800/adafruit_io_IMG_5711-ezgif.com-resize-2.jpg?1718123186)

&nbsp; &nbsp; 5. **Tap** the **"Get" button** to download and install the app on your device.&nbsp;

You may be prompted to enter your Apple ID password or use Face ID/Touch ID to confirm the installation

![](https://cdn-learn.adafruit.com/assets/assets/000/130/659/medium800/adafruit_io_IMG_5711-ezgif.com-resize-crop.jpg?1718123294)

After you have downloaded and installed ItsaSnap, open the app.

![](https://cdn-learn.adafruit.com/assets/assets/000/130/637/medium800/adafruit_io_adaSnap5-ezgif.com-resize.png?1718070937)

You will need to enter your&nbsp; **Adafruit username** and **Adafruit IO Key** (which is _different_ from your Adafruit account password).

Your Adafruit IO key is a long string of letters and numbers. To make it easier to add to the app, we've also included a QR code scanner that allows you to easily copy the Adafruit IO Key from the Adafruit IO website to the app.

![](https://cdn-learn.adafruit.com/assets/assets/000/130/660/medium800/adafruit_io_qrbuttonscan.png?1718123519)

On the ItaSnap app, the QR code scanner is located below the Adafruit IO Key and above the login button. To access it, press the ' **Scan QR code for IO Key**' button. This will open the QR code scanner.

![](https://cdn-learn.adafruit.com/assets/assets/000/130/662/medium800/adafruit_io_IMG_5702-ezgif.com-crop.png?1718123632)

To find the QR code for your Adafruit IO account, [navigate go to the overview page](https://io.adafruit.com/overview). Once there, click the yellow button with a key in the center (it's next to the "New Device" button) to reveal your Adafruit IO Key.&nbsp;

![](https://cdn-learn.adafruit.com/assets/assets/000/130/640/medium800/adafruit_io_Screenshot_2024-06-10_at_9.42.20%E2%80%AFPM.png?1718072559)

After clicking it, a window with your information will appear. Then, find the QR code and scan it, and log in.

![](https://cdn-learn.adafruit.com/assets/assets/000/130/653/medium800/adafruit_io_Pasted_Image_6_11_24__11_55_AM.png?1718121312)

# Holiday IoT Switch

## Install CircuitPython

[CircuitPython](https://github.com/adafruit/circuitpython) is a derivative of [MicroPython](https://micropython.org) designed to simplify experimentation and education on low-cost microcontrollers. It makes it easier than ever to get prototyping by requiring no upfront desktop software downloads. Simply copy and edit files on the **CIRCUITPY** drive to iterate.

## CircuitPython Quickstart

Follow this step-by-step to quickly get CircuitPython running on your board.

[Download the latest version of CircuitPython for this board via circuitpython.org](https://circuitpython.org/board/adafruit_feather_esp32s2/)
 **Click the link above to download the latest CircuitPython UF2 file.**

Save it wherever is convenient for you.

![install_circuitpython_on_most_boards_CircuitPython_downloaded.jpg](https://cdn-learn.adafruit.com/assets/assets/000/102/129/medium640/install_circuitpython_on_most_boards_CircuitPython_downloaded.jpg?1620922559)

![](https://cdn-learn.adafruit.com/assets/assets/000/106/648/medium800/adafruit_products_FESPB_reset_and_neopixel.jpg?1637349097)

Plug your board into your computer, using a known-good data-sync cable, directly, or via an adapter if needed.

Click the **reset** button once (highlighted in red above), and then click it again when you see the **RGB status LED(s)** (highlighted in green above) turn purple (approximately half a second later). Sometimes it helps to think of it as a "slow double-click" of the reset button.

If you do not see the LED turning purple, you will need to reinstall the UF2 bootloader. See the&nbsp; **Factory Reset** &nbsp;page in this guide for details.

On some very old versions of the UF2 bootloader, the status LED turns red instead of purple.

Once successful, you will see the **RGB status LED(s)** turn green (highlighted in green above), and a disk drive ending in " **...BOOT**" should appear on your host computer. If you see red, try another port, or if you're using an adapter or hub, try without the hub, or different adapter or hub.

If double-clicking doesn't work the first time, try again. Sometimes it can take a few tries to get the rhythm right!

A lot of people end up using charge-only USB cables and it is very frustrating! **Make sure you have a USB cable you know is good for data sync.**

Info: 

You will see a new disk drive appear called **FTHRS2BOOT**.

&nbsp;

&nbsp;

Drag the **adafruit\_circuitpython\_etc.uf2** file to **FTHRS2BOOT**.

![adafruit_products_FESP_FTHRS2BOOT.png](https://cdn-learn.adafruit.com/assets/assets/000/106/649/medium640/adafruit_products_FESP_FTHRS2BOOT.png?1637349249)

![adafruit_products_FESP_drag_UF2.png](https://cdn-learn.adafruit.com/assets/assets/000/106/650/medium640/adafruit_products_FESP_drag_UF2.png?1637349290)

Copy or drag the UF2 file you downloaded to the **BOOT** drive.

The **BOOT** drive will disappear and a new disk drive called **CIRCUITPY** will appear.

That's it!

![install_circuitpython_on_most_boards_CIRCUITPY.jpg](https://cdn-learn.adafruit.com/assets/assets/000/102/130/medium640/install_circuitpython_on_most_boards_CIRCUITPY.jpg?1620923145)

# Holiday IoT Switch

## Create Your settings.toml File

CircuitPython works with WiFi-capable boards to enable you to make projects that have network connectivity. This means working with various passwords and API keys. As of [CircuitPython 8](https://circuitpython.org/downloads), there is support for a **settings.toml** file. This is a file that is stored on your **CIRCUITPY** drive, that contains all of your secret network information, such as your SSID, SSID password and any API keys for IoT services. It is designed to separate your sensitive information from your **code.py** file so you are able to share your code without sharing your credentials.

CircuitPython previously used a **secrets.py** file for this purpose. The **settings.toml** file is quite similar.

Warning: Your **settings.toml** file should be stored in the main directory of your **CIRCUITPY** drive. It should not be in a folder.

## CircuitPython **settings.toml** File

This section will provide a couple of examples of what your **settings.toml** file should look like, specifically for CircuitPython WiFi projects in general.

The most minimal **settings.toml** file must contain your WiFi SSID and password, as that is the minimum required to connect to WiFi. Copy this example, paste it into your **settings.toml** , and update:

- `your_wifi_ssid`
- `your_wifi_password`

```auto
CIRCUITPY_WIFI_SSID = "your_wifi_ssid"
CIRCUITPY_WIFI_PASSWORD = "your_wifi_password"
```

Many CircuitPython network-connected projects on the Adafruit Learn System involve using Adafruit IO. For these projects, you must _also_ include your Adafruit IO username and key. Copy the following example, paste it into your settings.toml file, and update:

- `your_wifi_ssid`
- `your_wifi_password`
- `your_aio_username`
- `your_aio_key`

```auto
CIRCUITPY_WIFI_SSID = "your_wifi_ssid"
CIRCUITPY_WIFI_PASSWORD = "your_wifi_password"
ADAFRUIT_AIO_USERNAME = "your_aio_username"
ADAFRUIT_AIO_KEY = "your_aio_key"
```

Some projects use different variable names for the entries in the **settings.toml** file. For example, a project might use `ADAFRUIT_AIO_ID` in the place of `ADAFRUIT_AIO_USERNAME`. **If you run into connectivity issues, one of the first things to check is that the names in the settings.toml file match the names in the code.**

Warning: Not every project uses the same variable name for each entry in the **settings.toml** file! Always verify it matches the code.

## **settings.toml** File Tips
Here is an example **settings.toml** file.

```auto
# Comments are supported
CIRCUITPY_WIFI_SSID = "guest wifi"
CIRCUITPY_WIFI_PASSWORD = "guessable"
CIRCUITPY_WEB_API_PORT = 80
CIRCUITPY_WEB_API_PASSWORD = "passw0rd"
test_variable = "this is a test"
thumbs_up = "\U0001f44d"
```

In a **settings.toml** file, it's important to keep these factors in mind:

- Strings are wrapped in double quotes; ex: `"your-string-here"`
- Integers are _ **not** _ quoted and may be written in decimal with optional sign (`+1`, `-1`, `1000`) or hexadecimal (`0xabcd`).
  - Floats (decimal numbers), octal (`0o567`) and binary (`0b11011`) are not supported.

- Use `\u` escapes for weird characters, `\x` and `\ooo` escapes are not available in **.toml** files
  - Example: `\U0001f44d` for 👍 (thumbs up emoji) and `\u20ac` for € (EUR sign)

- Unicode emoji, and non-ASCII characters, stand for themselves as long as you're careful to save in "UTF-8 without BOM" format

&nbsp;

&nbsp;

When your&nbsp; **settings.toml&nbsp;** file is ready, you can save it in your text editor with the **.toml** &nbsp;extension.

![adafruit_products_dotToml.jpg](https://cdn-learn.adafruit.com/assets/assets/000/117/071/medium640/adafruit_products_dotToml.jpg?1671034293)

## Accessing Your **settings.toml** Information in **code.py**
In your **code.py** file, you'll need to `import` the `os` library to access the **settings.toml** file. Your settings are accessed with the `os.getenv()` function. You'll pass your settings entry to the function to import it into the **code.py** file.

```python
import os

print(os.getenv("test_variable"))
```

![](https://cdn-learn.adafruit.com/assets/assets/000/117/072/medium800/adafruit_products_tomlOutput.jpg?1671034496)

In the upcoming CircuitPython WiFi examples, you'll see how the **settings.toml&nbsp;** file is used for connecting to your SSID and accessing your API keys.

# Holiday IoT Switch

## Code the Switch

Once you've finished setting up your Feather ESP32-S2 with CircuitPython, you can access the code and necessary libraries by downloading the Project Bundle.

To do this, click on the **Download Project Bundle** button in the window below. It will download to your computer as a zipped folder.

https://github.com/adafruit/Adafruit_Learning_System_Guides/blob/main/IoT_Christmas_Lights_Switch/code.py

## Upload the Code and Libraries to the Feather ESP32-S2

After downloading the Project Bundle, plug your Feather ESP32-S2 into the computer's USB port with a known good USB data+power cable. You should see a new flash drive appear in the computer's File Explorer or Finder (depending on your operating system) called **CIRCUITPY**. Unzip the folder and copy the following items to the Feather ESP32-S2's **CIRCUITPY** drive.

- **lib** folder
- **code.py**

Your Feather ESP32-S2 **CIRCUITPY** drive should look like this after copying the **lib** folder and the **code.py** file.

![CIRCUITPY](https://adafruit.github.io/Adafruit_Learning_System_Guides/IoT_Christmas_Lights_Switch.png )

## Add Your **settings.toml** File

As of CircuitPython 8.0.0, there is support for [Environment Variables](https://docs.circuitpython.org/en/latest/docs/environment.html). Environment variables are stored in a **settings.toml** file. Similar to **secrets.py** , the **settings.toml** file separates your sensitive information from your main **code.py** file. Add your **settings.toml** file as described in the [Create Your settings.toml File page](https://learn.adafruit.com/blinka-led-sign/create-your-settings-toml-file) earlier in this guide. You'll need to include your `ADAFRUIT_AIO_USERNAME`, `ADAFRUIT_AIO_KEY`, `CIRCUITPY_WIFI_SSID` and `CIRCUITPY_WIFI_PASSWORD`.

```python
CIRCUITPY_WIFI_SSID = "your-ssid-here"
CIRCUITPY_WIFI_PASSWORD = "your-ssid-password-here"
ADAFRUIT_AIO_USERNAME = "your-username-here"
ADAFRUIT_AIO_KEY = "your-key-here"
```

## How the CircuitPython Code Works

The code begins by setting up the button as an input on pin **D5**. The state `lights_on` is set to `False`.

```python
button = digitalio.DigitalInOut(board.D5)
button.direction = digitalio.Direction.INPUT
button.pull = digitalio.Pull.UP
button_state = False

lights_on = False
```

## WiFi and IO

Next, the board connects to WiFi using your SSID and password information from your&nbsp; **settings.toml** file. After a connection is established, the board connects to Adafruit IO using HTTP and fetches the feed `lights`. If the feed does not exist, it creates a new feed called `lights`.

```python
aio_username = os.getenv("ADAFRUIT_AIO_USERNAME")
aio_key = os.getenv("ADAFRUIT_AIO_KEY")

print()
print("Connecting to WiFi...")
#  connect to your SSID
wifi.radio.connect(os.getenv('CIRCUITPY_WIFI_SSID'), os.getenv('CIRCUITPY_WIFI_PASSWORD'))
print("Connected to WiFi!")

pool = socketpool.SocketPool(wifi.radio)
requests = adafruit_requests.Session(pool, ssl.create_default_context())

io = IO_HTTP(aio_username, aio_key, requests)

try:
    feed_lights = io.get_feed("lights")
except AdafruitIO_RequestError:
    feed_lights = io.create_new_feed("lights")
```

## The Loop

In the loop, if the button is pressed it toggles the state of `lights_on`. The value of `lights_on` is sent to the `lights` feed as an integer (`0` for `False`, `1` for `True`).

The rest of the magic takes place with the itsaSNAP app and iOS Shortcuts. Make sure you follow along with the steps on the [iOS Shortcut Setup](https://learn.adafruit.com/holiday-iot-switch/ios-shortcut-setup) page to fully complete the project.

```python
while True:
    try:
        if not button.value and button_state:
            button_state = False
        if button.value and not button_state:
            print("pressed")
            lights_on = not lights_on
            io.send_data(feed_lights["key"], int(lights_on))
            button_state = True
    except Exception as error: # pylint: disable=broad-except
        print(error)
        time.sleep(5)
        microcontroller.reset()
```

### Holiday IoT Switch - iOS Shortcut Setup

[Holiday IoT Switch](https://learn.adafruit.com/holiday-iot-switch)
[iOS Shortcut Setup](https://learn.adafruit.com/holiday-iot-switch/ios-shortcut-setup)
# Holiday IoT Switch

## iOS Shortcut Setup

When you setup the [smart outlet](https://www.amazon.com/Tapo-Individual-Resistance-Certified-P400M/dp/B0CVN3CNCD) in Apple HomeKit, you can access it in Shortcuts and use itsaSNAP to access an Adafruit IO feed to turn the outlet on or off. You can download the Shortcut via the link below or build it out yourself using the steps below.

[Toggle Xmas Lights Shortcut](https://www.icloud.com/shortcuts/dcb5141e10d7429596e3635e4631a440)
## Shortcut for Toggling the Outlet
For this Shortcut, you'll be receiving data from itsaSNAP. You'll start with the itsaSNAP&nbsp; **Fetch Feed** action to read the most recent data from your feed.

![3d_printing_IMG_3847.jpg](https://cdn-learn.adafruit.com/assets/assets/000/134/191/medium640/3d_printing_IMG_3847.jpg?1734626035)

You'll use the **Match Text** action to check for a value from the incoming feed. Use an **If** action to check if the values match. If they do match, a **Control My Home** action is used to link into the outlet in Apple Homekit. Values of&nbsp; **0** and&nbsp; **1** are used to toggle the outlet on or off.

![3d_printing_IMG_3848.jpg](https://cdn-learn.adafruit.com/assets/assets/000/134/190/medium640/3d_printing_IMG_3848.jpg?1734625987)

In the Control My Home action, you'll be able to choose your smart outlet and select whether you want the action to turn the outlet on or off.

![3d_printing_IMG_3849.jpg](https://cdn-learn.adafruit.com/assets/assets/000/134/192/medium640/3d_printing_IMG_3849.jpg?1734626081)

## Hack the Automation

To add some automation to this process, you'll use [Adafruit IO Actions](https://learn.adafruit.com/how-to-use-blockly-for-actions-on-adafruit-io). Actions let you create tasks similar to the Shortcuts in iOS to have feeds trigger a series of events. In this case, you'll send an SMS message anytime a new value is added to the feed you're monitoring.

The SMS messaging Action is only available for IO+ users. However, if you do not have an IO+ account you can setup the Action to use email instead.

### Adafruit IO+ Subscription Pass – One Year

[Adafruit IO+ Subscription Pass – One Year](https://www.adafruit.com/product/3792)
The all-in-one Internet of Things service from Adafruit you know and love is now _even better_ with IO+. The 'plus' stands for MORE STUFF! More feeds, dashboards, storage, speed. Power up your [Adafruit IO](https://io.adafruit.com/) with the $99 pass for 1 year of the...

In Stock
[Buy Now](https://www.adafruit.com/product/3792)
[Related Guides to the Product](https://learn.adafruit.com/products/3792/guides)
![Text image that reads "IO+"](https://cdn-shop.adafruit.com/640x480/3792-01.jpg)

Info: The SMS messaging Action is only available for IO+ users. However, if you do not have an IO+ account you can setup the Action to use email instead.

Create an Action that uses a **Reactive trigger**. For the F **eed** , select your **lights feed**. For **Operator** , select **any**. Leave the **Feed or Value section blank**. This alerts for any new value on the feed. For the **Action** select **SMS** (or Email). You can leave the body as the default entry. For **...using** select the **same lights feed**.

![](https://cdn-learn.adafruit.com/assets/assets/000/134/185/medium800/3d_printing_Screenshot_2024-12-19_112256.png?1734625501)

You can test this Action by sending a **0** or **1** to your feed with the CircuitPython code on the Feather, the itsaSNAP app or in a browser with Adafruit IO directly. When you change the value, you should receive a text.

![3d_printing_IMG_3852.jpg](https://cdn-learn.adafruit.com/assets/assets/000/134/186/medium640/3d_printing_IMG_3852.jpg?1734625615)

If you don't want to be notified every time a text comes in, you can **toggle Hide Alerts**. This lets the process run in the background.

![sensors_IMG_3074.jpg](https://cdn-learn.adafruit.com/assets/assets/000/132/764/medium640/sensors_IMG_3074.jpg?1727794105)

Now comes the hack! Head over to the Shortcuts app and create a **new Automation**. Select a **Message automation** if you have an SMS action setup. If you setup an email action, select Email.

![sensors_IMG_3072.jpg](https://cdn-learn.adafruit.com/assets/assets/000/132/765/medium640/sensors_IMG_3072.jpg?1727794137)

Under **Sender** select the **Adafruit IO number**. Under **Message Contains** , enter the **name of your feed** since it will be in every text from the Action. Check off **Run Immediately**.

![3d_printing_IMG_3850.jpg](https://cdn-learn.adafruit.com/assets/assets/000/134/187/medium640/3d_printing_IMG_3850.jpg?1734625664)

Choose the **Shortcut** that you setup to **toggle the outlet**.

![3d_printing_IMG_3851.jpg](https://cdn-learn.adafruit.com/assets/assets/000/134/188/medium640/3d_printing_IMG_3851.jpg?1734625723)

Now when you change the value with the button attached to the Feather, the feed updates and sends a text to your iOS device. When the text is received, the Shortcut runs and you'll see your outlet turn on or off.

# Holiday IoT Switch

## Wiring

## Quick Connects

Use two pairs of quick connect cables. Remove the JST connectors from the cables. Remove a bit of insulation from each wire and apply solder to tin them.

![3d_printing_QC-cables.jpg](https://cdn-learn.adafruit.com/assets/assets/000/134/193/medium640/3d_printing_QC-cables.jpg?1734635953)

![3d_printing_QC-cables-prep.jpg](https://cdn-learn.adafruit.com/assets/assets/000/134/194/medium640/3d_printing_QC-cables-prep.jpg?1734635958)

![3d_printing_feather-cables.jpg](https://cdn-learn.adafruit.com/assets/assets/000/134/198/medium640/3d_printing_feather-cables.jpg?1734635999)

## Connect Wires to Feather

Solder the two blue wires to the ground pin on the Feather.

Solder a white wire to the 3V pin on the Feather.

Solder the second white wire to D5 pin on the Feather.

![3d_printing_QC-gnd-solder.jpg](https://cdn-learn.adafruit.com/assets/assets/000/134/195/medium640/3d_printing_QC-gnd-solder.jpg?1734635971)

![3d_printing_QC-3V-solder.jpg](https://cdn-learn.adafruit.com/assets/assets/000/134/196/medium640/3d_printing_QC-3V-solder.jpg?1734635979)

![3d_printing_QC-D5-solder.jpg](https://cdn-learn.adafruit.com/assets/assets/000/134/197/medium640/3d_printing_QC-D5-solder.jpg?1734635984)

## Arcade Button

Remove the switch and LED assembly from the arcade button by turning it counter-clockwise and pulling it out from the stem.

Unscrew the plastic hex nut from the stem of the button.

Remove the hub panel from the stem.

![3d_printing_button-parts.jpg](https://cdn-learn.adafruit.com/assets/assets/000/134/203/medium640/3d_printing_button-parts.jpg?1734636074)

## Connect Wires to LED & Switch

Plug one of the ground wires from the Feather to the ground terminal on the LED.

Plug the 3V wire from the Feather to the anode terminal on the LED.

Plug the D5 wire from the Feather to the NO terminal on the switch.

Plug the remaining ground wire to the COM terminal on the switch.

![3d_printing_BLED-gnd.jpg](https://cdn-learn.adafruit.com/assets/assets/000/134/200/medium640/3d_printing_BLED-gnd.jpg?1734636031)

![3d_printing_BLED-3V.jpg](https://cdn-learn.adafruit.com/assets/assets/000/134/201/medium640/3d_printing_BLED-3V.jpg?1734636038)

![3d_printing_BLED-NO.jpg](https://cdn-learn.adafruit.com/assets/assets/000/134/202/medium640/3d_printing_BLED-NO.jpg?1734636053)

## Connected Feather

Take a moment to ensure the quick connect wires are attached to the correct terminals on the switch and LED.

![3d_printing_QC-feather-soldred.jpg](https://cdn-learn.adafruit.com/assets/assets/000/134/199/medium640/3d_printing_QC-feather-soldred.jpg?1734636015)

# Holiday IoT Switch

## Assembly

## Install Button

Insert the button into the top cover with the notches lined up.

Place the hub panel onto the stem of the arcade button.

Screw the plastic hex nut onto the stem and tighten.

![3d_printing_button-cover.jpg](https://cdn-learn.adafruit.com/assets/assets/000/134/204/medium640/3d_printing_button-cover.jpg?1734636147)

![3d_printing_button-cover-install.jpg](https://cdn-learn.adafruit.com/assets/assets/000/134/205/medium640/3d_printing_button-cover-install.jpg?1734636154)

![3d_printing_button-cover-nut-instal.jpg](https://cdn-learn.adafruit.com/assets/assets/000/134/206/medium640/3d_printing_button-cover-nut-instal.jpg?1734636166)

## Install Switch LED

Push the switch/LED assembly into the bottom of the stem and twist clockwise to lock into place.&nbsp;

![3d_printing_button-switch-install.jpg](https://cdn-learn.adafruit.com/assets/assets/000/134/207/medium640/3d_printing_button-switch-install.jpg?1734636195)

## Install Case

Fit the two case parts together so the hole for the feathers USB port are lined up.&nbsp;

![3d_printing_case-colors.jpg](https://cdn-learn.adafruit.com/assets/assets/000/134/208/medium640/3d_printing_case-colors.jpg?1734636210)

![3d_printing_case-colors-install.jpg](https://cdn-learn.adafruit.com/assets/assets/000/134/209/medium640/3d_printing_case-colors-install.jpg?1734636217)

![3d_printing_case-colors-installed.jpg](https://cdn-learn.adafruit.com/assets/assets/000/134/210/medium640/3d_printing_case-colors-installed.jpg?1734636226)

## Install Top

Place the top cover over the case so the notches are lined up.

Firmly press the top cover into the case.

![3d_printing_cover-case-install.jpg](https://cdn-learn.adafruit.com/assets/assets/000/134/211/medium640/3d_printing_cover-case-install.jpg?1734636242)

## Install Feather

Place the Feather onto the built-in standoffs on the bottom cover with the USB port facing the edge.

Use two M2.5 x 6mm long steel machine to secure the Feather to the bottom cover.

![3d_printing_feather-btm-install.jpg](https://cdn-learn.adafruit.com/assets/assets/000/134/212/medium640/3d_printing_feather-btm-install.jpg?1734636256)

![3d_printing_feather-btm-secured.jpg](https://cdn-learn.adafruit.com/assets/assets/000/134/213/medium640/3d_printing_feather-btm-secured.jpg?1734636262)

## Install Bottom Cover

Insert the bottom cover into the case with the USB port holes lined up.

![3d_printing_btm-case-install.jpg](https://cdn-learn.adafruit.com/assets/assets/000/134/214/medium640/3d_printing_btm-case-install.jpg?1734636278)

## Secure Bottom Cover

Line up the mounting holes on the bottom cover with the mounting tabs in the case.

Use four M3 x 6mm long steel machine screws to secure the bottom cover to the case.

![3d_printing_btm-case-secure.jpg](https://cdn-learn.adafruit.com/assets/assets/000/134/215/medium640/3d_printing_btm-case-secure.jpg?1734636290)

## USB Power

Connect a USB-C cable into the USB C port on the Feather ESP32 S2.

Connect the USB-C cable to a 5V 1A power supply.

![3d_printing_USB-power.jpg](https://cdn-learn.adafruit.com/assets/assets/000/134/216/medium640/3d_printing_USB-power.jpg?1734636303)

## Install Bezel

Snap the matching colored bezel onto the arcade button. Use double-sided tape or glue to adhere the bezel.

![3d_printing_bezel-install.jpg](https://cdn-learn.adafruit.com/assets/assets/000/134/217/medium640/3d_printing_bezel-install.jpg?1734636318)

## Connect Smart Plug

Plug the [TP-Link Tapo](https://www.amazon.com/gp/product/B0CVN3CNCD/) device into a wall outlet, then plug in lights or other appliance to the outlet 1 (the outlet on the left).

The green light will power on when the outlet is on.

![3d_printing_tapo-tree-white.jpg](https://cdn-learn.adafruit.com/assets/assets/000/134/238/medium640/3d_printing_tapo-tree-white.jpg?1734711033)

## Final Build

Press the button to turn on/off the smart outlet.

Congrats on your build!

![3d_printing_final-build.jpg](https://cdn-learn.adafruit.com/assets/assets/000/134/218/medium640/3d_printing_final-build.jpg?1734636335)


## Featured Products

### Adafruit ESP32-S2 Feather - 4 MB Flash + 2 MB PSRAM

[Adafruit ESP32-S2 Feather - 4 MB Flash + 2 MB PSRAM](https://www.adafruit.com/product/5000)
What's Feather-shaped and has an ESP32-S2 WiFi module? What has a STEMMA QT connector for I2C devices? What has your favorite Espressif WiFi microcontroller and lots of Flash and RAM memory for your next IoT project? What will make your next IoT project flyyyyy?

That's right -...

In Stock
[Buy Now](https://www.adafruit.com/product/5000)
[Related Guides to the Product](https://learn.adafruit.com/products/5000/guides)
### Massive Arcade Button with LED - 100mm White

[Massive Arcade Button with LED - 100mm White](https://www.adafruit.com/product/1187)
OMG WATCH OUT! This 100mm diameter arcade button with a **10mm deep plastic base** is so massive and inviting it may collapse upon itself and form a black hole from which not even light can escape! Until it does, however, it ready for all sorts of pressing and pushing. Science...

In Stock
[Buy Now](https://www.adafruit.com/product/1187)
[Related Guides to the Product](https://learn.adafruit.com/products/1187/guides)
### Arcade Button and Switch Quick-Connect Wires - 0.187" (10-pack)

[Arcade Button and Switch Quick-Connect Wires - 0.187" (10-pack)](https://www.adafruit.com/product/3835)
Quick connector wire sets make wiring up our arcade-style or metal buttons quicky-quick. Each wire comes as a 'pair' with two 0.187" quick-connects pre-crimped. The wires are terminated together in a JST 2.5mm 2-pin connector. This connector will fit in 0.1" headers,...

In Stock
[Buy Now](https://www.adafruit.com/product/3835)
[Related Guides to the Product](https://learn.adafruit.com/products/3835/guides)
### Pink and Purple Woven USB A to USB C Cable - 2 meters long

[Pink and Purple Woven USB A to USB C Cable - 2 meters long](https://www.adafruit.com/product/5044)
This cable is not only super-fashionable, with a woven pink and purple Blinka-like pattern, it's also made for USB C for our modernized breakout boards, Feathers and more.&nbsp; [If you want something just like it but for Micro B, we have a B...](https://www.adafruit.com/product/4111)

Out of Stock
[Buy Now](https://www.adafruit.com/product/5044)
[Related Guides to the Product](https://learn.adafruit.com/products/5044/guides)
### 5V 1A (1000mA) USB port power supply - UL Listed

[5V 1A (1000mA) USB port power supply - UL Listed](https://www.adafruit.com/product/501)
Need a USB jack for charging or powering a project, but don't want to lug around a computer? This switching supply gives a clean regulated output at up to 1000mA! 110 or 240 input, so it works in any country. The plugs are "US 2-prong" style so you may need a plug adapter, but...

In Stock
[Buy Now](https://www.adafruit.com/product/501)
[Related Guides to the Product](https://learn.adafruit.com/products/501/guides)
### Adafruit IO+ 1 Year Subscription Card

[Adafruit IO+ 1 Year Subscription Card](https://www.adafruit.com/product/3980)
It's the Internet of the Things!&nbsp;[Adafruit IO+](https://io.adafruit.com/plus) is the easiest way to stream, log, and interact with your data. Whether you're interesting in&nbsp;datalogging or communicating with your microcontroller over the web, Adafruit IO is our cloud...

In Stock
[Buy Now](https://www.adafruit.com/product/3980)
[Related Guides to the Product](https://learn.adafruit.com/products/3980/guides)

## Related Guides

- [Adafruit ESP32-S2 Feather](https://learn.adafruit.com/adafruit-esp32-s2-feather.md)
- [CircuitPython Web Workflow Code Editor Quick Start](https://learn.adafruit.com/getting-started-with-web-workflow-using-the-code-editor.md)
- [IoT Filament Sensor](https://learn.adafruit.com/iot-filament-sensor.md)
- [No-Code IoT Pool Monitor](https://learn.adafruit.com/iot-pool.md)
- [Espresso Water Tank Meter](https://learn.adafruit.com/espresso-water-tank-meter.md)
- [Nunchuck Controlled Laser Cat Toy](https://learn.adafruit.com/nunchuck-controlled-laser-cat-toy.md)
- [TFT Spirit Board](https://learn.adafruit.com/tft-spirit-board.md)
- [Control Wiz Lights With CircuitPython](https://learn.adafruit.com/control-wiz-lights-with-circuitpython.md)
- [Adafruit USB Host FeatherWing with MAX3421E](https://learn.adafruit.com/adafruit-usb-host-featherwing-with-max3421e.md)
- [No-Code IoT Humidity and Temperature Sensor with Adafruit IO WipperSnapper](https://learn.adafruit.com/no-code-humidity-and-temp-tracker.md)
- [Introducing Adafruit Feather](https://learn.adafruit.com/adafruit-feather.md)
- [Networking in CircuitPython](https://learn.adafruit.com/networking-in-circuitpython.md)
- [ESP-NOW in CircuitPython](https://learn.adafruit.com/esp-now-in-circuitpython.md)
- [LED Emerald with Circuit Playground Bluefruit](https://learn.adafruit.com/led-emerald-with-circuit-playground.md)
- [Visual Studio Code for Education... and CircuitPython](https://learn.adafruit.com/visual-studio-code-for-education-and-circuitpython.md)
