This software lets you control an RGB led strip via a MQTT-compatible home automation controller.
See settings.lua
for all cusomizable settings. You need to provide your Wi-Fi connection paramters, MQTT server address
and username/password if needed, and make sure the pin numbers for Red, Green and Blue match your setup. No other files
need to be modified.
integer
firmware, master
branch from 2016/10/12, with the following modules:
gpio, mqtt, net, node, pwm, tmr, uart, wifi
. Get yours at https://nodemcu-build.com/settings.lua
first). Use esplorer
or any other similar tool of your choice, and upload all files in the src
subdirectory.The on-board LED will flash rapidly if the software is not properly connected to either Wi-Fi or MQTT server, and will blink once every 10 seconds if the module is connected and functioning properly. It will also blink once every time an MQTT command is received.
Suppose the MQTT root topic is set to bedroom/bed
in settings.lua
. Then, the following commands will be accepted by NodeRGB:
bedroom/bed/light/set
: payload is either on
or off
, turns the light on and off.bedroom/bed/brightness/set
: payload is an integer from 0 to 100.bedroom/bed/rgb/set
: payload is a comma-separated triplet of integer values from 0 to 255. For example, 255,0,0 set the light color to red.bedroom/bed/fadetime/set
: payload is an integer from 0 to 3600000, set the fade-in/fade-out time in milliseconds. Default is 2000, or 2 seconds.NodeRGB reports back the following topics:
bedroom/bed/status
: payload is either connected
or disconnected
, disconnected
is set via Last Will and Testament.bedroom/bed/light/status
: the payload reflects the commands specified above.bedroom/bed/brightness/status
: same as above.bedroom/bed/rgb/status
: same as above.bedroom/bed/fadetime/status
same as above.NodeRGB sets the retain
flag on, so if your home-automation controller is restarted, it will
receive the current data from MQTT server upon reconnection.
Set up your Home Assistant like this:
light:
- platform: mqtt
name: 'Master Bedroom Bed Light'
state_topic: 'bedroom/bed/light/status'
command_topic: 'bedroom/bed/light/set'
brightness_state_topic: 'bedroom/bed/brightness/status'
brightness_command_topic: 'bedroom/bed/brightness/set'
rgb_state_topic: 'bedroom/bed/rgb/status'
rgb_command_topic: 'bedroom/bed/rgb/set'
brightness_scale: 100
optimistic: false
retain: true
qos: 1
Setting retain
flag to on
allows NodeRGB to re-acquire needed settings in case mains power was lost, or the module is
rebooted for any other reason.
This software is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/.