This project adds an easy way to control LED Xmas Smart Baubles from Home Assistant, an amazing, extensible, open-source home automation system.
I followed Gosse Adema's instructable to create the baubles and his origical code but wanted to change the effects and wanted to be able to control the baubles from Home Assistant, so I adapted the code and took extracts from corbanmailloux's esp-mqtt-rgb-led project. As of version 0.26, the MQTT JSON light platform has been merged into Home Assistant.
By sending a JSON payload (in an MQTT message), Home Assistant can include whichever fields are necessary, reducing the round trips from 3 to 1. For example, this is a sample payload including most of the fields:
{
"state": "ON",
"effect": "sparkle",
}
To set this system up, you need to configure the MQTT JSON light component in Home Assistant and set up a light to control. This guide assumes that you already have Home Assistant set up and running. If not, see the installation guides here.
-
In your
configuration.yaml
, add the following:light: - platform: mqtt_json name: mqtt_json_light_1 state_topic: "home/json_brightness" command_topic: "home/json_brightness/set" brightness: false effect: true effect_list: [sparkle, rainbow, uniglow] optimistic: false qos: 0
-
Set the
name
,state_topic
, andcommand_topic
to values that make sense for you. -
Restart Home Assistant. Depending on how you installed it, the process differs. For a Raspberry Pi All-in-One install, use
sudo systemctl restart home-assistant.service
(or just restart the Pi).
- Using the Library Manager in the Arduino IDE, install ArduinoJSON, PubSubClient, and Adafruit_NeoPixel. You can find the Library Manager in the "Sketch" menu under "Include Library" -> "Manage Libraries..."
- Update the
config-sample.h
file with your settings for pin numbers, WiFi settings, and MQTT settings. - Ensure that the
CONFIG_MQTT_CLIENT_ID
setting is a unique value for your network. - Set
CONFIG_MQTT_TOPIC_STATE
andCONFIG_MQTT_TOPIC_SET
to match the values you put in yourconfiguration.yaml
. - Save the configuration file as
config.h
. - Open the
.ino
file in the Arduino IDE and upload to a "WeMos D1 R1 & Mini" with the correct connections.