An Arduino-based smart "switch" that fits over a regular switch and physically flips it on demand (because we're all just renters these days).
Uses MQTT to integrate with Home Assistant.
My first electronics project!
- Arduino Nano ESP32
- Small servo motor
- Tools and other materials:
- Infrastructure
- Mosquitto or other MQTT server install
- Home Assistant install with the MQTT integration connected
- Setup the Arduino IDE with the ESP32 and MQTT libraries (on Linux, you may need to add
SUBSYSTEMS=="usb", ATTRS{idVendor}=="2341", ATTRS{idProduct}=="0070", MODE:="0666"
to/etc/udev/rules.d/60-arduino-esp32.rules
). - Copy
template.creds.h
tocreds.h
and fill it in if you want to (if not, you'll need to configure connection settings via Bluetooth). - Strip a centimeter or so of insulation off each of the three wires of the servo (power, ground, control).
- Do the same for 3 wires that end in female jumper pins. Coordinating colour with the 3 servo wires is recommended.
- Manually twist the exposed end of the power wire from the servo motor with a corresponding female jumper wire for a loose attachment.
- Do the same for the servo ground wire.
- Solder the 2 power wires (that were twisted together to form "one wire") to the
VIN
pin on the Arduino.- You could use the breadboard to prototype everything first.
- Solder the "merged" ground wire to one of the
GND
pins on the Arduino. - Solder the servo control wire to either the
D3
,D6
, orD7
ports on the Arduino.- Only one pin is technically used but the code outputs to all 3 - this is a lazy way to "correct" a soldering error in my builds.
- Solder the remaining hanging wire (the third female jumper wire) to the
VBUS
pin on the Arduino. - Connect a USB-C power supply to the device. It should show up in Home Assistant with a permanent randomly-generated ID, and should be usable immediately.
- Depending on the motor used and how you set it up, you may need to modify some variables under
// Hardware config
- experiment with what values work for you. - Note that the code does support a push button connected to pin
D5
, but I ended up not using one for my build.
- Depending on the motor used and how you set it up, you may need to modify some variables under
- Use the aluminium strips and double sided tape to securely mount everything over your existing dumb switch.
- Obviously, skip this in the prototyping stage.
- The female jumpers are used to power a second switch without needing a second USB-C power supply.
- Using a male-male wire, connect the
VBUS
-attached pin of the USB-powered switch to theVIN
-attached (power) pin on the second switch. - Do the same to connect the
GND
-attached pins of both switches. - Due to power constraints, only 1 switch can be attached in this way.
- Using a male-male wire, connect the
- After the board is plugged in, it should automatically connect to the configured MQTT server. If you did not put configuration variables in
creds.h
, you can use a Bluetooth LE scanner app to configure the switch via Bluetooth (as instructed in the Bluetooth characteristic). The blinking lights you see on boot represent a 6 digit code you will need to include when configuring the switch.
Hey, I never said it was pretty.