• Matthew Dunlap

Motion Thermostat Using Puck.js, Kasa Smart Plug, and IFTTT

Whenever I wish to turn on the light, I walk over to the light switch and press or flick the switch. If the light is connected via a smart plug or has IoT capabilities, I will simply ask my voice assistant on my smart phone to turn on the light. Moments later: illumination. However, what if neither of those are possible?

A small disc-shaped device inscribed with "Puck.js" is held in front of a fan that is installed into a window. The disc is about the diameter and depth of a large watch.
The Puck.js microcontroller is being used to control the fan shown in the background.

My sister has a disability that serverly restricts her from performing common everyday tasks. The above example of turning on a light is impossible because she cannot walk, operate the light switch, or even speak to a voice assistant. While pondering ways to allow her to operate such devices, I discovered Puck.js. Shown above, this tiny device packs a button, magnetometer, gyro, infrared emitter, infrared receiver, three LEDs, temperature and light sensors, and a programmable NFC tag. All of this functionality is accessible via Bluetooth Low Energy (BLE) using any device that supports the wireless protocol. If one were to program the puck carefully, the device may run a single CR2302 button cell battery for over a year.


For many years, I have been thinking of ways to enable my sister operate her television, lights, or anything. While growing up, she received a Barbie doll for almost every holiday and birthday. She has amassed a large collection of dolls and would occasionally have a specific doll by her side. Eventually, we found that the legs of the doll were the perfect shape/size for her to grasp. She would hold on to the Barbie and shake her arm to make it dance.


To my amazement, this same motion could be harnessed for signaling to other devices using Puck.js. The puck meets all of the requirements needed to be used by my sister. It has an accelerometer; it is wireless, small, and light; and has low power requirements. Gasping for breath, I immediately purchased two of these devices. I finally found a way!


After receipt of both pucks, I realized that I needed a simple way to test the device and familiarize myself to the workings of BLE. A month ago, I installed a fan in one of my kitchen windows as my century old apartment lacked a stove vent. In addition, the summers in NYC made cooking anything in our kitchen a hellish experience. While the fan had a vent that automatically closed to keep the elements out when venting was no longer required, it didn't have a thermostat to regulate the temperature. My solution was to use a puck to read the temperature and report it back to a Raspberry Pi server that is already running 24/7. The pi would turn the fan on and off using IFTTT webhooks and a Kasa smart plug.


While the fan is a massive asset, it can be very loud and annoying. Therefore, I decided to make a kill switch that would override the temperature sensor and shut the fan off. Thinking that this would allow me test the puck's ability to detect motion, I looked for a way to have the fan kill switch be active when the puck was flipped upside down. (Which feels like playing a weird game of Reversi.) Fortunately, the puck contains a module called "puckjsv2-accel-tilt" which can wait for movement in order to detect the tilt level while only consuming 40uA of power. Since a typical CR2302 contains 235 mAh of capacity, this means that the puck in stand-by mode may last about 8 months on a full battery!


If you want to try the code for yourself, the project and full instructions are posted on my Github.