Introduction: DIY Smart Home PC Ambilight

I've seen a bunch of projects online of people either building their own "Ambilight" for their PC's or buying them off the shelf. I recently started playing with addressable LED strips like the WS2812(b) and decided to build my own PC Ambilight.

I make use of Apple HomeKit throughout my apartment to control various appliances such as switches, outlets, and lights, so a requirement for this project was to make the Ambilight HomeKit compatible.

Supplies

Hardware:

Software:

* Note: If you have a very big screen and require a long piece of LED strip, consider getting a 5V 6A power supply instead.

* Note: For this project, you require a working Homebridge server if you wish to also control your Ambilight using Apple HomeKit.

* Note: For this project, I opted for the Wemos D1 mini WiFi board. You can however use alternatives such as the ESP-01 or NodeMCU

Step 1: Prepare Wemos D1 Mini (hardware)

The Wemos D1 mini is ideal as it can be powered using 5V DC, the same voltage that will power the WS2812b LED strip. You can easily swap out the Wemos D1 mini with a NodeMCU as this micro-controller also accepts 5V input voltage. Another (cheaper) alternative is the popular ESP-01 module. The only downside is that the ESP-01 module requires additional hardware as this module only supports 3.3V I/O voltages.

In this step, we will be preparing our micro-controller hardware.

To start, the Wemos D1 mini does not come with any pins soldered to it. I decided to solder some female header pins to 4 pins of the Wemos D1 mini (5V, Ground, D4, and D3). By soldering some female headers to the micro-controller you can easily interchange it later, or reuse it in other projects.

The Wemos D1 mini is now ready to be flashed with software to connect it to your WiFi network. We will do this in the next step.

Step 2: Prepare Wemos D1 Mini (software)

In this step, we will be flashing (programming) our Wemos D1 mini with open source light control software known as WLED. Programming ESP8266 based devices like the Wemos D1 mini is very simple. I created an Instructable on this topic that can be found at this link. I will however briefly go through the process below, but for all the details, please refer to my other instructable.

Since we are working with a Wemos D1 mini, we can connect our board to our computer via a micro-USB cable.

  1. Connect your Wemos D1 mini to your computer through a micro-USB cable.
  2. Open your preferred flashing tool, I use Tasmotizer.
    • Make sure that your port is correct. Also, since we are using a Wemos device in this project, make sure that the "self-resetting device" option is on.
  3. Download the latest binary of WLED (I use the WLED_x.xx.x_1M.bin file) - Link to WLED releases
  4. Select the WLED firmware file just downloaded in your flash tool.
  5. Now you can proceed to flash the firmware. In Tasmotizer, click "Tasmotize!". If you are using another flashing tool, proceed to flash the firmware to the Wemos device.
  6. Wait for the WLED firmware to be flashed to your device, this can take some time.
  7. Once you received a message that the firmware is successfully flashed, you can restart your device.

In the next step, we will be configuring our Wemos D1 mini to connect to your WiFi network.

Step 3: Configure Wemos D1 Mini (WiFi)

The WLED firmware was flashed to your Wemos D1 mini in the previous step. Once you restarted (power cycled) the device we can continue in this step to connect the device to your WiFi network.

Using a mobile device or computer with WiFi capability, search for WiFi networks around you (close to your Wemos device).

  1. Connect to the WLED-AP WiFi network with the password "wled1234"
  2. You should be redirected to the WLED web-interface in a few seconds, otherwise navigate to 4.3.2.1 in a browser.
  3. Click on "WIFI SETTINGS"
  4. Write down the mDNS address and enter your WiFi credentials under the "Network name" and "Network password" inputs.
  5. Save the settings and wait for your device to reboot.
  6. Connect back to your main WiFi network
  7. You should now be able to navigate to the "mDNS" address you wrote down in (4) and be presented with the WLED server interface running on your Wemos device.

Your Wemos D1 mini is now ready to be configured to control addressable LEDs. We will do this in the next step.

Note: ESP8266 devices only support 2.4GHz WiFi networks.

Again, for more information on flashing ESP8266 device, have a look at my ESP8266 WLED Instructable

