Digital LED Smart Clock – Alexa Controlled

April 24, 2019

Today on the hookup I was going to teach you how to combine amazon alexa emulation with echo’s built in routines functionality to allow for advanced control of your projects without the need for a hub, but I accidentally built a cool alexa controlled LED clock while explaining it, so stick around if you’re interested in either of those things!.

A few weeks ago my elementary aged nephew came to visit all the way from Chicago, and he’s got the tinkerer gene for sure.  In his carry on bag he packed his Nintendo switch, a raspberry pi, an Arduino uno and a few LED strips.  As you can imagine, this was my time to shine as the “cool uncle”, so we set out to do a fun project together.  He showed me how he uses tinkerCAD to create 3D models and together we designed personalized LED nightlight for his room using an ESP8266.  There was just one small problem:  He doesn’t have smart things, home assistant, a computer, or a cell phone in his room to be able to control this project wirelessly.  He does however have an amazon echo dot, so we needed to be able to build in all the desired functionality using just alexa commands.

Over the last few years there have been a bunch of different libraries developed for Arduino to emulate local devices to use with amazon echo.  The first devices emulated the Belkin wemo protocol but only offered a binary on/off state.  More recently the emulation has switched to the more powerful Philips hue protocol and the library called ESPAlexa developed by aircookie supports brightness, color, and on newer echo devices it even supports color temperature.  Since each ESP8266 device can emulate up to 10 different hue devices, you can cram a lot of different control into one project.

Today we’re going to look at a simple LED project that I download from thingiverse called “lazy grid clock” and printed on my 3d printer. The LEDS that I’m using are WS2812B leds, but the slightly denser 300 LED per 5m edition.  This project creates a 7 by 11 grid of LEDS for us to play with. I’m using this project for the purpose of this video, but you can apply these concepts to any echo controlled project.

In our sketch were going to build in some effects using the fastLED library.  I’m not writing these from scratch, they are just taken from my HolidayLED 2.0 sketch that I use for the LEDs mounted to the roof of my house.  The difference is, instead of using MQTT to control the colors and effects we’re going to use the ESPAlexa library and a little bit of out of the box thinking.  My sketch requires 3 things: Overall brightness control, color control for 3 individual colors, and  effect control.  This means that I’m going to have to emulate at least 3 devices to be able to control my 3 different colors and then determine how to deal with color control.  The first device I’m going to call Smart Clock, my second device is going to be called Clock Color Two, and my third device is going to be called Clock Color Three.

Each of these devices can have their brightness and color set individually via my amazon echo.  Which means I’ll be able to have 6 distinct command channels for my project.  I’ll be using the RGB color controls for each device to set the 3 different colors for my animations.  I’ll use the brightness of the “Smart Clock” device to set the main brightness for the grid, I’ll use brightness of “Clock Color Two” to set the effect of my project, and I’ll use the brightness of “Clock Color Three” to modify the different properties of each effect.  If using the brightness values of a device seems like a stupid and clunky way to control effects, stick with me, I promise it will make sense later.

In my code I’ll modify the different callbacks for each echo command to change the property I want.  That means for “Smart Clock” the brightness will be assigned to the global brightness variable, and RGB color information will be saved to Red1, Green1, and Blue1.  For “Clock Color Two” I’ll use the RGB color information for Red2, Green2, and Blue2, and I’ll use the brightness information to assign different values to my effect variable.  In my example here I just took 100 percent of brightness and divided that by the number of effects that I wanted to be able to select from.  I then used if statements to figure out which effect to set.  A switchcase probably would have been the better way to program this, but I decided to use if statements because I think they are easier for learning programmers to understand.

For Clock Color Three the RGB color information is going to become Red3, Green3, and Blue3, and my brightness information is going to become the effect modifier.  This is the only echo command that will be a little bit clunky since you’ll have to say things like “turn Clock Color 3 to 80” in order to modify the current pattern.  If you wanted to avoid this odd speech you could add a fourth device called Grid Effect to solve that issue.

