fe3fb622ee
This user mod adds a function to toggle output pins via MQTT. |
||
---|---|---|
.. | ||
README.md | ||
usermod_mqtt_switch.h |
MQTT controllable switches
This usermod allows controlling switches (e.g. relays) via MQTT.
Usermod installation
- Copy the file
usermod_mqtt_switch.h
to thewled00
directory. - Register the usermod by adding
#include "usermod_mqtt_switch.h"
in the top andregisterUsermod(new UsermodMqttSwitch());
in the bottom ofusermods_list.cpp
.
Example usermods_list.cpp
:
#include "wled.h"
#include "usermod_mqtt_switch.h"
void registerUsermods()
{
usermods.add(new UsermodMqttSwitch());
}
Define pins
Add a define for MQTTSWITCHPINS to platformio_override.ini. The following example defines 3 switches connected to the GPIO pins 13, 0 and 2:
[env:livingroom]
board = esp12e
platform = ${common.platform_wled_default}
board_build.ldscript = ${common.ldscript_4m1m}
build_flags = ${common.build_flags_esp8266}
-D LEDPIN=3
-D BTNPIN=4
-D RLYPIN=12
-D RLYMDE=1
-D STATUSPIN=15
-D MQTTSWITCHPINS="13, 0, 2"
MQTT topics
This usermod listens on [mqttDeviceTopic]/switch/0/set
(where 0 is replaced with the index of the switch) for commands. Anything starting with ON
turns on the switch, everything else turns it off.
Feedback about the current state is provided at [mqttDeviceTopic]/switch/0/state
.
Home Assistant auto-discovery
Auto-discovery information is automatically published and you shoudn't have to do anything to register the switches in Home Assistant.