Tuesday, 14 June 2022

HA : WLED

I purchased a WS2812B LED strip over a year ago.  The LEDs are individually addressable, allowing you to set up patterns on the lights.  I didn't get around to doing anything with them until I saw that they can be controlled using an app called WLED which in turn can be integrated with Home Assistant (HA).  I think the W in WLED stands for wifi; LEDs are connected to an ESP8266 which controls them and the WLED iPAD app allows you to configure patterns.

Arduino Setup

My first task was to setup an ESP8266 and connect the LED strip.  I used an article by mechatronics to guide me, it shows the connections are very simple.




I then loaded the example sketch, which uses the FastLED library, into ESP8266 and it works, without modification, displaying an attractive red / blue pattern on the LEDs .  Always a pleasant surprise when this happens😊

The sketch shows that displaying a pattern is simply a matter of putting correct colour values in the array leds[] and calling FastLED.show to display them.  They pattern can be made to change by adding loop to the sketch specifying how the pattern changes each time.  It gives me complete control of which LEDs are are used, what colours they are and when they change from a C program😊

WLED Install

WLED runs on an ESP8266 to control the strip.  It has a ultra-cool website URL kno.wled.ge  which provides the relevant installation instructions.  WLED is loaded into the ESP8266 using a utility esptool.py.  I downloaded esptool.py and WLED 0.13.1 to WSL then ran esptool.py to flash WLED onto the ESP8266.   ESP8266 starts up with an access point WLED-AP.  I attach to WLED-AP and go to address 4.3.2.1 in my browser to connect to the ESP program.

Now all I have to do is configure my Wifi network and password, then restart and I can access the browser app from any local network browser😊

WLED is surprisingly complicated to use; there are over 100 effects you can use to create LED patterns and a variety of colour palettes you can choose.  You can set the speed, select groups of LEDs and string a sequence of patterns together.  


Luckily there are various youtube tutorials to help you and kno.wled.ge provides a list.  I used a couple of tutorials by Dr zzs to give me the general idea.

WLED API

I dont find it easy to setup devices based on a graphical user interface, it is too easy to forget/overlook details.  WLED provides both HTTP and JSON APIs allowing you to control WLED remotely.  JSON is the newer, more complete interface which is easier to code / read so I concentrated on setting up some JSON configs.  Curl is used to send WLED API commands, as a simple example the following command turns the LED strip on.


In practice it is better to put the json into a file, the example below causes WLED to blink LEDs 30 to 40 in the strip between blue and green.
Now that I have a mechanism to program WLED I can create a variety of configs for the lights.  WLED allows you to setup presets to store configurations; once I have downloaded a configuration I save it in a preset.

HA and GA

There is a HA native integration for WLED making it trivial to include it within the system.  HA allows you to control individual elements, however I think it is easier to setup presets as shown above then invoke them within HA.



Now WLED can be controlled by running a HA script and I can set up a routing in Google Home for voice control of LEDs, job done😊



No comments:

Post a Comment