The Lights Project

Tablet as control centre for Yeelights

by Dalibor Lanik


After deciding to use Yeelights, I needed a central option to control the lights. Even though you can control Yeelights with your phone over WiFi or 4G internet, it is not very convenient to have to take your mobile phone every time you wish to turn the lights on or off. Luckily, all my lights are in the same space - living room with diner and kitchen. So I thought having one or two tablets somewhere would be enough for control. Of course, the best position for these "control centers" would be directly on the wall somewhere, but bringing the power to these tablets is not easy. Fixing them onto concrete walls is no joke either. I suppose Americans have this easier since all their houses are made of wood, so it is easier to drill etc.


One thing that was needed 100% was a hole for the power supply cable. There are various ways to hang the tablet on the wall, depending on the materials used. I had misfortune that in my flat you just can't glue the tablets onto the walls, other choice would be to glue them onto the kitchen elements (because they're smooth) but those locations were not convenient for day to day use. So I found this location which is in the center of the living room/diner and decided to put it there. I used 3 screws to fix the tablet onto the wall, and had to drill another pretty big hole in order to bring the power USB cable to the tablet. I decided to use my old Nexus 7 tablet for this. I removed the cover and found good place for holes (so metal screws don't touch any electronics) and drilled the holes at correct places, screwed the tablet back onto the wall. So far so good.

I put one screw at the location where the back camera was supposed to be - Nexus 7 didn't have the back camera, only front, but there was space reserved for it, so this was the ideal location for the screw head not to mess with the electronics.

Now, you also need USB power cable. It's best to use the flat USB cable, since you'll want the hole hidden behind the tablet. Surprisingly, these are not so easy to find, especially with small connectors or in color that you need (I used white). I ended using the Xiaomi short flat USB cable that I got with Yeelight night light, and USB extender cable.

Luckily, this was the only cable needed, because the tablet would communicate with bulbs via WiFi.

After I fixed the back and tightened the screws, all I needed to do was click the rest of the tablet into place and connect the USB cable. As you can see from the photos taken at the time of installation, at first I used regular black USB cable, which only later I replaced with the thinner, flat white cable. I even tried using the USB cable with the LED light, which looked pretty cool, thinking that if I can't completely hide the damn thing, I might as well make it look as if it's there intentionally, as a part of the design, but the wife didn't like that.



But let's get down to the software side of things. There are several suites that are able to inter-operate with Yeelights. One such is Yeti, a really nice freeware, the other paid one is, for example, ImperiHome. But these apps, at least IMHO, don't have such nice user interfaces, and are limited to the home automation stuff. What if I want to play music from Google Music, or listen to the radio? I really like Microsoft's tiles interface, and find it really adequate for these wall panels, so that is what I decided to use. After testing several Windows style launchers, I found out that the best and most customizable app for this purpose is SquareHome 2.


First of all, it covers the whole area of the desktop, not like standard Android launchers that have icons; each tile is big enough to be a button that is easy to press, and you can easily make even bigger tiles, by making it double or 4x the size. And you can also use widgets.

The basic setup is pretty simple. All you need is a Yeelight app, which you can get from the Google Play, or if it is not compatible with your tablet (wasn't with mine), just extract it from your phone and copy onto your tablet as an "apk" file.

Then you design the layout, however simple or complicated you want, and assign each tile a command from the Yeelight app. These would mostly be on/off commands for various bulbs, but you can also have commands to set the color bulb to a certain color or set a set of bulbs to a certain color or brightness, etc, so called "scenes".

I decided to have on/off switch for the mono bulbs, plus the brightness button (opens brightness slider), and 6 additional buttons for each color bulb/strip that would directly set the bulb/LED strip to the desired color or color flow.

Square Home 2 has the option to use image as a tile background, so it is pretty easy to make several jpegs with the light names, i.e. "kitchen", "living room" etc. You can also choose to animate these, so it is not that static. I set the animation on brightness buttons, so it changes between my custom image and default Yeelight icon. I also included the Yeelight widget, not because it added some usage value but to make the whole screen less monotonous.


I made 3 home screens, one for the lights control, and the other two for various multimedia stuff. At first, it was the Kodi remote control screen; it seemed like a good idea to allow remote control and display the "now playing" screen from my Kodi media center. For this I used the Yatze widget, remote control app for Kodi. On the widgets, you have all possible controls, and when you play something, it shows the cover art/poster.

Using my YeeMee addon for Kodi, which not only controls the Yeelights but can also be used as a cheap Ambi light when you watch movies, I made it so that when I play a film or music on my Kodi media center, the tablet automatically switches from the light control screen to the Kodi control screen, using another Tasker plugin called Tasker Network Event Server (TNES). This plugin receives the command sent from my Kodi media center, when it starts or stops playback, and then I use Tasker to change the home screen.

As I kept adding functionality, I added the third screen, with Google Music widget and myTuner widget (radio), so I can connect tablet via Bluetooth to my Bluetooth amplifier, and listen to my Google Music library and radio stations:

The key thing, though, for me, was turning the tablet on. As you know, Nexus doesn't have the front on/off/home button as i.e. iPad. So turning it on from the side button is a bit awkward. The proximity sensor is not there as well, since N7 is not a phone, but a tablet. Even if it was there, it reacts only on couple of centimeters distance. So the most logical conclusion is to just use the Nexus front camera.

After a bit of searching, I found exactly what I needed - a perfect software, designed exactly for this purpose - Motion Detector. This software uses the front camera and if it detects any changes, it can do several things. One of those things is to send the intent to Tasker. Whooooa! Because, once we get something to Tasker, we can do anything we want, right? Like ... turn on the screen! Of course, you have to be rooted in order to do this. But that's not a problem. You can set several parameters, how sensitive the detector should be, how many change events need to happen before you trigger the intent, etc. This needs a bit of playing and trying to get it right, but once you set it, it works beautifully.


The downside is that the tablet would be on the whole time, it would never get into "deep sleep" mode, because the front cam would be working. But after like 6 months, I don't see any problems with this. You just approach the tablet, and the screen wakes up. After 15 seconds of inactivity, it goes off. To save the tablet battery just a bit, I bought a simple digital on off switch timer, which turns off power supply at 1 am until 5 am, so the tablet is not always on AC. Also, I turn off the motion detector automatically from Tasker at 1 am until 5 am, so the tablet gets at least a bit of "deep sleep". Don't know if this helps at all, but it seemed like a good idea at the time :)

Another interesting option the Motion Detector has, is to capture image, once it detects motion. And it can upload the image to your FTP server or send it by mail to you. So you also get the basic security system - while you are not at home, you can monitor for any motion in your home.

Another thing I added are the BLE Bluetooth switches, which also connect to this tablet, but more about those in special article.

Next thing I implemented is direct LAN control of the lights via Tasker and fantastic Send/Expect Tasker plugin. As you probably know, Yeelights can be used in LAN if you enable Developer mode, or LAN control, as they call it now. Then you can send JSON commands to the bulbs and have immediate control, without going to the cloud through Xiaomi/Yeelight servers. But this is a bit more complex and deserves an article on it's own. Maybe someday, if I have enough free time :)

The last thing I added was Google Assistant voice control. As you may or may not know, there are problems with Yeelight/Google Assistant integration if you use Chinese server. You have to be on Singapore server in order to get this working. This unfortunately, has other problems, because the Home control from Xiaomi, doesn't work well, so you can't have everything, until Xiaomi implements this on all servers. So I decided to bypass the Google Assitant integration, and use IFTTT, AutoNotification Tasker plugin to do it. The main objective being bypassing Xiaomi's servers. The way it works is that Google Assistant is set on a key word. I chose to use "can you". So when I say, "OK, Google, can you..." it knows to send this text i said to the IFTTT. Then IFTTT has a small applet which sends notification to my tablet, with the exact text I said (excluding "OK Google"). AutoRemote then intercepts this notificaton, passes it to Tasker, which parses the text and does what needs to be done.

If sounds complex, but it is really fairly easy. All I had to do is check for certain words, i.e. when it finds the words "left lamp" in text, it knows that I want to do something with left lamp. If it finds the word "percent", it looks for previous word, and knows that this is a brightness level for the bulb. If it finds words "red, blue, green" etc, it knows that is should set the bulb(s) to this color. Then there are words "on, off, switch, toggle", etc, etc. And it works quite well.

So for the end, a small video with all the phases of developing the "lights project" and YeeMee addon for Kodi....