How To: Inexpensive ($10 US) WiFi RGB Bulb that works with Home Assistant

Yeelight, is it possible to that the bulb save the state of the light after a reboot (power turned off and on)?

Like it’s possible with AI Light and Espurna

I now have a $13 (with tax) RGB/gold bulb that works with Home-Assistant thanks to ekim, Sam and all the contributors. Home-Assistant did discover the bulb but did not display the selection for the effect, the color picker, the color temperature or the white value features. Everything worked after I added the all the features as a mqtt_json light in the configuration.yaml file.

I had the same problem with the color picker and so on. So me and Sam debuged and found, if changing
(In pubsubclient.h, MQTT_MAX_PACKET_SIZE needs to be set to 256) to 512 instead will make the autodiscover work better with color picker, white and temp.

So change that and update the firmware, OTA so you don’t need to soldering agani :slight_smile:

1 Like

Thanks for the tip!

Just wanted to let you guys know that I reworked my first version of the firmware and now a new one is ready! This one now remembers all your last light settings after a power cycle. Also, it has a neat embedded UI that allows you to control the light remotely and adjust some settings like MQTT, WiFi, etc.

The UI is responsive and looks something like this:

On my blog I wrote about the background developing this: https://www.sachatelgenhof.nl/blog/ailight
You can also checkout the new version on Github here: https://github.com/stelgenhof/AiLight

Let me know what you think and what features you’d like to see else :slight_smile:

5 Likes

This morning I installed the new version of the AiLight software from @stelgenhof and was really pleasantly surprised. In the process of doing so, I came to the startling realization that I’m my own worst enemy. :slight_smile:

After a bit of learning I was able to compile and install the new software on my AiLight and all I can say is - WOW - Sacha, you’ve really outdone yourself! I was floored by the simplicity, elegant UI design, and beautiful AiLight functionality. I absolutely love this code and can’t say enough great things about what a fantastic job Sacha has done! Kudos to you sir! I very much appreciate all your hard work and can’t help but gush about how happy I am with it.

After reading Sacha’s instructions on GitHub I wanted to share my learnings in an effort to help anyone else who runs into problems:

  1. When performing ‘npm install’ at the command line, make sure you’re in the AILight-master directory first. If not then NodeJS won’t see the package.json file and none of the proper dependancies will be installed and you won’t be able to compile properly.

  2. I also had to comment out the #ifdef DEBUG and #endif lines in main.ino around the // Serial Port Initialization section, since I wasn’t seeing any debug information in the PlatformIO Serial Monitor after I successfully flashed the AiLight. Potentially this was a fluke, but it seemed to get resolved when I removed the aforementioned #ifdef / #endif statements.

  3. tool-mkspiffs was not installed initially in PlatformIO. PlatformIO detected that it wasn’t installed and installed it for me, but it took me a while to understand that PlatformIO had already installed it and that I just needed to do was restart PlatformIO. After that all was well.

Cheers Sacha! You made my day!!!

1 Like

Hi Mike,

Thanks for the nice words and feedback! Really appreciate it. It is still a work in process so hopefully I can iron out some of those kinks :slight_smile:

As for the problems you ran into:

  1. Good catch. My instructions are indeed not clear on this. I’ll update it shortly.
  2. Let me have a look at the Serial Port init part. I enabled it only when in DEBUG mode, because in production mode Serial output isn’t needed. If that isn’t working properly then I need to see for another option.
  3. The AiLight firmware isn’t using SPIFFS at all. The UI code is all embedded. Did you get any error message during flashing/compilation about this?

Cheers! Sacha

Hi Sacha,

No problem. The code seemed pretty solid, so it doesn’t seem like there are many issues to contend with.

For the serial port, it’s not a big deal if debug output isn’t needed. I wasn’t sure about that, since the GitHub instructions mentioned setting the upload_port variable in platformio.ini to the hostname shown in the debug output.

As for the tool-mkspiffs issue, I’m not sure why I saw that, especially if it’s not used in the UI. Please disregard that comment. Could be I didn’t have my second cup of coffee when I compiled. :wink:

Made some minor improvements. Updated the instructions and now the HTML UI has a favicon :).
Thinking about separating the instructions into a Developer one and one for end user…(how to use the UI).

1 Like

Thanks very much Sacha! The new version compiled without any issues. I’ll flash the light with it first thing in the morning, Boston time, and take it for a spin. I look forward to trying it out!

I’m still struggling to get the color temperature and white value slider to show up in HA. I’ve reset HA multiple times and stripped my configuration.yaml down to barebones with no luck. I’ll try tracking the messages manually tomorrow and as a last resort update HA. I’m currently running version 0.39.3.

I am using the latest version of HA: 0.43.1

Hi Sacha,

I performed a fresh Home Assistant installation with version 0.43.2 and found that everything worked as expected, including the now visible color temperature and white value sliders in Home Assistant. I’m guessing there’s a bug in Home Assistant version 0.39.3, or more than likely some issue in my configuration that’s causing weirdness within Home Assistant.

In conclusion, your code is awesome and I would highly recommend it to anyone interested in using the AiLight!!! It’s currently the most functional and feature rich code I know of for the AiLight!

Hi Mike,

Happy to hear it works now for you. Thanks again for your kind words. Anything else you would like to see added or something that is not working perfectly?

Cheers! Sacha

Good work man. I was responding to you on Reddit too, but I’m moving the reply here because I like this community better :stuck_out_tongue:

Ok I got it flashed, that was pretty straightforward, and it wooooorks! And I echo what @mikegwatson said – this is about as elegant as one gets with embedded devices, and I would wish all IoT stuff was this polished from the get go.

My first facepalm is I didn’t set the MQTT to retain messages which is behavior I want and I can’t figure out how to OTA. It’s not listening on 8266, which I didnt change in config.h, so I’m not sure where to go from here… Am I stuck other than getting serial on it again?

1 Like

Thanks! Many developers, hackers, etc. are pretty happy when their prototype works. However I wanted to challenge myself a bit to see if I could make a clean, elegant prototype that is easy to use and looks beautiful. Simple enough even my grandmother could use it :slight_smile:

I am quite happy with the results so far; but there is always room for improvements…

If you haven’t changed anything in the config.h file, OTA should work on port 8266 and the device name you gave it. So something like: .local:8266. In my place I’ve found that the mDNS isn’t always reliable: maybe it is my own network… If I use the IP address of the device instead, then OTA most of the times works perfectly.

Did you see any message when you tried to upload via OTA on the Serial Monitor?

Yah I don’t bother with mDNS stuff much anyhow, my DDNS is reliable. it’s named ailight1 and that resolves fine for me. Nah, its not a name resolution problem. That port is literally not open on the device. 80 and 5353 are all that respond, since I hard scanned it in case it was being awkward (And since Im blind to serial)… looking at the code I don’t see why it wouldn’t try to open that port so, ugh, guess something isn’t quite right with it.

Let me have a few tries again to see if it works ok or not.

I was curious if there were other conditions in play like, there’s a magic URL to activate it, or it works better if the device is reset and in AP mode, or stuff like that… didn’t dig too hard since I was just looking for an easy answer from you :stuck_out_tongue:

Just tried about 5 times and was pretty much successful using the IP address. Few times it didn’t respond but that was because I used the wrong port number (I am not using the standard 8266 port number).

Yah. Feared as such. Ill have to go serial sometime when Im motivated to not be annoyed, I’ll see if I can find some kind of output giving a clue as to why it’s failing before blowing it away.