# Multi-relay usermod JSON API

**URL:** <https://wled.discourse.group/t/multi-relay-usermod-json-api/12991>\
**Category:** Uncategorized\
**Created:** [October 18, 2024, 6:34pm UTC](https://wled.discourse.group/t/multi-relay-usermod-json-api/12991 "2024-10-18T18:34:57Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![DamianPe](https://yyz2.discourse-cdn.com/free1/user_avatar/wled.discourse.group/damianpe/32/6901_2.png) [@DamianPe](https://wled.discourse.group/u/DamianPe)\
**Post date:** [October 18, 2024, 6:34pm UTC](https://wled.discourse.group/t/multi-relay-usermod-json-api/12991/1 "2024-10-18T18:34:57Z")

</div>

Hi,  
I’m trying to use Multirelay usermod in my WLED project however I encountered a problem. I’d like to use preset with JSON API commands. There is a command to turn particular relay on and off but I cannot find any command to TOGGLE a relay. There are toggle commands in HTTP API and in MQTT. Is it somehow included in JSON API? I tried several ideas but no success…

---

<div class="post-metadata">

**Author:** ![ALDIY](https://yyz2.discourse-cdn.com/free1/user_avatar/wled.discourse.group/aldiy/32/2716_2.png) [@ALDIY](https://wled.discourse.group/u/ALDIY)\
**Post date:** [October 18, 2024, 6:44pm UTC](https://wled.discourse.group/t/multi-relay-usermod-json-api/12991/2 "2024-10-18T18:44:58Z")

</div>

This is an example i tested a long time ago

```auto
curl -X POST "http://10.0.6.17/json/state" -d {"MultiRelay":{"relay":0,"on":true}} -H "Content-Type: application/json"
curl -X POST "http://10.0.6.17/json/state" -d {"MultiRelay":{"relay":0,"on":false}} -H "Content-Type: application/json"

```

![image](https://global.discourse-cdn.com/free1/uploads/wled/original/2X/3/35612302d99c89cea62252719d0b567ca3f280f5.png)

Please try with `{"on":"t"} `if that works for you as I no longer have the usermod nor i use it but was just testing it with another user

---

<div class="post-metadata">

**Author:** ![DamianPe](https://yyz2.discourse-cdn.com/free1/user_avatar/wled.discourse.group/damianpe/32/6901_2.png) [@DamianPe](https://wled.discourse.group/u/DamianPe)\
**Post date:** [October 18, 2024, 6:56pm UTC](https://wled.discourse.group/t/multi-relay-usermod-json-api/12991/3 "2024-10-18T18:56:08Z")

</div>

Works like a charm, thanks a lot!  
I wouldn’t think about that syntax 🙂

---

<div class="post-metadata">

**Author:** ![ALDIY](https://yyz2.discourse-cdn.com/free1/user_avatar/wled.discourse.group/aldiy/32/2716_2.png) [@ALDIY](https://wled.discourse.group/u/ALDIY)\
**Post date:** [October 18, 2024, 7:15pm UTC](https://wled.discourse.group/t/multi-relay-usermod-json-api/12991/4 "2024-10-18T19:15:04Z")

</div>

Good , Might help the next guy if you could show the outcome of your toggle api but not mandatory just to pay it foreword 😉

---

<div class="post-metadata">

**Author:** ![DamianPe](https://yyz2.discourse-cdn.com/free1/user_avatar/wled.discourse.group/damianpe/32/6901_2.png) [@DamianPe](https://wled.discourse.group/u/DamianPe)\
**Post date:** [October 31, 2024, 12:58pm UTC](https://wled.discourse.group/t/multi-relay-usermod-json-api/12991/5 "2024-10-31T12:58:42Z")

</div>

Hi ALDIY,

I wish I could but multirelay usermod behaves in a strange way.  
Generally let’s say that I have 2 presets. They are triggered by 2 physical pushbuttons. Each of them shall (apart of other things) switch state of one of lines defined by multirelay. This works fine. There is also a third preset used to switch WLED on and off (just like power icon in top left corner. Preset needs to be defined as `{"on":"t"}` - it triggers “built-in” relay functionality but it also triggers both multirelays which spoils all the logic.  
Have I messed up my configuration or this is how multirelay add-on works that main power button affects it too?

---

<div class="post-metadata">

**Author:** ![ALDIY](https://yyz2.discourse-cdn.com/free1/user_avatar/wled.discourse.group/aldiy/32/2716_2.png) [@ALDIY](https://wled.discourse.group/u/ALDIY)\
**Post date:** [October 31, 2024, 2:06pm UTC](https://wled.discourse.group/t/multi-relay-usermod-json-api/12991/6 "2024-10-31T14:06:05Z")

</div>

I did not test buttons thoroughly and do not have any wired with wled but in the usermod there is “external” option might be try to change and test . If you face more issues then make sure you are on latest 15.0.B6 or B7 and then provide the configuration and presets you have and I will try to replicate your setup and see the interaction with button , of/off …etc  
As said also I do not use a physical relay with wled but only test the behavior and response from mqtt but could also test with a physical relay if needed the same way you did

---

<div class="post-metadata">

**Author:** ![DamianPe](https://yyz2.discourse-cdn.com/free1/user_avatar/wled.discourse.group/damianpe/32/6901_2.png) [@DamianPe](https://wled.discourse.group/u/DamianPe)\
**Post date:** [November 1, 2024, 7:10am UTC](https://wled.discourse.group/t/multi-relay-usermod-json-api/12991/7 "2024-11-01T07:10:55Z")

</div>

Hi.  
My hardware setup is as following:  
Two LED stripes connected to GPIO26 and GPIO27.  
Two pushbuttons connected to GPIO13 and GPIO12.  
(temporarly) Build in relay output connected to GPIO15 to control PSU enable input.  
(temporarly) 4 LEDs as multirelay outputs co1. nnected between GND and GPIOs: 16, 17, 18, 19.

1. Settings:
2. Short button press of Button 1 triggers Preset 1 , double triggers Preset 3  
Short button press of Button 2 triggers Preset 2 , double triggers Preset 3  
Multirelay 0 and 1 have no delay, multirelay 2 and 3 have 5s of delay

Presets:  
1:  
`{"seg":[{"id":0,"on":"t"}],"MultiRelay":[{"relay":0,"on":"t"},{"relay":2,"on":"t"}]}`  
2:  
`{"MultiRelay":[{"relay":1,"on":"t"},{"relay":3,"on":"t"}],"seg":[{"id":1,"on":"t"}]}`  
3:  
`{"on":"t"}`

WLED was compiled from github latest source version but I can see it is 0.14.4, not the one you mention.

As I am playing with WLED while writing that, I noticed that physical buttons are not necessary. What happens is:  
I begin with “standby state”, meaning WLED is off (meaning power icon is not highlided, PSU controlled by relay is off, multirelay LEDs are off).  
I run Preset 3 or click Power icon, PSU turns on but at the same time, relay-0 and relay-2 turn on, 5 seconds later relay-1 and relay-3 turn on. This is not what I was expecting as there was no command to turn them on.  
When I run Preset 3 again, PUS turns off, as well as relay-0 and 2, 5s later the same happens with relay-1 and 3.  
Now, never mind if PSU is on or off, I try to run i.e. Preset 1 (Preset 2 behaves in the same way): when I run it, both relay-0 and relay-2 turn on or off at the same time. There is no delay as intended…

In general, what I’d like to achieve?  
My setup is as below: 2 led stripes with 2 buttons to control them separately and PSU controlled from ESP32

 ![image](https://global.discourse-cdn.com/free1/uploads/wled/original/2X/9/971f1f20362396372cc56337e3e71470546479e6.jpeg)  
I don’t like t o perform any specific action to control PSU (like my Preset 3 just to turn it on and off). If any of stripes should be turned on, PSU shall be turned on too, if none of them is lit, PSU shall turn off. That simple. I was advised to use multirelay and a piece of hardware like OR gate and set everything up so multirelay state shows if stripe is on or off.

---

<div class="post-metadata">

**Author:** ![ALDIY](https://yyz2.discourse-cdn.com/free1/user_avatar/wled.discourse.group/aldiy/32/2716_2.png) [@ALDIY](https://wled.discourse.group/u/ALDIY)\
**Post date:** [November 1, 2024, 9:37am UTC](https://wled.discourse.group/t/multi-relay-usermod-json-api/12991/8 "2024-11-01T09:37:29Z")

</div>

In the usermod there is “external” option which i tested now and it will solve the issue you listed earlier as if you check that then wled ui power button will not trigger the relay . try that first .  
Info on that is here [WLED/usermods/multi\_relay at 0\_15 · Aircoookie/WLED · GitHub](https://github.com/Aircoookie/WLED/tree/0_15/usermods/multi_relay)  
Also 15.0.B6 source is here [GitHub - Aircoookie/WLED at 0\_15](https://github.com/Aircoookie/WLED/tree/0_15)  
Bins are here [Releases · Aircoookie/WLED · GitHub](https://github.com/Aircoookie/WLED/releases)  
And the last CI run bins are here [Merge pull request #4231 from Aircoookie/b7 · Aircoookie/WLED@af34da4 · GitHub](https://github.com/Aircoookie/WLED/actions/runs/11601551622/job/32304569608)

---

<div class="post-metadata">

**Author:** ![DamianPe](https://yyz2.discourse-cdn.com/free1/user_avatar/wled.discourse.group/damianpe/32/6901_2.png) [@DamianPe](https://wled.discourse.group/u/DamianPe)\
**Post date:** [November 1, 2024, 4:21pm UTC](https://wled.discourse.group/t/multi-relay-usermod-json-api/12991/9 "2024-11-01T16:21:57Z")

</div>

Thanks, I changed settings to ‘external’, works better but still there is no delay, which is also important for me. While switching off I have ‘fade off’ effect so triggering Preset 1 or 2 starts fading but without delay it would instantly switch PSU (this is why am using 2 outputs for stripe - the one without delay is to turn PSU immediatelly and with delay is to allow fade out to finish).  
Is it corrected in latest version, please?

---

<div class="post-metadata">

**Author:** ![ALDIY](https://yyz2.discourse-cdn.com/free1/user_avatar/wled.discourse.group/aldiy/32/2716_2.png) [@ALDIY](https://wled.discourse.group/u/ALDIY)\
**Post date:** [November 1, 2024, 11:09pm UTC](https://wled.discourse.group/t/multi-relay-usermod-json-api/12991/10 "2024-11-01T23:09:56Z")

</div>

Possibly a bug , i have now also used a relay and when I set the " delay-s" in the usermod I do not see any change and it will still trigger without a delay when the api is used from MQTT .  
Try to to test on B7 and if you still face an issue then file a bug in github here

> **[Issues · Aircoookie/WLED](https://github.com/Aircoookie/WLED/issues)**
>
> Control WS2812B and many more types of digital RGB LEDs with an ESP8266 or ESP32 over WiFi! - Issues · Aircoookie/WLED

---

<div class="post-metadata">

**Author:** ![ALDIY](https://yyz2.discourse-cdn.com/free1/user_avatar/wled.discourse.group/aldiy/32/2716_2.png) [@ALDIY](https://wled.discourse.group/u/ALDIY)\
**Post date:** [November 1, 2024, 11:25pm UTC](https://wled.discourse.group/t/multi-relay-usermod-json-api/12991/11 "2024-11-01T23:25:05Z")

</div>

This might be related to the same issue

> <https://github.com/Aircoookie/WLED/issues/4207>
>
> \### What happened?
> 
> When having a button action on the BTN 0 and 1 the action is… not instant than 2,3.
> 
> \### To Reproduce Bug
> 
> Set a push button for the 1.
> Configure a relay for the button 1.
> Press one time the button.
> 
> \### Expected Behavior
> 
> The reaction of the relay should be instant like the button 2 and 3.
> 
> \### Install Method
> 
> Binary from WLED.me
> 
> \### What version of WLED?
> 
> 0.14.4, 0.15.0-b6
> 
> \### Which microcontroller/board are you seeing the problem on?
> 
> ESP32
> 
> \### Relevant log/trace output
> 
> \_No response\_
> 
> \### Anything else?
> 
> \_No response\_
> 
> \### Code of Conduct
> 
> \- \[X\] I agree to follow this project's Code of Conduct

---

<div class="post-metadata">

**Author:** ![DamianPe](https://yyz2.discourse-cdn.com/free1/user_avatar/wled.discourse.group/damianpe/32/6901_2.png) [@DamianPe](https://wled.discourse.group/u/DamianPe)\
**Post date:** [November 2, 2024, 9:20am UTC](https://wled.discourse.group/t/multi-relay-usermod-json-api/12991/12 "2024-11-02T09:20:11Z")

</div>

I tried to compile B7 from source [GitHub - Aircoookie/WLED at 0\_15](https://github.com/Aircoookie/WLED/tree/0_15) on my machine but no go, the compilator complains about missing files: `wled00/wled_server.cpp:3:21: fatal error: html_ui.h: No such file or directory`…

---

<div class="post-metadata">

**Author:** ![ALDIY](https://yyz2.discourse-cdn.com/free1/user_avatar/wled.discourse.group/aldiy/32/2716_2.png) [@ALDIY](https://wled.discourse.group/u/ALDIY)\
**Post date:** [November 2, 2024, 2:57pm UTC](https://wled.discourse.group/t/multi-relay-usermod-json-api/12991/13 "2024-11-02T14:57:51Z")

</div>

B7 is already on the release page but the delay-s is also ignored in that build .  
You might want to start compiling on github , use this helper tool [WLED Compile helper](https://wled-compile.github.io/) or if you must use local vsc then update it
