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.