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

Could be. I grabbed 1.7.1 which was the newest posted.

Edit: would definitely appreciate your updates :slight_smile:

Super! Don’t hesitate to ask anything if you’re stuck :slight_smile:

Yeah, PlatformIO is pretty nice. I’m using Arch Linux for all my coding / hacking


If you have a look at the Espurna source code (https://bitbucket.org/xoseperez/espurna/src/a042efb5106aa7dae4b26e3975910f20c81908fb/code/espurna/light.ino?fileviewer=file-view-default), you can see functions (color_rgb2array) that convert a RGB triplet into a HEX color.

I wrote my own firmware that publishes the colors as HASS wants them :slight_smile:

1 Like

so when will you publish your firmware with OTA and all the goodie stuff? :slight_smile:

With Xose PĂ©rez firmware is it only possible to turn the bulb on/off and change color, not set the brightness?

The last time I looked at the source code for something I got sucked into developing an application, so I’m realllllly trying to avoid it here :slight_smile: But loving seeing what you guys are working on here, the evolution will happen :slight_smile:

1 Like

I have problem to get the MQTT to work, when I eneter the commands (see below) nothing happens. I have configured the bulb and I can see in status site that the MQTT is “Connected” but when I try to send commands from my RPi with Hass and Mosquitto.

This is the commands I did try sending from my RPi
mosquitto_pub -u pi -P xxxxxxxx -t “/test/switch/AI LIGHT_AC38FB/relay/color” -m “#FF0000”
mosquitto_pub -u pi -P xxxxxxxx -t “/test/switch/AI_LIGHT_AC38FB/relay/color” -m “#FF0000”
mosquitto_pub -u pi -P xxxxxxxx -t “/test/switch/AI-Light01_AC38FB/relay/color” -m “#FF0000”
mosquitto_pub -u pi -P xxxxxxxx -t “/test/switch/AI-Light01 AC38FB/relay/color” -m “#FF0000”

There’s no error message and my ‘/var/log/mosquitto/mosquitto.log’ is empty

The curl commands works fine, it’s just the mqtt that I can’t get to work.

Here’s some info for my system
chip id: AC38FB
hostname For the bulb): AI-Light01
RPi: IP 192.168.50.35

Here’s screenshots of the bulb

Does anyone have any idea what could be wrong?

Does your MQTT broker require authentication? If not, then leave the MQTT user field blank.

Publishing messages without a username/password (with authentication enabled), results in nothing :slight_smile: Your messages disappear in nothingness


I have made my complete firmware available on Github here; https://github.com/stelgenhof/AiLight. I reworked the previous library version into a regular PlatformIO project.

Note that it isn’t equipped with many features like Espurna, however gives you a basic firmware that allows you to control the light with MQTT/HASS.

With this firmware you can:

  • switch the light on/off
  • set the RGB colours
  • set the white value
  • set the brightness
  • set the colour temperature
  • make the light flash

There is still some work to do, but should be working fine if you follow the instructions in the README file.

Happy to hear your thoughts / feedback!

I found the problem, as I have changed the hostname to AI-Light01, AI-Light02 and so on

then I don’t need the chip ID. I just put the hostname in command,

so in my case it should look like
mosquitto_pub -u pi -P xxxxxxxx -t “/test/switch/AI-Light01/relay/color” -m “#FF0000”

:grinning:

Is it possible to do OTA between firmwares as long as they both support OTA, like if I have Xose PĂ©rez firmware, can I then do an OTA to install your @stelgenhof firmware?

Super! Nice you figured it out

Never tried that before but I think it should work fine since my firmware uses the same code base.

@stelgenhof

When I ran “Build” in PlatformIO I got these error messages.

/Users/darijo/Documents/Arduino/PlatformIO/AiLight-master/src/light.ino: In function 'void
_ lightMQTTCallback(uint8_t, const char*, const char*)’:_
/Users/darijo/Documents/Arduino/PlatformIO/AiLight-master/src/light.ino:52:19: error: 'MQT
T_LIGHT_ACTION_RESTART’ was not declared in this scope

