In this video I'm going to show you how to add digital LED strip
into Home Assistant using ESPHome like this.
Now make sure you stick around, and if you like what you see hit subscribe so
you don't miss out on future videos.
Hi I'm Will from Will Surridge Tech. Today I'm going to take you through all the
steps in integrating a digital LED strip into Home Assistant
using ESPHome. First we're going to look at the WS2812B
LED strip, then we're looking at some simple circuitry to connect it to a
Wemos D1 Mini, after that we'll flash it with ESPHome
before finally integrating it into Home Assistant so we can play with effects or
use it in automations. If you stick around until the end I'll
show you a very simple automation that I've created for mine
which lets me know when my phone battery gets too low. So
what is WS2812B digital LED strip? Well let's break it down.
LED strip is a strip with LEDs on it. It is used when you want to create a
long line of light so it can be used in ceilings of big open spaces like
warehouses or garages or on countertops. It is often used to
replace fluorescent tubes because it's safer
and cheaper to run. Now there are two main types of led strip
digital and analog. First let's look at analog -
it's very simple. It has a common power and then three channels for three
colours red, green and blue. Depending on how much power you send down each of
these three channels depends on the colour you get out. The
downside of analog led strip is the whole strip
needs to be the same colour. So in comes digital. There are many
different types of digital LED strip and Rob from The Hook Up has an excellent
video detailing them all. But in a nutshell each LED has its own
microchip built into it to tell the LED what colour it needs to
be when it receives a data signal. Now I've chosen the WS2812B digital LED
strip. WS2812B being the name of the microchip
within the LEDs because of a few reasons - it's 5 volts
which means it can run on the same power supply that i'm using to run my Wemos D1
Mini; it's cheap; and it also is compatible with the libraries that
we're going to be using later to run it. The led strip has three cables going to
it - a red for 5 volts, a white
for ground, and a green for data. It also has a spare red and white cable for
power injection. Because we're doing such a short run
today we're going to ignore that, but if you're doing a longer run then
you want to inject power every five meters or so
to keep your LEDs constant and so they have enough power to run.
Now that's enough of the boring stuff let's get on with the project.
To do this project you're going to need: W2812B
LED strip; something to cut your led strip to length;
a Wemos D1 Mini (you can use a different esp8266 controller if you wish);
and a micro usb power supply. You're also going to need some jumpers.
Depending on your manufacturer will depend on which jumpers you need,
but I needed male to female. I didn't have any lying around so I've made one
using the connector cable that the company provided with the LED strip.
Now this is an all-in-one cable, so if you're going to make one like this
make sure you get the pins in the right order.
It needs to be 5 volts, ground and then data
in order to connect it to the D1 Mini. If your D1 Mini comes without pins attached
then you're also going to need a soldering iron to attach your header
pins. It's generally cheaper to get them
without pins attached if you're happy to do a bit of soldering.
I got my LED strip from amazon but if you're willing to wait a little longer
you can get it from eBay or AliExpress for much cheaper.
First you're going to need to look at the power consumption of your LED strip
so you can decide the power supply. You can use the table from The Hook Up's
video to tell you how much power your LEDs are going to use.
He says it's going to be 0.18 watts per single LED.
I'm using one meter of LED strip so that's 60 LEDs,
that means I'm going to be drawing 10.8 Watts
and at 5 Volts that's 2.16 Amps. My power supply is rated to 2.5 Amps so
that will be fine. When I first heard about esp8266
microcontrollers I went for the cheapest one I could find
the ESP-01s. I'd highly recommend you don't do this.
These chips run on 3.3 Volts which means you either need to buy or
build an adapter to run them from usb at 5 Volts.
They also don't accept serial via USB because they don't have a USB port,
so you've got to buy a USB serial to TTL converter.
For just a couple of pounds more you can get the Wemos D1 Mini
which has USB power and USB serial built in so you can flash it really
easily. The first thing I need to do is solder
the header pins onto my D1 Mini. As you can see mine came with three
different types of header pins, but for this case i'm just going to use the
male-to-male ones and solder them on. Next we need to connect our LED strip to
the controller - we need to connect the red cable to 5 volts,
the white cable to ground, and the green cable
to a data pin. I'm using pin D4 because it's next to the 5 Volts and ground.
Now we head over to Home Assistant. You're going to need to make sure you
have the ESPHome add-on installed, so if you head over to
the supervisor tab, go to the add-ons page, and then search
for ESPHome it'll appear there. Once you've clicked install you can open
the web UI. I have mine in the sidebar for ease of
access later on. Once we're in the ESPHome add-on you
click on the plus. Here you can enter the name of your
device, make sure you're only using lower cases and don't use any spaces.
Click next and select the board type - we're using the Wemos D1 Mini,
click next again and enter your Wi-Fi details.
Once you've clicked finish you'll need to flash it.
Once up and running you'll be able to re-flash it over the air
or through your Wi-Fi but for the first time we need to plug it in,
so if you plug your D1 Mini into your computer using the USB
now. You're supposed to be able to flash over USB using the add-on
but I've never managed to get it to detect the device
so I use a tool called ESPHome flasher. Now to use this we're going to need to
compile and download the binary. Click on the three dots next to your new
device and click compile. It may take a while but when it's done
you can click download binary. From here you need to open up the new
app ESPHome flasher and select the serial port that your
device is connected to. It should automatically select it but if
you have multiple devices plugged in you'll need to choose the correct one
here. You now need to click browse and select
the new .bin file from your downloads, and click flash. It may take a while to
flash it but once it's done it will give you the
Wi-Fi information and say setup finished. Now I have all the devices on my network
on a static IP address so I'm going to set that up now in the
router and then restart the router and my D1 Mini.
Now we go back to the ESPHome add-on and refresh the page -
we should see our device listed as online. Now we need to go to the ESPHome
website and you can see here that there are so
many different devices you can integrate with your micro controllers.
We want lights so we're going to scroll down to light and click
FastLED. Once here we can scroll down and see that WS2812B
is compatible with FastLED. So we're going to copy the yaml from above,
and we need to go back into our Home Assistant add-on, click on edit
next to our new device and we can be editing the yaml for our device.
We paste it at the bottom and we need to edit a few things here.
First we want to edit the chip, we're using the WS2812B
chip. Now we change the pin I'm using pin D4.
Next is the number of LEDs I've got 60 LEDs in my one meter strip.
Now we change the RGB order in this case we want it to be GRB.
You may find that this is wrong for your particular LED strip,
so this is where you'd change it if you turned on blue and it came out red for
example. Lastly we can call it a name - this is
what will come up when we use Home Assistant later.
We save it, validate it, and once we're sure the yaml is correct, we upload it.
Again this may take a while as we're integrating some new libraries and
packages. Once we see the purple Wi-Fi information
we can close the window and move on to integrating into Home
Assistant. We go to the configurations page and click
integrations. Once here your device should appear at the top.
But if not, don't worry, you click on the plus and search for ESPHome.
We now insert the host name - this is what you called your device in the first case,
so for my case it's cave_led you then add .local so cave
_led.local
The port should be correct so
we click next and select an area we want this device
to be in, click finish and your device should appear in the integrations.
If you click through on your integrations you'll be able to turn it
on and off and change the colour of it. You might be
thinking hold on... I can only control the entire strip... and
you'd be right so now what we're going to look at is adding effects to our LEDs.
If we go back to the ESPHome website we can see that effects is an option we
could add. Here we can click on light effect and
scroll and see some various examples that we can use.
I'm going to copy and paste a few of these examples into my cave_led.yaml file
back in my add-on. I'm just going to use some of the demo effects that they have
listed, but you can create your own or just edit
the numbers in some of those. Once we're happy, we save, validate, and
upload our configuration file. Once done we can see some of our new
effects in action. If we go back to the integrations page we can see them listed
and we can select them. Because i've decided to mount the LED
strip in a visible location, i've decided to use some aluminium
channel. I'd highly recommend this as it gives a much nicer finish when the LEDs
are off and it diffuses the light when they're
on. It's very easy to install - you just attach the fixings it comes
with to the surface you're trying to mount to.
I'm using one at each end, and one in the middle. You stick the led strip down the
center of the channel, pop in the diffuser and then attach the
channel into the mountings. After a little bit of cable management
you can turn it on and enjoy your handywork.
I said i'd show you how I use this in an automation so here we go.
Let's dive into node-red. I like to keep my automations as tidy as possible
so we're going to go over to the lighting tab. First we're going to copy
and paste this description node so we can label what this automation
does. Then I'm adding an event state node using the entity of my phone's battery
sensor - you can find your entity names in the developers tab.
Next we're going to choose an output node. So now we set it up -
we're triggering a light, we want it to turn on,
and we want to set the entity to the entity of the light that we've just
created. Now if we go into the data we can edit
the json to select the effect that we want to use.
I'm going to be triggering a rainbow effect in this case. I'm going to test
this integration by adding an inject node
to the call service. We connect it up and we can deploy.
Now we can inject and it should trigger the rainbow effect that we're looking to
see. I'm going to add a condition for this
automation. It's going to be a get state node
for my cave switch. Basically it means the trigger only happens
if I'm at my desk i.e the cave switch is on.
Once we're happy we link it all up deploy and we can sit back and relax
while we wait for our automation to happen. If you like what you saw today
make sure you click subscribe so you can find out more about my tech and how you
can build yourself the ultimate smart home.