WLED custom animations – Making the DIY smart wardrobe even more awesome

Published by Oliver on

A simple DIY smart wardrobe with lights that turn on and off automatically is awesome. Using the digital LEDs to their full potential and adding WLED custom animations is even better. This is how I upgraded my wardrobe lights.

The smart wardrobe lights

In an earlier article I described how I build my smart wardrobe light setup. It is relatively cheap works well and looks awesome. It was not using its full potential though. When I started the build I decided to not go with the standard analogue LEDs but instead with “digital” ones. The WS2812B I am using have a data line running through all the individual LEDs on the strip that allows me to control each one individually.

To fully utilize the individually controllable LEDs I had always planned to add some animations. The WLED software I am using supports a wide range of pre-made animations already. It is very simple to make the LEDs display some patterns instead of just switching them on or off. I did notice very soon though that “useless” animations do annoy me more than they help. Instead I wanted a sliding on and off motion where the LEDs turn on or off one by one following the motion of the door.

The WLED wipe animation

WLED supports different animations, one of them called wipe which turns on one LED in the strip after another. Sounds like what I wanted but unfortunately it does not stop when all LEDs are switched on. Instead they are all switched off and the animation starts again, cycling endlessly.

I hope that WLED will one day get a setting for to disable this but right now there is a workaround. WLED supports custom animations and someone has already added one that can be used in my case. Using a WLED custom animation requires a little bit more work though, as you need to compile the code yourself. Fortunately that is easier than it sounds.

Setting up a development environment for WLED

To build the custom version of WLED we first need the codebase. So go ahead and git clone the repository git clone https://github.com/Aircoookie/WLED.git. Now we need an easy way to change and compile the new code. The best way right now in my opinion is using Visual Studio Code and PlatformIO. The code comes with a premade config file for PlatformIO so this setup is quite simple.

First go and install Visual Studio Code, a great versatile and pretty lightweight IDE. Once the VS code is running select the extensions tab on the left side and install the PlatformIO IDE integration. After one restart you are ready to go.

The extension tab on the left side with the PlatformIO plugin installed

Click the new PlatformIO icon on the left side to go the main screen of the plugin and click open project to select the folder with the source code we downloaded earlier. VS Code and PlatformIO will now automatically install any dependencies and open the project files.

Create a WLED custom animation

We do not want to create a new animation from scratch here, but instead use a premade one. The WLED code contains a usermods directory which has a starway_wipe_basic folder with some custom animation code inside. We can use this by copying the code from the ino file inside that folder to the usermod.cpp in the main WLED code directory.

For the Arduino code to work in this environment we need to add some imports and a couple of definitions at the start of the file:

#include <Arduino.h>
#include "wled.h"

void startWipe();
void turnOff();

Now that this is done we can compile the new code. This is done by clicking the small check mark icon in the bottom.

Compile button in the middle

If you did not change any configurations PlatformIO will now download any missing dependencies and build three different variations of WLED for different platforms. If everything runs without errors the final files should be in the .pio/build directory. Either the travis_esp8266 or the esp01_1m_ota will most likely be the files you need. In my case because of errors with the esp8266 variant I had to use the esp01 version.

Getting the new code onto your LED controller

Now that we have the custom firmware including the new WLED custom animation we need to get it onto the LED controllers. There are two ways of doing this. The most simple one is using the included OTA (over the air) update functionality.

If you open the WLED web interface and click on config security & updates you will see a manual OTA update button. Just select the new firmware by going to the build folder mentioned above and select the respective firmware.bin file. Click Update! and the code will be uploaded.

WLED OTA screen for uploading new firmware

If you have the controller nearby or, like in my case, there are problems uploading the code via OTA you can still upload it directly via a USB cable. Just disconnect any other cables from the Wemos D1 mini (including the LEDs) and instead connect it to your PC via a micro USB cable. Now you can use any flashing software to upload the new firmware.

uploading the wled custom animation via Tasmotizer
Tasmotizer can be used to upload any firmware by using the BIN file option

I decided to use the Tasmotizer software from my article about Tasmota. Just use the BIN file option, select the right COM port and the firmware.bin file and click Tasmotize!.

The endresult

Once the code was uploaded I slightly changed my control code to activate the new WLED custom animation. My rules file will now not send a message via MQTT but instead send a HTTP request setting the U0 custom variable that is used to run the activation and deactivation animation.

rule "Switch lights on/off when the right cabinet door opens/closes"
when
	Item cabinetR_state received update
then
    logDebug("Rule", "Cabinet light updating. Contact 1 is {}", cabinetR_state.state)

    if (cabinetR_state.state == OPEN) {
        //WLED_schrankR.sendCommand(ON)
        sendHttpGetRequest("http://wled-schrank1/win&U0=2")
    }

    if (cabinetR_state.state == CLOSED) {
        //WLED_schrankR.sendCommand(OFF)
        sendHttpGetRequest("http://wled-schrank1/win&U0=0")
    } 
end

Afterwards I slightly adjusted the animation speed via the web interface so that the animation runs about as fast as I normally open the wardrobe doors.

Now when I open the doors the LED strip turns on one light by one following the doors motion. It stays on until I close the door again when it turns off one by one. Pretty awesome lighting 🙂

In the future I hope this process will get easier when a feature to stop repetitions of animations is added. I created a feature request and hope someone will have the time to add this and make the already awesome software even better.