Step 4: Testing Wemos D1 Mini (WLED)

Your Wemos device is now running the WLED firmware and is connected to your WiFi network. We will now test if everything is working as expected.

  1. Make sure your Wemos D1 mini is connected to your DC power supply
  2. Navigate to the address of your Wemos D1 mini running WLED. This is the "mDNS" address you wrote down in (4) of the previous step.
  3. Have a few WS2812b LEDs close by (I had some of these 8x8 LED matrices at hand).
  4. Navigate to the "Config" pane of the WLED interface.
  5. Click on "LED Preferences"
  6. Enter the number of LEDs you plan to test within my case (8x8=64).
  7. Click "Save"
  8. Power down the device.
  9. Setup test hardware as shown in the attached circuit diagram.
    • Note that WLED will communicate with the LED strip using pin D4.
    • Note the current limiting resistor of 270Ohm between D4 and the LED strip.
    • Note that the Wemos D1 mini and the LED strip is powered using the same 5V power supply.
  10. To make testing easier download the WLED mobile application (optional)
  11. When you built the test circuit, power it on and wait a few seconds. Your test WS2812b LEDs should turn on.
  12. Navigate to the WLED mobile application and open it (optional)
    • Click on "Discover lights..." and wait a few seconds
    • Click the Checkmark in the top right of the screen
    • Your light should appear as WLED in a list.
    • Click on it.
  13. If you cannot use the mobile application, simply go to the "mDNS" address you wrote down for your Wemos device in an earlier step.
  14. At this stage, you can verify that your WS2812B LEDs are working and you can play with the colours and effects that WLED offer.

Now that we verified our WLED is running and our Wemos device can control WS2812 LED devices, we can continue to create an enclosure for our micro-controller.

Pro tip: The WLED mobile application is a very convenient way to discover WLED enabled devices on your network, providing you an easy way to discover their IP addresses.

Step 5: Create Enclosure

It is always good to create enclosures for your electronic projects, as you don't want cables running everywhere as it can create hazards or look untidy.

For this reason, I created an enclosure for the Wemos D1 mini using Fusion 360. The enclosure can be downloaded from Thingiverse to be 3d-printed.

Navigate to this Thingiverse link for the files, or find the files attached below. Print them using at least a 0.2mm resolution and a well-calibrated printer. It is designed as a simple friction-pressure fit.

In the next step, we will assemble the enclosure and wiring for our final circuit.

Step 6: Assembling Enclosure

The next step is to assemble our enclosure and final circuit.

  1. Create the final circuit diagram
  2. Solder wires to the connectors as shown in the diagram
  3. Use heat-shrink tubing to keep everything net inside the enclosure
  4. Only 2 out of the 3 pins will be used on the 2.1mm x 5.5mm DC connector. Use a volt-meter to test.
  5. Only 3 out of 4 pins of the 4-pin connector will be used, use your digression. Remember the order you chose (+5v, ground, and data) this will be very imported when you eventually connect your LED strip.
  6. Connect a male 2.1mm x 5.5mm connector on the end of your 5V power supply.

At this stage, it is a good idea to test your circuit again as before, and verify that everything works as expected.

In the next step, we will create the strip for placing behind our screen.

Step 7: Ambilight LED Strip Construction

