WLED and external input device(s)

Created on 23 Sep 2019  路  18Comments  路  Source: Aircoookie/WLED

I am working on a project to illuminate a dark stairway with a smart LED strip, custom effect(s), using 2 motion sensors to trigger the LED strip in forward or reverse.
This seems like a common enough problem to trigger the LED strip based on motion or button, or some sensor wired to the same ESP.
What is already supported in WLED and what would need to be in the custom portions to do something like this?
I read through all issues, the wiki, and guides and if it's already there, sorry, but I missed it.

stale

Most helpful comment

However, simple motion sensors with a configurable timeout might be a widespread enough use case for me to offer built-in support at some point.

All 18 comments

Hi!
Right now the only input device types supported by WLED are a simple pushbutton and infrared.
Supporting more sensors is outside the scope of the project for now as the requirements of most people are to specific for one generic implementation. (What sensor model? What should it do? When will it turn off again? What activation threshold? What pinout? and so on...)

There are two suggestions I have for you:

  1. You could use a different sensor and a home automation platform or similar solution. This is more advanced and configurable, but probably overkill for your and many other's needs.
  1. Code the desired behavior yourself in the wled06_usermod.ino file. For addressing the sensor, just doing the same as in a simple sensor example sketch should work. Interfacing to WLED is a bit more arbitrary, a few details are on this page: https://github.com/Aircoookie/WLED/wiki/Add-own-functionality . I should really improve upon and document the internal API so that you can modify the code to your needs more easily :)
    The steps you'd need to take is to read the data from the sensor and trigger a certain effect (you could use Wipe and see how long it takes to fill the strip, after that switch to solid, then turn off after 1-2 minutes)

However, simple motion sensors with a configurable timeout might be a widespread enough use case for me to offer built-in support at some point.

A motion sensor will be a good addition, I use the wled for all my ledstrip lights in my house and I don't have them connected all the time to the internet, I use the Infrared remote and the button to open the lights, and a motion sensor will be a more useful trigger, this can be used for automation sistem to, if you can publish the trigger to home assistant or some other automation I think.

A motion sensor will be a good addition, ... or some other automation I think.

Just wondering: wouldn't adding a motion sensor to WLED make WLED more like a home automation system? People using WLED could also tie in a/the motion sensor into a home automation solution, in which WLED is also integrated, make a rule (in the home automation solution) triggering WLED when a the motion sensor is triggered?

But if @Aircoookie is willing to add it to WLED at one point: no problem of course.

I think the motion sensor will be more useful in home automation if you have more wled setups with motion sensor you could se were it's movement and start an automated scene close the door or opens the blinds start the music etc.

Even though my original request was very specific, I was thinking about many other use-cases, such as "welcome home" and under-cabinet WLED-controlled LED strips. Sure under-cabinet addressable LEDs is not the standard go-to, but with the SYNC capability, it seems like it could take ordinary boring under-cabinet LED lighting to the next level and beyond from a WOW factor perspective.

You know, seeing the under cabinet lighting dancing in precisely the same way as other WLED strips sync'd up.

Begs the question, are there multiple SYNC channels available? I see grouping WLED ESPs with different UDP sync ports is the answer to that.

Has anyone got any further with integrating a PIR directly into a WLED ESP? Wouldn't this be as simple as having a GPIO pin monitor?

Simple approach, just use ESPHome with another ESP device. it has built-in support for a number of PIR devices and you can sync it directly with WLED via MQTT. Just takes a slight bit of extra money for the second ESP.
Slightly harder would be the usermod.ino. It's not too hard to find examples you can use for a starting point and building WLED on your own is also not too difficult. More research & time than an ESPHome build, though.

Yea I did think about having a second device to control the PIR sensors, wouldn't I need a MQTT broker running to do this though?

for MQTT yes, but a pi will run mosquitto easily enough. ESPhome also has capability to easily create a gpio or relay output, which then could be connected as the "button" input to WLED. It may also be possible to add a simple lambda into the ESPhome config that makes an API call directly to the WLED web ui.

Personally, I just pulled the code and make my own changes. I have some experience with coding so that helped. WLED does build somehwhat easily with a number of tools (I'm using vscode). Just took some setup time and some edits of the platformio.ini file). I don't think it's the preferred build environment, however, as it does mysteriously fail sometimes for no clear reason. but, it just takes a few more clicks to try again so that's good enough for my needs.

I am interested about this subject... if you have a user mode for this please post it. Thanks

I'd also be very interested in this as I want to do exactly the same thig the OP wants to

Has anyone got any further with integrating a PIR directly into a WLED ESP? Wouldn't this be as simple as having a GPIO pin monitor?

SOLVED
Firstly a big thumbs up to Aircookie!!

Motion sensor : hc-sr501 (5v input, 3.3v output, adjustable sensitivity and duration).
Set the jumpers to single trigger and the running time to minimum to imitate a button press. Depending on the adjust-ability of the motion sensor you may be able to fine tune the button press down to short or long press despite the datasheet claiming 5s min. For my purposes I set the wled short and long button press to point to the same macro.
WLED sets gpio0 (wled00wled09_button.ino) to High and so when a normal button press is triggered the gpio0 reads as 'low' (wled00wled09_button.ino). So to make the motion sensor work directly you would need the opposite to happen, ie. default/start gpio0 Low and detect button press by reading High. This is fine if you you want to change the code every time you update the software but that seems like too much effort long run. I would hope in the future that Aircookie integrates the same button press code in reverse on another gpio pin so that any motion etc sensor can direct trigger macros via high input; avoiding the extra circuitry below.

So in the meantime the easiest solution is to introduce a relay in the form of a pn2222 npn transistor which costs very little. Connect the collector pin to the gpio0, emitter pin to the ground pin, and the base pin to the motion sensor control pin.
This works but to avoid possible shorts, have more stable pin values and waste less power, it is recommended to use pull up resistors though this is not really necessary if the pin coding makes use of the internal gpio pullup resistors. However, if in doubt you can add a 0.22k resistor between base pin and control pin, and a 10k resistor between gpio0 and the collector pin (though for me the 10k resistor had to be swapped to around 0.5k to work).

Now my lights come on when motion is detected and turn of after a set time period (motion sensor simulating a button press detection and activating a corresponding macro :)

These are not recommendations and its at your own risk if your try them. :)

I am interested in this subject to !

@rawframe Awesome, thank you for sharing how you got it to work!
I believe I will add an option to invert the button logic level soon, which would eliminate the need for additional hardware :)
Have a great start into the new decade!

Hey! This issue has been open for quite some time without any new comments now. It will be closed automatically in a week if no further activity occurs.
Thank you for using WLED!

@Aircoookie I'd really like more info on this if it exists. I already have MQTT running another project via Node-Red and am trying to trigger my LEDs using a motion sensor on a D1 mini loaded with your fabulous WLED!

I sent you an email, but I am also interested in triggering a 'scene' in WLED, according to a GPIO input. Not new at coding, just new at arduino/esp32. I am looking to say activate a chase scene in RED when GPIO 4 is high, GREEN when 5 is high...etc. Thank you, and I love WLED and all it functionality. I wish this was built-in, but it also gives me the opportunity to learn some more coding!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

djhampson picture djhampson  路  3Comments

Legsmaniac picture Legsmaniac  路  3Comments

fribse picture fribse  路  4Comments

exeljb picture exeljb  路  4Comments

ArJay60 picture ArJay60  路  3Comments