mqttSubscribe(MQTT_LIGHT_ACTION_RESTART);
^
/Users/darijo/Documents/Arduino/PlatformIO/AiLight-master/src/light.ino:58:21: error: 'MQT
T_LIGHT_ACTION_RESTART’ was not declared in this scope
mqttUnsubscribe(MQTT_LIGHT_ACTION_RESTART);
^
/Users/darijo/Documents/Arduino/PlatformIO/AiLight-master/src/light.ino:81:23: error: 'MQT
T_LIGHT_ACTION_RESTART’ was not declared in this scope
if (strcmp(topic, MQTT_LIGHT_ACTION_RESTART) == 0) {
^

I followed your ReadMe, but I’m not sure what to put here.
MQTT_LIGHT_STATE_TOPIC // The MQTT state topic for Home Assistant
MQTT_LIGHT_COMMAND_TOPIC // The MQTT command topic for Home Assistant

I just wrote, not sure that’s OK
#define MQTT_LIGHT_STATE_TOPIC “/house/libe/sensor”
#define MQTT_LIGHT_COMMAND_TOPIC “/house/libe/status”

Also I’m not sure about this ‘Update the ‘upload_port’ variable in your platformio.ini file with the ‘hostname’ value from the Serial Monitor.’ when do I do that after I have flashed the firmware and turned on the bulb?

Where do I set what hostname I would like the bulb to have, like ‘AI-Light01’?

seems to be a cool firmware, will def flash my bulbs with it, I have 2 right now and I have ordered 10 more. :slight_smile:

Can you please update your local clone of the repository? My apologies, as this part of the code incidentally was left behind. Please be aware that I will still make changes and improvements to the firmware. I try to avoid these issues as much as possible of course!

As for the MQTT topics, anything is fine as long as it is the same in Home Assistant and the firmware. The state topic is used for communicating the current state to HASS; the command topic is used for responding to commands from HASS. Mine are set as follows:

  • MQTT_LIGHT_STATE_TOPIC: “/office/light”
  • MQTT_LIGHT_COMMAND_TOPIC: “/office/light/set”

The hostname will default look something like this “AiLight_####.local”, where #### is a unique identifier based on the ESP8266 Chip ID. If you have your light still connected to the FTDI cable, then you can see this hostname in your terminal session.

I am aware this version is not quite ‘plug and play’, so I appreciate your feedback for me to improve the firmware. The Espurna firmware is more advanced, since it has a webinterface that enables you to see the firmware details and set all configuration variables.

Still get the same error message after I download from https://github.com/stelgenhof/AiLight (I pressed ‘Clone or download’ and then ‘Download ZIP’). I’m using Mac, has that something to do with it?

/Users/darijo/Documents/Arduino/PlatformIO/AiLight/src/light.ino: In function 'void lightMQTTCallback(uint8_t, const char*,

const char*)’:
/Users/darijo/Documents/Arduino/PlatformIO/AiLight/src/light.ino:52:19: error: ‘MQTT_LIGHT_ACTION_RESTART’ was not declared
in this scope
mqttSubscribe(MQTT_LIGHT_ACTION_RESTART);
^
/Users/darijo/Documents/Arduino/PlatformIO/AiLight/src/light.ino:58:21: error: ‘MQTT_LIGHT_ACTION_RESTART’ was not declared
in this scope
mqttUnsubscribe(MQTT_LIGHT_ACTION_RESTART);
^
/Users/darijo/Documents/Arduino/PlatformIO/AiLight/src/light.ino:81:23: error: ‘MQTT_LIGHT_ACTION_RESTART’ was not declared
in this scope
if (strcmp(topic, MQTT_LIGHT_ACTION_RESTART) == 0) {
^

@stelgenhof
I installed Atom and Platform on an Win10 and I get same error message there.

You are absolutely right. I must have overlooked that part. It is some code left behind while I was testing it. I’ve updated it on Github. Can you update again by either downloading it again or issuing a ‘git pull’ command in your local repository?

I’ve tested it myself and the firmware compiles now.

yes! it’s working now. Will try to flash the bulb tomorrow.

Is it possible to set custom hostname for the bulb, like AI-Light01.local, AI-Light02.local
 and not ‘AiLight_####.local’ as you described above.