Now that we’ve gone over the code we can upload to the NodeMCU and get our LEDS hooked up.  This sketch uses pin D2 for the LED data pin and I’m going to power the NodeMCU with 5 volts connected to the Vin pin and ground connected to ground.  I wouldn’t recommend trying to power all 83 LEDs using the USB input the nodeMCU because that will put a lot of strain on the voltage regulator and will likely cause it to fail.  Instead you should split your 5v source and attach one side of the split to your nodeMCU and the other to your LED strip.  A trick that I like to use is connecting the power injection wires directly to the 5V AC adapter and then using the connector that comes with the LEDS to provide 5V and ground to the nodeMCU.

Once you’ve got all your connections made you can power up your project, start your alexa app and hit search for new devices.  Your 3 devices should be automatically discovered and set up for you.  You can click on them to test out your project. “Smart Clock” should turn the device on and off, adjust the brightness, and set color1, “Clock color two” should change color 2, and the brightness slider should change the effect when changed in increments of 10.  You can see the different effects here and how they change with the brightness slider.  Finally “clock color 3” should set color 3 and the brightness slider should modify the properties of each effect.  These properties are things like the speed of the animation and the frequency of the random glitter effects.  But again, these controls are far from user friendly, so it’s time to set up some routines.

We don’t want to have to remember to say “set Grid Color Two to 30 to turn on the rainbow effect, we want to be able to say “set the clock to rainbow”.  To do this, click on routines and hit “new routine”.  You’ll want to choose a voice event for the trigger, I’m going to use the phrase “change the effect to rainbow”, but you can choose almost any phrase you want.  Under action we’ll go to smart home, then “clock color two” and set brightness to 30.  Now whenever we say “change the effect to rainbow” it will actually set grid color two to 30% brightness, which is interpreted by the NodeMCU as setting the effect to rainbow.

This is a fun an useful hack because it allows makers like us to produce projects that can end up in other people’s homes without having to support any cloud api or service, and the alexa local integration is pretty stable and responsive, so tech support issues should be kept to a minimum.

As I said, this concept doesn’t just apply to LED projects, it can be used to give powerful control to any DIY project without needing to have a hub or bridge device in the end user’s home.  If you’re interested in building this exact project I’ve left links to the excellent thingiverse project made by the user Parallyze, and I’ve put amazon links for all of the products I used.  The code I made is also down in the description if you want to modify it for your own project.

Some interesting applications of this clock could be changing colors for a kid to signify playtime, cleanup time, bedtime, screentime, homework time or any other specific time that you regulate for your kid, and basically all of that can be done with routines within the echo app without additional coding.  I’ve got a bunch of other ideas that I’m going to implement like timer and a stopwatch functionality, but seeing as I just kinda made this project by accident I haven’t fully implemented them yet.  Check the github page for updates.

Speaking of modifying code, I’m currently in the process of updating most of my projects to include Echo, smartthings, habitat, and OpenHAB support in addition to the standard MQTT based home assistant integration that they were originally designed for.  If you’re an openHAB user and you’d be willing to write the “things”, “items”, “sitemap”, and “rules” files for my projects please leave a comment below or send me an email.  If you’re a smartThings or habitat user please let me know if you’d be willing to beta test my integrations.  If you’re interested in supporting my channel you can use the affiliate links in the description or support me directly through patreon like these awesome people.  If you enjoyed this video and you’d like to see more like it please consider subscribing, and as always, thanks for watching the hookup.

+++Github and Code+++

https://github.com/thehookup/Alexa-Enabled-LED-Clock

 

+++Parts List+++

NodeMCU: https://amzn.to/2I89xDF

WS2812 LEDS 300/5m: https://amzn.to/2XEJPdR

5V Power Supply: https://amzn.to/2VlOns2

 

+++Thingiverse Project+++

https://www.thingiverse.com/thing:3241802

 

+++Alexa Emulation Library+++

https://github.com/Aircoookie/Espalexa

 

Visit my website: http://www.thesmarthomehookup.com

Follow me on Twitter: @TheHookUp1

 

Support my channel:

Patreon: https://www.patreon.com/thehookup

 

Tesla Refferal Code: https://www.tesla.com/referral/robert37264

Related Posts