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

In response to this Home Assistant discussion, I recently purchased some $10.00 WiFi RGB light bulbs that I modified and work really well with Home Assistant.

Disclaimer: Some relatively simple soldering is required, as well as downloading code to the bulb.
If you’re still interested read on…

A big thank you to Xose Pérez and Sacha Telgenhof for all their hard work writing and maintaining Espurna and stelgenhof/AiLight code!!!

Materials:

  • Wowfeel / AI Light RGB LED bulbs are available from: Amazon, eBay, or Ali Express to name just a few. I’ve seen a lot of different names for these bulbs, but an easy way to find them is to do an online search for the Tuya Smart App and look for the app shown on the phone in the picture above.

  • FTDI / TTL-232R-3V3 USB to TTL convertor like the one shown here.

Steps:

  • Remove the white diffuser on the bulb by twisting and pulling. I was able to remove one of my diffusers without too much effort, while the other was slightly more stubborn. Either way they come apart pretty easily.

  • To program the AI Light, use a FTDI or TTL-232R-3V3 USB to TTL adaptor wired up as shown below:

    TTL-232R-3V3 GND-------->GND Ai Light
    TTL-232R-3V3 GND-------->IO0 Ai Light
    TTL-232R-3V3 3.3v--------->3V3 Ai Light
    TTL-232R-3V3 TxD--------->Rx Ai Light
    TTL-232R-3V3 RxD--------->Tx Ai Light

You can see the exposed solder pads below on the Ai Light, this is where the wires get soldered.

  • Lightly solder flexible wire to the following contacts on your AI Light. Remove about 1mm of insulation from the wires and tin them a bit. Apply a hot soldering iron on the pads and leave a small bit of solder on them. Next just touch each wire with a pad and heat them together for less than a second. Afterwards, I connected the flexible wires to solid CAT5 wire, so that I could easily insert and remove them in a bread board to program as needed during debugging.

======================================================================== 

Previously I used the Arduino environment with Espurna code, but found that using PlatformIO and NodeJS with Sacha Telgenhof’s code provides a beautiful GUI web interface that’s very stable and has great MQTT support within Home Assistant. Also, Sacha’s code provides added functionality with color temperature and white value sliders on the Home Assistant web interface. For that reason I would recommend skipping the rest of this How To and check out Sacha’s code and How To on GitHub!

--------------------------------------------------------------------------------------------------------------------------------------

SKIP THE REST OF THIS HOW TO AND VISIT SACHA’S GITHUB PAGE SHOWN ABOVE

--------------------------------------------------------------------------------------------------------------------------------------

  • Setup the Arduino environment as described here.

  • Next install the ESP8266FS tool by following these steps:

    • Download the tool here.
    • Unzip esp8266fs.jar into the folder: /Arduino/tools/ESP8266FS/tool/ (you may need to create it first).
    • It should end up looking like this: /Arduino/tools/ESP8266FS/tool/esp8266fs.jar
    • Restart the Arduino IDE. Now you should see ESP8266 Sketch Data Upload in the Tools menu.
  • If you haven’t done so, download the Espurna code by Xose Pérez available here. I used the latest Dev build, only because I ended up on the bleeding edge of all this somehow, but any subsequent master build after 1.7.1 should be fine.

  • Before programming, be sure to setup your Arduino tools as follows:

  • Plug in the FTDI / TTL-232R-3V3 USB cable into a computer, then click on Arduino IDE -> Sketch -> Upload (you should see … dots indicating that the binary is uploading)
    If you receive any upload errors then check your Arduino IDE -> Tools selections and make sure everything is setup as recommended, also check that you have the correct wiring and that you don’t have any loose wires.

  • After a successful upload, unplug the USB Cable and plug it back in. This is required to put the Ai Light back into programming mode. If you skip this step then you’ll get an error. Once you’ve removed your USB adaptor and then plugged it back in go to the Arduino IDE -> Tools -> ESP8266 Sketch Data Upload (again you should see … dots indicating that the binary is uploading). Once you’ve done that successfully, disconnect all the wiring.

  • Upon powering on with AC mains the device will start in Soft AP mode creating a WIFI SSID named “DEVICE_XXXXXX”, where DEVICE will be an identifier of your Ai Light and XXXXXX are the last 3 bytes of the radio MAC address. Connect via WiFi with a phone, PC, laptop, or whatever to that WiFi network, the password is “fibonacci”. Once connected in Soft AP mode browse to “http://espurna.local”. It will then present an authentication challenge. The default user and password are “admin” and “fibonacci” (again).

  • After that you’ll be presented with another page change with the previous default password. The new password has to have a minimum of 8 characters (letters, numbers and _) including one number, one lower case, and one uppercase. The same password is used for the WIFI Access Point, for the web interface and for the OTA firmware upload.
    Once you change the password you’ll have to authenticate again using the new password and finally you will see the configuration page where you can set different configuration parameters. You can configure up to five WiFi networks. The code tried to connect to WiFi networks in order of signal strength. If none of the defined networks succeed it will default back into Soft AP mode again. You can also switch back to Soft AP mode by double clicking the on-board button or reset the board long clicking it. The Ai Light will stay in Soft AP mode for a minute before trying to reconnect.

  • As a general rule, anytime changes are successfully made the firmware displays a dialog saying “changes saved.”
    Join WiFi network and see if you can find the Ai Light and enter the IP address in your web browser.

  • If all goes well you can now switch the light on and off with the web interface and change the colors of the light. If you already have MQTT installed on Home Assistant then go to the MQTT tab on the AI Light web interface and enter the credentials of your HA MQTT server and hit Update. If all goes well click the Status on the left of the AI Light web interface and you should see CONNECTED. Be sure to make note of your CHIP ID.


