This project adds an easy way to create DIY lighting for Home Assistant, an amazing, extensible, open-source home automation system and Node-RED.
By sending a JSON payload (in an MQTT message), Home Assistant or Node-RED 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",
"flash": 5
}
I'm using ESP8266 microcontrollers for my lights because they are so cheap and small. The downside of the size and price is that programming them can be a bit of a hassle. There are many sites that go into detail, so I won't do it here. You'll need an ESP set up to work with the Arduino IDE. See the readme here for instructions. Another good device to work with is the Wemos D1 Mini, which has a built-in micro-USB port and is much easier to program.
- Using the Library Manager in the Arduino IDE, install ArduinoJSON and PubSubClient. You can find the Library Manager in the "Sketch" menu under "Include Library" -> "Manage Libraries..."
- NOTE:: At the moment, this project only supports ArduinoJSON version 5. The default is now version 6, so you'll have to specify the version to install in the dropdown in the Library Manager window.
- Open the
mqtt_esp8266_light
project in the Arduino IDE. - Update the
config-sample.h
file with your settings for LED type, pin numbers, WiFi settings, and MQTT settings. - Review the comments to help with the options. For the
CONFIG_STRIP
option, choose one ofBRIGHTNESS
,RGB
, orRGBW
. - 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 an ESP with the correct connections.
Note that the MOSFETs have pull-up resistors in this setup. This means that the lights may flash on when the module resets, but it was necessary to keep the ESP's pins in the right start state.