usermods/multi_relay/readme.md
This usermod-v2 modification allows the connection of multiple relays, each with individual delay and on/off mode. Usermod supports PCF8574 I2C port expander to reduce GPIO use. PCF8574 supports 8 outputs and each output corresponds to a relay in WLED (relay 0 = port 0, etc). I you are using more than 8 relays with multiple PCF8574 make sure their addresses are set in sequence (e.g. 0x20 and 0x21). You can set address of first expander in settings. (NOTE: Will require Wire library and global I2C pins defined.)
All responses are returned in JSON format.
http://[device-ip]/relayshttp://[device-ip]/relays?switch=1,0,1,1The number of values behind the switch parameter must correspond to the number of relays. The value 1 switches the relay on, 0 switches it off.
http://[device-ip]/relays?toggle=1,0,1,1The number of values behind the parameter switch must correspond to the number of relays. The value 1 causes the relay to toggle, 0 leaves its state unchanged.
Examples:
http://[device-ip]/relays?toggle=0,1,0,0http://[device-ip]/relays?switch=1,0,1You can toggle the relay state by sending the following JSON object to: http://[device-ip]/json
Switch relay 0 on: {"MultiRelay":{"relay":0,"on":true}}
Switch relay 3 and 4 off: {"MultiRelay":[{"relay":2,"on":false},{"relay":3,"on":false}]}
wled/deviceMAC/relay/0/command on|off|togglewled/deviceMAC/relay/1/command on|off|toggleWhen a relay is switched, a message is published:
wled/deviceMAC/relay/0 on|offAdd multi_relay to the custom_usermods of your platformio.ini environment.
You can override the default maximum number of relays (which is 4) by defining MULTI_RELAY_MAX_RELAYS.
Some settings can be defined (defaults) at compile time by setting the following defines:
// enable or disable HA discovery for externally controlled relays
#define MULTI_RELAY_HA_DISCOVERY true
The following definitions should be a list of values (maximum number of entries is MULTI_RELAY_MAX_RELAYS) that will be applied to the relays in order: (e.g. assuming MULTI_RELAY_MAX_RELAYS=2)
#define MULTI_RELAY_PINS 12,18
#define MULTI_RELAY_DELAYS 0,0
#define MULTI_RELAY_EXTERNALS false,true
#define MULTI_RELAY_INVERTS false,false
These can be set via your platformio_override.ini file or as #define in your my_config.h (remember to set WLED_USE_MY_CONFIG in your platformio_override.ini)
Usermod can be configured via the Usermods settings page.
enabled - enable/disable usermoduse-PCF8574 - use PCF8574 port expander instead of GPIO pinsfirst-PCF8574 - I2C address of first expander (WARNING: enter decimal value)broadcast- time in seconds between MQTT relay-state broadcastsHA-discovery- enable Home Assistant auto discoverypin - ESP GPIO pin the relay is connected to (can be configured at compile time -D MULTI_RELAY_PINS=xx,xx,...)delay-s - delay in seconds after on/off command is receivedactive-high - assign high/low activation of relay (can be used to reverse relay states)external - if enabled, WLED does not control relay, it can only be triggered by an external command (MQTT, HTTP, JSON or button)button - button (from LED Settings) that controls this relayIf there is no MultiRelay section, just save current configuration and re-open Usermods settings page.
Have fun - @blazoncek
2021-04
2021-11
2023-05
2023-11