Once you’ve got everything up and running you can try the following:

COMMAND LINE API:

(Make sure to get your HTTP API Key from the Ai Light espurna web interface / ADMIN Tab on the left):
Issue the following commands to turn ON the AI Light, change the color to GREEN, and turn it OFF:

curl "http://YOUR_IP_ADDRESS/api/relay/0?apikey=YOUR_API_KEY&value=1"
curl "http://YOUR_IP_ADDRESS/api/color/?apikey=YOUR_API_KEY&value=00FF00"
curl "http://YOUR_IP_ADDRESS/api/relay/0?apikey=YOUR_API_KEY&value=0"

eg. curl "http://192.168.1.15/api/relay/0?apikey=4709C7864E96513E&value=1"

COMMAND LINE MQTT:

(Make sure to get your CHIP ID (YOUR_CHIP_ID) from the Ai Light espurna web interface / STATUS section of the left, also you only need -u and -P options shown below if you have enabled MQTT security in HA):

mosquitto_pub -u username -P password -t "/test/switch/AI LIGHT_YOUR_CHIP_ID/relay/0" -m 1
mosquitto_pub -u username -P password -t "/test/switch/AI LIGHT_YOUR_CHIP_ID/color" -m "#FF0000"
mosquitto_pub -u username -P password -t "/test/switch/AI LIGHT_YOUR_CHIP_ID/relay/0" -m 0

e.g. mosquitto_pub -u pi -P secret-password -t "/test/switch/AI LIGHT_0AF81C/relay/0" -m 1

HOME ASSISTANT MQTT:

To configure the Ai Light in Home Assistant, add the following to your configuration.yaml file.

group:
  default_view:
  lights:
    name: Lights
    entities:
      - light.RGB_light

mqtt:
  broker: 127.0.0.1
  port: 1883
  client_id: home-assistant
  username: YOUR_USER_NAME
  password: YOUR_PASSWORD
  
light:
  platform: mqtt
  name: 'RGB_light'
  state_topic: '/test/switch/AI LIGHT_05FB1C/relay/0'
  command_topic: '/test/switch/AI LIGHT_05FB1C/relay/0'
  payload_on: 1
  payload_off: 0
  rgb_state_topic: '/test/switch/AI LIGHT_05FB1C/color'
  rgb_command_topic: '/test/switch/AI LIGHT_05FB1C/color'
  rgb: true
  optimistic: false

If everything goes according to plan, you should see something like this when you turn on the switch then click on it to adjust the color.