At this stage of the project, we need to create the LED strip to place behind your screen.

  1. Take your WS2812b strip and hold it against the back edges of your monitor. The goal here is to determine the number of LEDs for each of the 4 sides of your monitor.
  2. For my monitor I require a layout like follows:
    • Bottom-left: 18 LEDs
    • Left: 18 LEDs
    • Top: 39 LEDs
    • Right: 18 LEDs
    • Bottom-right 18 LEDs
  3. Things to take note of:
    • You don't have to implement a gap where your monitor has a stand.
    • Note the starting position of your LED strip
    • Note the direction data travels in your LED strip. This will be indicated with arrows.
    • Sketch the number of LEDs required on each side.
    • Please note that the cutting of your strip is optional. You can also bend it if you want to. Cutting however gives a better result.
  4. When you know the number of LEDs required per side for your monitor, cut them to length.
  5. Get some coloured wires and cut them into 4 cm lengths (to be used to solder the strips together again.
  6. Solder your connector to the starting position of the strip.
  7. Now with your strip completed, we need to test it before mounting to the monitor we will do this in the next step.

Step 8: Testing LED Completed Strip and Mount to Monitor

You now have a LED strip ready to be used as an Ambilight behind a computer monitor. This step will involve testing that everything thus far works as expected.

  1. Connect your LED strip to your enclosure - make sure the order of the connection matches on both LED strip and enclosure:
    • +5V - +5V
    • Data - Data
    • Gnd - Gnd
  2. Navigate to the WLED mobile application or web-interface
  3. Click on your new WLED device
  4. Click on "Config"
  5. Click in "LED Preferences"
  6. Update the "LED count" value to match the total number of LEDs on your new strip.
    • In my case (18+18+39+18+18 = 111)
  7. Click "Save"
  8. Your LED strip should now work.
  9. Mount the LED strip to the back of your monitor - I used sticky tape on the edges and the start and end of the strip.
  10. Connect the Enclosure to power and your lights should turn on.

In the next step, we will test the completed strip using the WLED interface.

Step 9: WLED Testrun

The Hardware part of this project is now completed. All that remains is some software configurations and testing.

  1. Navigate to your WLED mobile application or web-interface
  2. Play with the colours or effects.

In the next step, we will configure Hyperion.ng - this can be used to sync your Ambilight with the contents of your screen.

Step 10: Configure Hyperion.ng

You can read up on Hyperion.ng on their forum or Project page.

The idea is, you install Hyperion.ng on your computer, it uses screen-recording to analyze what is being displayed on your screen, processes it, and converts it to a stream that can integrate with WLED to create near real-time ambient lighting.

  1. Navigate to Hyperion releases and download the latest version.
  2. Install it
  3. Open Hyperion (it will start-up in the background and go to the system tray)
  4. Double click on Hyperion in the system tray
  5. Hyperion will open in your browser and may ask you to enter a new username/password - do this.
  6. In the Hyperion web-interface, navigate to "LED Hardware"
    • Select "wled" in the "Controller type" drop-down menu.
    • Enter your WLED controller IP address - an easy way to find this is to use the WLED mobile application as mentioned before.
    • Click on "Save settings"
  7. Next, navigate to the LED layout tab
  8. Enter your number of LEDs
    • Note I used the same number of LEDs for my bottom row and selected a gap length of 3. (calculated as 39-18-18=3).
    • I set my gap position at LED 75 (18+39+18=75)
    • I set my input position to 75 as well.
  9. Click on "Save Layout"
  10. Navigate to "Dashboard" and make sure your LED hardware is running under the "Smart Access" section
  11. Now you should have an Ambilight that mirrors your screen to your wall.

In the next step, we will connect the Ambilight to Apple HomeKit.

Note: this project assumes you are using a Windows machine

Step 11: Apple HomeKit Setup Using Homebridge

My final requirement for the Ambilight was to be able to control it using Apple HomeKit. I expose a variety of 3rd party devices to HomeKit using the Homebridge project.

Note: This project assumes you already have a running instance of Homebridge on your network.

Quoting from the Homebridge site - "Homebridge allows you to integrate with smart home devices that do not natively support HomeKit. There are over 2,000 Homebridge plugins supporting thousands of different smart accessories."

If you also plan to integrate the Ambilight with Apple HomeKit and do not have Homebridge, follow their great instructions on getting the server running on your local network. I recommend the Raspberry pi 3 or newer.

Adding the Ambilight to HomeKit turned out to be very simple. There are two methods - you can set up MQTT on your WLED Ambilight, and control the light via the "Homebridge Mqttthing" plugin in Homebridge, or you can simply install the "Homebridge Wled Simple" plugin in Homebridge. I'm going to save you time now and recommend the "Homebridge Wled Simple" plugin for Homebridge.

  1. Navigate to your Homebridge server on your network by entering the IP address of your Homebridge server.
  2. Navigate to the "Plugins" tab
  3. Search and install the following plugin "Homebridge Wled Simple"
  4. Get the IP address of your Ambilight on your network - the easiest way to do this is using the WLED mobile application.
  5. In the web-interface of Homebridge in the plugins section, click on "Settings" of the "Homebridge Wled Simple" plugin
  6. Edit the default accessory or click on "ADD ACCESSORY" at the bottom of the screen.
  7. Add the code snippet presented below as JSON - update with a name and your IP address.
  8. Click "Save"
  9. Restart your Homebridge instance
  10. Your Ambilight will appear in your HomeKit on all your Apple devices.
{
	"accessory": "WLEDSimple", 
	"name": "Name to display here",
	"apiroute": "http://your ip address here"
}

NOTE: a tip is to create a static IP address for all your WLED devices on your network. By doing this you will always know the address of each light, and ensure that Homebridge can always contact your device. If you do not assign static IP addresses to WLED devices and plan to use them using the "Homebridge Wled Simple" plugin, their IP addresses might change on device restarts and you will have to reconfigure the plugin.

Step 12: Assign Static IP Address to Your Ambilight

You can use two methods for setting a static IP address for your WLED Ambilight.

The first method involves the WLED web-interface or application.

  1. Go to the web-interface of your WLED device (or use the application).
  2. Go to "Config"
  3. Go to "WiFi Setup" and scroll down to the "Static IP (leave at 0.0.0.0 for DHCP):" section
  4. Enter the IP address you'd like to assign to the device - make sure the IP address won't clash with something else on your network.
  5. Enter the static gateway info of your router - this will be something like "192.168.1.1" or "10.0.0.2"

The second method is to navigate to your router interface, determine the MAC address of your WLED device using its current IP address, and then setting a Static IP address for your device in your router.

Step 13: Home Automation (HomeKit)

Since a requirement for this project was met for controlling the Ambilight using Apple HomeKit, we can now create some automatons for our Ambilight. I suggest the following scenario.

  1. Automatically turn on the Ambilight with the colour blue at 18h00 every day.
  2. Automatically change the Ambilight to a warm-white at 20h00 every day.
  3. Automatically turn on the Ambilight to a Red if motion detected in the room between 00h00 and 06h00 every day - and turn it off after 5 minutes.

Let us get started

Creating a schedule based automation in HomeKit is simple:

  1. Open the Apple Home application
  2. Navigate to the automation tab
  3. Click the "+" to create a new automation
  4. Select the "A Time of Day Occurs" menu option
  5. Make sure the "Time of Day" option is selected and enter the time you'd like the automation to run. I will enter 18:00. You can also select repeat days or restrictions on people that needs to be at the home or not for the automation to run. When you are happy with your inputs click on "Next".
  6. Scroll down and identify your ambilight. Mine is called "PC Ambilight" in my "Study" room. Select it and click "Next" in top right corner of the home app.
  7. Long press the Ambilight to be able to set its colour and brightness for the automation.
  8. When you are happy, press the "Test This Automation" option to test it.
  9. When you are happy with the result, press "Done" in the top right corner and the automation will appear in your list of automations.

To create the "Warm-white" automation is exactly the same, with the exception of setting the colour of the automation. In step (7) above, you click on the "edit" button when selecting the colour of your Ambilight in the Home app. Then you select the "Temperature" tab to select between a range of white light colour temperatures.

In order to create a motion based automation in the Apple home app you require a motion sensor connected to the apple home app. I use RF-based motion sensors exposed to HomeKit through Homebridge and Ewlink. The following steps are required to build the motion based automation:

  1. Open the Apple Home application
  2. Navigate to the automation tab
  3. Click the "+" to create a new automation
  4. Select the "A Sensor Detects Something" menu item
  5. Scroll and find the sensor of interest. In my case the "Study" motion sensor. Select your sensor and click "Next" in the top right corner.
  6. Select the "Detects Motion" option and enter your time constraints. I will select the Time --> Specific times option and enter a start time of 00:00 and an end time of 06:00.
  7. Click on "Next" in the top right corner.
  8. Scroll down and find your Ambilight. Select it and click on "Next"
  9. Long press your Ambilight and select the colour. I will choose red.
  10. Now select the "Turn off" option and select your time. This will cause the Ambilight to turn on using the colour you specified, and then turn off after your specified time duration. For this demo, I will use 1 minute.
  11. You can now select "Test this automation" to test the behavior. If you are satisfied, select "Done" in the top right corner and your automation will appear in your list of automations.

In the next step we will be implementing some custom animations using the Apple Shortcuts app.

Note: This project assumes you already have a running instance of Homebridge on your network.

Step 14: Home Automation (Apple Shortcuts or WLED API)

test

Since the Ambilight is powered using WLED, we can control it using the HTTP request API. This is very useful since Apple HomeKit does not (not that I know of) support the range of animations that WLED has to offer. The WLED API enables you to control almost all aspects you can do in the web-interface of WLED.

For android users, you also get applications that enable you to fire HTTP calls using buttons or widgets. For this project, however, I will be focusing on Apple devices using the Shortcuts app.

The official WLED documentation for the request API states that we need to call the following URL to control our WLED device:

[ipadress]/win

I used the WLED mobile application and determined that my WLED device IP address is 192.168.1.25, thus I can control my Ambilight using the following scheme:

http://192.168.1.25/win

Another scheme is to use the mDNS address of your WLED device. I like to go this route as IP addresses (if not set up as static) can change. The term "led" should be changed with your device's mDNS id.

http://led.local/win

The documentation states that we can control effects using the following parameters in the URL string:

  • "&A=" Specify the master brightness. Values accepted: 0 to 255
  • "&FX=" Specify an effect index. Values accepted: 0 to 101
  • "&SX=" Specify an effect speed. Values accepted: 0 to 255
  • "&IX=" Specify an effect Intensity. Values accepted: 0 to 255

Various other parameters are discussed in the documentation, but these are of interest to this project.

The documentation provides us with a nice list of available effects at the following link. I am interested to create a Shortcut to display the "Palette" effect. Referencing the documentation this has an Id of 65. I want the effect to have the following properties:

  • 50% effect speed
  • 100% Effect intensity
  • 100% Effect brightness

To achieve this I need a URL string that looks like this:

http://192.168.1.25/win&A=255&FX=65&SX=128&IX=255

Now creating an Apple Shortcut to achieve this:

  1. Open the Shortcuts application.
  2. Select the "My Shortcuts" tab.
  3. Select a folder for creating the shortcut. I created a "WLED" folder.
  4. Click the "+" in the top right-hand corner.
  5. At the bottom of the screen search for "Get Contents of URL"
  6. Click on the "Get Contents of URL" action
  7. Click on "Show More" and make sure that the "GET" method is selected.
  8. Enter your URL in the "URL" section and click "Next" in the top right corner.
  9. Give your Shortcut a name and icon.
  10. Click "Done"
  11. You can now activate your Effect using some of the following methods:
    • Clicking on it in the shortcuts app.
    • Adding it as a widget on your home screen
    • Asking Siri to run your shortcut.
  12. You can now create shortcuts for numerous WLED effects or even create automations inside the Shortcuts app that can trigger WLED effects based on device states like:
    • Getting a message or email from someone can flash your LEDs
    • When your device battery level goes below 50% turn the LEDs red.
    • When you plug your device into a charger, turn the LEDs green - I will create an automation like this just as a demo.

The Apple shortcuts app is a very powerful tool to automate your home.

Note: your apple device needs to be on the same WiFi network for this to work. Unlike HomeKit, this shortcut implementation cannot work from outside your home network. Furthermore, for this demo, I used the IP address for the WLED device directly. In practice, you should either set up a static IP address for your WLED device or use the mDNS address that does not change.

Shortcuts may also ask you the first time to permit it to send data to websites - just accept the message.

Step 15: Conclusion

Overall this project turned out to be great meeting all my requirements:

  • Ambilight
  • Control with HomeKit
  • Automations in HomeKit and Shortcuts

Shout out to all the great projects out there that made this possible:

Automation Contest

Participated in the
Automation Contest