Using a reed contact as ON/OFF Switch


I am new to WLED and I would like to build a cabinet light.
My WLED version 0.12.0 “Hikari”, build 2104020 runs on a Wemos D1 mini and a WS2812E, connected to GPIO2.
Everything is running as desired.
Now I want to switch WLED on and off via a reed relay (contact) as follows:

  • Door will be opened, reed contact will be opened → light should be switched on.
  • Door will be closed, reed contact will be closed → light should be switched off.

The reed contact is connected to GPIO0(zero) with a 10K pull-up resistor, as described in the Wiki under Macros and Buttons.

The wiki describes that 2 presets should be created, which are activated by Switch Low2High or Switch High2Low.

  • Preset 1 contains T=1
  • Preset 2 contains T=0

However, I do not know how to correctly assign the button states to the presets so that the light is switched as described above!

I have already tried to assign the presets Long and Short Clicks, but I can only switch on the light when closing the reed contact. Nothing happens when I open it.

Maybe someone can help me by posting a small tutorial.

Many thanks for your help

I think you want to set the pin mode to Switch Inverted. Assignments are done in Time & Macros and enter the preset numbers for the button states.

Hello tonyno,
thank you very much for your tip.

Unfortunately I have already tested this, but it does not lead to any solution.

I think the problem is that you can’t set button actions specifically for a static switch, as described in the wiki:

“For switch buttons you can only assign 2 presets, one for the switch transition from LOW to HIGH and the second for the reverse transition from HIGH to LOW. If you select 0 for the preset, the default action will be set. If you find that the default action for the switch is inverted, please create presets for the On and Off actions and assign them accordingly.”

For Alexa, yes, presets exist in the Time and Macro settings On/Off, but for buttons, only input options exist for Short Press, Long Press, and Double Press.

So the question is, where do you have to enter the presets for for ON (High2Low) and Off (Low2High) in the Time and Macros settings if you use a static switch (reed contact)???

Looking forward to your help

You need to get on a more recent build. :wink: Pick your bin file from here…

Hello tonyno,

have looked at WLED Wemos shield and already flashed on my Wemos D1 mini.

In the Sync Settings section is the solution, if I understand correctly.

  • Connect the reed contact to GPIO14 - D5 - IR receiver or optional button.
  • Sync Settings On/Off button enabled: true

I will try it out tonight.

In any case many many thanks for your help.

Many greetings

No, you need to set the input pin and mode in LED Preferences then enter your preset numbers in Time & Macros under Button actions.

Hello tonyno,

I just took the wrong firmware from WLED-wemos-shield: wemos_shield_esp8266.bin
Thera is no possiblity to define a GPIO Pin for the switch and configuer the Presets in Time&Macros.

Now I flashed the following firmware:
WLED 0.13.0-b2 “Toki” at Aircoookies Github

And what should I say, everything works fine :ok_hand: , just like you discribed it. :wave:

So once again

Thank you for your help

1 Like

BTW GPIO0 is not suitable for application of switches.
If your switch is in the wrong position and ESP reboots it will not start.

1 Like