[/quote]

  • Setup the Arduino environment as described here.

  • Next install the ESP8266FS tool by following these steps:

    • Download the tool here.
    • Unzip esp8266fs.jar into the folder: /Arduino/tools/ESP8266FS/tool/ (you may need to create it first).
    • It should end up looking like this: /Arduino/tools/ESP8266FS/tool/esp8266fs.jar
    • Restart the Arduino IDE. Now you should see ESP8266 Sketch Data Upload in the Tools menu.
  • If you haven’t done so, download the Espurna code by Xose Pérez available here. I used the latest Dev build, only because I ended up on the bleeding edge of all this somehow, but any subsequent master build after 1.7.1 should be fine.

  • Before programming, be sure to setup your Arduino tools as follows:

  • Plug in the FTDI / TTL-232R-3V3 USB cable into a computer, then click on Arduino IDE -> Sketch -> Upload (you should see … dots indicating that the binary is uploading)
    If you receive any upload errors then check your Arduino IDE -> Tools selections and make sure everything is setup as recommended, also check that you have the correct wiring and that you don’t have any loose wires.

  • After a successful upload, unplug the USB Cable and plug it back in. This is required to put the Ai Light back into programming mode. If you skip this step then you’ll get an error. Once you’ve removed your USB adaptor and then plugged it back in go to the Arduino IDE -> Tools -> ESP8266 Sketch Data Upload (again you should see … dots indicating that the binary is uploading). Once you’ve done that successfully, disconnect all the wiring.

  • Upon powering on with AC mains the device will start in Soft AP mode creating a WIFI SSID named “DEVICE_XXXXXX”, where DEVICE will be an identifier of your Ai Light and XXXXXX are the last 3 bytes of the radio MAC address. Connect via WiFi with a phone, PC, laptop, or whatever to that WiFi network, the password is “fibonacci”. Once connected in Soft AP mode browse to “http://espurna.local”. It will then present an authentication challenge. The default user and password are “admin” and “fibonacci” (again).

  • After that you’ll be presented with another page change with the previous default password. The new password has to have a minimum of 8 characters (letters, numbers and _) including one number, one lower case, and one uppercase. The same password is used for the WIFI Access Point, for the web interface and for the OTA firmware upload.
    Once you change the password you’ll have to authenticate again using the new password and finally you will see the configuration page where you can set different configuration parameters. You can configure up to five WiFi networks. The code tried to connect to WiFi networks in order of signal strength. If none of the defined networks succeed it will default back into Soft AP mode again. You can also switch back to Soft AP mode by double clicking the on-board button or reset the board long clicking it. The Ai Light will stay in Soft AP mode for a minute before trying to reconnect.

  • As a general rule, anytime changes are successfully made the firmware displays a dialog saying “changes saved.”
    Join WiFi network and see if you can find the Ai Light and enter the IP address in your web browser.

  • If all goes well you can now switch the light on and off with the web interface and change the colors of the light. If you already have MQTT installed on Home Assistant then go to the MQTT tab on the AI Light web interface and enter the credentials of your HA MQTT server and hit Update. If all goes well click the Status on the left of the AI Light web interface and you should see CONNECTED. Be sure to make note of your CHIP ID.


Once you’ve got everything up and running you can try the following:

COMMAND LINE API:

(Make sure to get your HTTP API Key from the Ai Light espurna web interface / ADMIN Tab on the left):
Issue the following commands to turn ON the AI Light, change the color to GREEN, and turn it OFF:

curl "http://YOUR_IP_ADDRESS/api/relay/0?apikey=YOUR_API_KEY&value=1"
curl "http://YOUR_IP_ADDRESS/api/color/?apikey=YOUR_API_KEY&value=00FF00"
curl "http://YOUR_IP_ADDRESS/api/relay/0?apikey=YOUR_API_KEY&value=0"

eg. curl "http://192.168.1.15/api/relay/0?apikey=4709C7864E96513E&value=1"

COMMAND LINE MQTT:

(Make sure to get your CHIP ID (YOUR_CHIP_ID) from the Ai Light espurna web interface / STATUS section of the left, also you only need -u and -P options shown below if you have enabled MQTT security in HA):

mosquitto_pub -u username -P password -t "/test/switch/AI LIGHT_YOUR_CHIP_ID/relay/0" -m 1
mosquitto_pub -u username -P password -t "/test/switch/AI LIGHT_YOUR_CHIP_ID/color" -m "#FF0000"
mosquitto_pub -u username -P password -t "/test/switch/AI LIGHT_YOUR_CHIP_ID/relay/0" -m 0

e.g. mosquitto_pub -u pi -P secret-password -t "/test/switch/AI LIGHT_0AF81C/relay/0" -m 1

HOME ASSISTANT MQTT:

To configure the Ai Light in Home Assistant, add the following to your configuration.yaml file.

group:
  default_view:
  lights:
    name: Lights
    entities:
      - light.RGB_light

mqtt:
  broker: 127.0.0.1
  port: 1883
  client_id: home-assistant
  username: YOUR_USER_NAME
  password: YOUR_PASSWORD
  
