ESP8266 Led Strip MQTT Control Lights WS2812




Introduction: ESP8266 Led Strip MQTT Control Lights WS2812

I always wanted under bed led lights so that I can control the mood or even on the family room underneath the tv to get very subtle lighting. I could write rules in OpenHAB and it takes care of the rest. This is a rather simple setup to get everything accomplished over MQTT thanks to the power of Homie Framework with only a few lines of code.

Things to consider before getting started. Depending on the size of your LED Strip of WS2812s, you will need to adjust.

Each LED light consumes about 60 mA, so if you are powering 60, the minimum Amperage would be as follows. As you add more lights, the power requirements also increase.

60 LEDs × 60 mA ÷ 1,000 = 3.6 Amps minimum

Parts List:

Step 1: Wiring

The wiring schematic is fairly simple.

Note: Please make sure you have the polarity right on the power supply or you can damage the LEDs and/or ESP8266.

From Power Supply

  • VCC Line to Wemos D1 5V Pin and to Positive/Red Wire on LED Strip
  • GND Line to Wemos D1 GND Pin and to Ground/White Wire on LED Strip
  • Add 1000uf Capacitor on Ground/5V line close to LED Strip

From Wemos D1

  • Connect D1 Pin to Data/Green Wire on LED Strip.

Thats it. :)

Step 2: Programming

Dependencies for Arduino are Homie 2.0 which you can get from their Github and the Adafruit Neopixel Library

Sketch for Arduino

#include <Homie.h>
#include <Adafruit_NeoPixel.h>

#define FW_NAME "led-control" #define FW_VERSION "1.0.0"

#define PIN D1 #define LED_COUNT 60

Adafruit_NeoPixel strip = Adafruit_NeoPixel(LED_COUNT, PIN, NEO_GRB + NEO_KHZ800); int delayval = 500; int showType = 0; int SoffitR; int SoffitG; int SoffitB; int numPixels = LED_COUNT;

HomieNode ledNode("led", "led");

bool lightOnHandler(HomieRange range, String value) { if (value == "off") { colorWipe(strip.Color(0, 0, 0), 50); // Black/off Homie.setNodeProperty(ledNode, "color").send("0,0,0,0"); } else if (value == "red") { colorWipe(strip.Color(255, 0, 0), 50); // Red Homie.setNodeProperty(ledNode, "color").send("0,255,0,0"); } else if (value == "green") { colorWipe(strip.Color(0, 255, 0), 50); // Green Homie.setNodeProperty(ledNode, "color").send("0,0,255,0"); } else if (value == "blue") { colorWipe(strip.Color(0, 0, 255), 50); // Blue Homie.setNodeProperty(ledNode, "color").send("0,0,255,0"); } else { //value.trim(); Serial.print (value); //Serial.flush(); // split string at every "," and store in proper variable // convert final result to integer SoffitR = value.substring(0,value.indexOf(',')).toInt(); SoffitG = value.substring(value.indexOf(',')+1,value.lastIndexOf(',')).toInt(); SoffitB = value.substring(value.lastIndexOf(',')+1).toInt(); colorWipe(strip.Color(SoffitR, SoffitG, SoffitB), 50); Homie.setNodeProperty(ledNode, "color").send(value); } return true; } int i;

void colorWipe(uint32_t c, uint8_t wait) { for (uint16_t i=0; i

void setup() { Serial.begin(115200); Serial.println(FW_NAME FW_VERSION); strip.begin();

Homie_setFirmware(FW_NAME, FW_VERSION); ledNode.advertise("color").settable(lightOnHandler);



void loop() { Homie.loop(); }

JSON Config File

"name": "LED for TV Stand", "device_id": "family-room-tv-led", "wifi": { "ssid": "MYSSDID", "password": "MYWIFIPASSWORD" }, "mqtt": { "host": "MY MQTT SERVER", "port": 1883, "base_topic": "devices/", "auth": true, "username": "sensor", "password": "sensor1" }, "ota": { "enabled": true } }



Color TVLedLight "Bed Color" <colorlight> (All)
String TVLedLightColor (All) {mqtt=">[OpenHab:devices/family-room-tv-led/led/color/set:command:*:default]"}


Text label="Family Room" icon="sofa" {
Frame label="Switches"

Switch item=wifiplug_living_room

Colorpicker item=TVLedLight




import org.openhab.core.library.types.*

rule "Set RGB value TVLedLight"

Item TVLedLight changed


val hsbValue = TVLedLight.state as HSBType

val brightness = hsbValue.brightness.intValue

val redValue = (((( * 255) / 100) * brightness) / 100).toString

val greenValue = (((( * 255) / 100) * brightness) / 100).toString

val blueValue = (((( *255) / 100) * brightness) / 100).toString

val color = redValue + "," + greenValue + "," + blueValue

sendCommand( TVLedLightColor, color )


Give it a test run.

Thanks for reading.

* I maybe compensated for some links.

Be the First to Share


    • For the Home Contest

      For the Home Contest
    • Make It Bridge

      Make It Bridge
    • Big and Small Contest

      Big and Small Contest



    3 years ago

    Are there any experiences about the speed of processing the command from MQTT Broker? Is it possible to do something like animations with the setup?


    Question 4 years ago on Step 2

    Maybe there are some new versions of libs and so on...

    I tried to make this tutorial and end up in a error of the compiler

    'class HomieInternals::HomieClass' has no member names 'setNodeProperty'

    Does someone has a idea?

    Dorian G
    Dorian G

    Answer 4 years ago

    Found a similar issue on Github:

    Replace the line containing 'setNodeProperty' using the following pattern:
    Homie.setNodeProperty(ledNode, "color").send("0,0,0,0");

    Sanjay JudeD
    Sanjay JudeD

    5 years ago

    how to go ahead with this project. I have a NodeMCU and compiling the code in Aurdino. I get this error -

    #include <ArduinoJson.h> not found.

    Where does the JSON file go


    Reply 5 years ago

    The error means that you need to install the ArduinoJson library. Check out:


    5 years ago

    Also where does the JSON config file go. Sorry for being so dumb.


    5 years ago

    Hi am new to this hobby. Am working on something similar. Based on instructions from other videos I had bought a nodeMCU ESP8266 controller. Can I use this instead of Wemos D1. Also can you please do a step by step video for complete noobies like me. Thank you


    6 years ago

    Hi nice instruction to get my tiny led strip running with MQTT commands!

    I found a small bug in your Arduino IDE script:

    int i;

    void colorWipe(uint32_t c, uint8_t wait) {
    for (uint16_t i=0; i

    Needs to be:

    int i;

    void colorWipe(uint32_t c, uint8_t wait) {
    for(uint16_t i=0; i<strip.numPixels(); i++) { //<strip.numPixels
    strip.setPixelColor(i, c);;