Ambilight with WiFi on ESP8266


I built an Ambilight clone that listens for MQTT messages over WiFi when it’s not receiving serial data. This allows it to be controlled by Home Assistant and vicariously the Google Assistant. The code lives at

Board Swap

My first Ambilight clone served me quite well. I started with a system like the one described here. It worked like this: Kodi > boblight > Arduino > WS2812 LED strips.

But it was time to upgrade. The biggest change was to swap out the Arduino for a NodeMCU. These boards are built on top of the ESP8266 which provide WiFi. Unlike the barebones ESP8266, the NodeMCU boards include a USB connection. The NodeMCU boards come with a firmware that will run Lua scripts or something. I opted to discard the whole Node/Lua firmware thing and replaced it with the standard Arduino environment.

Where is pin D1?

To setup your environment for this, grab your Arduino software from Next choose File > Preferences. In the Additional Boards Manager URLs enter:

I also had to swap out the standard NeoPixel library for NeoPixelBus. The former gave me problems when trying to use it at the same time as the serial port–although that could have been a mistake on my part.

With a few other minor changes I was back in business. The new micro controller was reading data from the serial port and displaying it on the LEDs.

Arduino, meet WiFi and MQTT

Adding WiFi support to the ESP8266 in the Arduino IDE is pretty standard business. However, where most others use HTTP for remote control, I chose to use MQTT. The MQTT protocol is a lightweight pub-sub protocol that works great with low power devices. You do need to setup an MQTT broker (aka server), but that’s pretty easy with docker.

docker run -ti -p 1883:1883 -p 9001:9001 toke/mosquitto

I’ve been using the image above for some time with absolutely no issues, but it seems eclipse has recently put an official image together.

One of the benefits of MQTT is that all devices connect to the broker, so there is no need to track the IP addresses of all of your things. Everyone meets at the broker to exchange messages.

Another benefit is that the device can send you a message at any time. This was a big help when debugging since the serial port was in use.

You should have used Hyperion!!!

Actually, I did make the switch from boblight to Hyperion. Like boblight, Hyperion runs on your Kodi box and performs the same task as boblight, but also exposes a JSON API to the network. They even provide free Android and iOS apps to control the lights. If you’re reading this post, you should definitely check out Hyperion. Also, did I mention they have black border detection?

<rant>How does boblight not have black border detection yet?!!</rant>

All that said, I quickly grew tired of turning on my Kodi box, in order to turn on the lights.


With the NodeMCU powered by the USB port on my Kodi box, I looked for a BIOS setting to keep the power to USB ports on, even when the computer was off. Alas, I could not find it. Plan B should have been to use a powered USB hub, but in lieu of that I built a one 1 port, powered USB adapter.

Always powered USB cable

The ground and data pins from the USB cable are passed through, but voltage comes from that secondary orange/white cable so that even when the USB port loses power, the NodeMCU stays on.

Control Interface

I use Home Assistant for the moment. It runs great on docker.

docker run -d --name="home-assistant" -v /path/to/your/config:/config -v /etc/localtime:/etc/localtime:ro --net=host homeassistant/home-assistant

Home Assistant has built-in support for MQTT lights with a configuration entry like this.

- platform: mqtt
 name: Ambilight
 command_topic: 'ambilight/switch'
 rgb_command_topic: 'ambilight/rgb'
 rgb_value_template: "{{ value_json }}"

Assuming you have the Google Assistant Home Assistant component already setup, you can now control your Ambilight with your voice.

Demo Time


Ambilight Mode



The Code

You can find the code for the NodeMCU at

6 thoughts on “Ambilight with WiFi on ESP8266

  1. Alexander

    Hi man. Great work! Can you tell about kodi settings.
    You write sketch to NodeMCU and connect it to your WIFI AP. Then you started Hyperion Kodi Plugin amd next? What did you do for launch it?

  2. what pins should the lights connect to on the nodeMCU, if the code is standard? Ground and pins no???

    • Heath

      Great question! The data pin going to the LEDs is connected to GPIO2 aka D4 on the nodeMCU board.

  3. hi my friend what pins are connected to the nodeMCU from the lights is it ground and GPIO1?

    • Heath

      Great question! The data pin going to the LEDs is connected to GPIO2 aka D4 on the nodeMCU board.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>