light:
  platform: mqtt
  name: 'RGB_light'
  state_topic: '/test/switch/AI LIGHT_05FB1C/relay/0'
  command_topic: '/test/switch/AI LIGHT_05FB1C/relay/0'
  payload_on: 1
  payload_off: 0
  rgb_state_topic: '/test/switch/AI LIGHT_05FB1C/color'
  rgb_command_topic: '/test/switch/AI LIGHT_05FB1C/color'
  rgb: true
  optimistic: false

If everything goes according to plan, you should see something like this when you turn on the switch then click on it to adjust the color.

29 Likes

Wow this is very cool, I might buy a couple of these and try it out. I have some of the cheap limitlessled bulbs but these are even cheaper and I’d prefer wifi. Do transitions/color fades work well with HA? Will it work with the flux component to change color temp?

edit: except they don’t seem to be in stock anywhere, hmm

2 Likes

Yes, at at around $10.00 each it’s not a huge investment to try out. As you can see here (scroll toward the bottom) another poster mentioned, using a different set of code, that he was able to implement Brightness, Color Temp and White Value on the Ai Light. The Espurna code for the Ai Light is still pretty new and doesn’t have everything implemented yet, but I expect that to change in short order. I just got everything working very recently and haven’t had a chance to try everything out. The good news is that it’s all open source Arduino code. You can see the current Ai Light code here and the MY9291 library here. If there’s a feature missing you can write the code and make it happen. The other cool part about the Espurna code is that once you flash it on the Ai Light, you can do over the air updates via WiFi. I haven’t tried that part out yet, but it seems like a really flexible platform overall, since it’s based on the ESP8266.

As a follow up, it does look like Amazon in the US just sold out, but Ali Express still has them for slightly more.

why not just buy xaiom, same price…

1 Like

Do you mean the Xiaomi Yeelight? If so, I believe they typically sell for around $30 USD and use 220V, which isn’t very useful in the US.

@ekim thanks for the write up, I will order a few and try it out.

@oakbrad You’re welcome! Give a holler, if you get stuck or need some pointers.

I like this a lot… mostly because I’m used to the ‘blind’ Limitlessled type right now.

If the power is cut to the light, I guess since it’s using MQTT it’s just going to see the last state? I wonder if this could be adjusted to be more native, eg, if the bulb doesn’t ping then we know it’s offline entirely? That’s been my big “problem” with all of the bulbs… the WAF around you aren’t getting rid of switches :slight_smile:

@quadportnick Yes, the software is really cool, the Espurna configuration web page allows you to select the light power on setting of your choice.

For example, you can set the light to:

  • Always turn on when power is applied
  • Always remain off when power is applied
  • Return to the previous power state once power is returned

Furthermore, it remembers the last color that was set and returns to that color when power is applied. If you’ve got any pending, or new, MQTT messages then they would certainly override the pre-programmed default power on state. Additionally, to your point, if the bulb is off then it certainly can’t ping. Also, the light provides MQTT command acknowledgements, so that Home Assistant always knows the state of the bulb.

2 Likes

Yah, i’m definitely buying some now lol. Thank you for the thread :slight_smile:

Cool. Sure, anytime! :slight_smile:

1 Like

For me the same thing. I live in Japan and we use 100V. Unfortunately the Yeelight isn’t available yet in a 100/110V version. On the other hand, who doesn’t love to tinker :wink:

That other poster was me :slight_smile: I can post the code later regarding the color temperature if you like.

Thank you very much Sacha.
Yes, I’m a bit envious of the additional color temperature functionality of your code. :wink:

You can also search on various sites like AliExpress using the keywords “M1636” (Model number) or “MY9291” (The LED driver used in this light).

1 Like

Hi Michael, I commented in the discussion thread of Xose’s repos. The code is available in my repos here: https://github.com/stelgenhof/AiLight. Let me know if you have any questions :slight_smile:

That’s a good tip about searching for M1636 and MY9291. Thank you for that!

Also, thank you so much code repo! I can’t wait to try it out!

Around 10-15, I think 110 is available. Try gearbest

I’m also working on an alternative firmware for theses bulbs. I haven’t received one yet, but my code should already work. It supports the MQTT Discovery and the MQTT JSON Light component (rgb, white, brightness and color temperature).


(In pubsubclient.h, MQTT_MAX_PACKET_SIZE needs to be set to 256)

Feedbacks are welcomed. Thanks.

Sam

1 Like

Thanks Sam. Choice is always good!