1ecbaf2c7f
* Rawframe edit: * - TESTED ON WLED VS.0.10.1 - WHERE ONLY PRESET 16 SAVES SEGMENTS - some macros may not be needed if this changes. * - Code has been modified as my usage changed, as such it has poor use of functions vs if thens, but feel free to change it for me :) * * Edited to SWITCH between two lighting scenes/modes : STANDBY and HIGHLIGHT * * Usage: * - Standby is the default mode and Highlight is activated when the PIR detects activity. * - PIR delay now set to same value as Nightlight feature on boot but otherwise controlled as normal. * - Standby and Highlight brightness can be set on the fly (default values set on boot via macros calling presets). * - Macros are used to set Standby and Highlight states (macros can load saved presets etc). * * - Macro short button press = Highlight state default (used on boot only and sets default brightness). * - Macro double button press = Standby state default (used on boot only and sets default brightness). * - Macro long button press = Highlight state (after boot). * - Macro 16 = Standby state (after boot). * * ! It is advised not to set 'Apply preset at boot' or a boot macro (that activates a preset) as we will call our own macros on boot. * * - When the strip is off before PIR activates the strip will return to off for Standby mode, and vice versa. * - When the strip is turned off while in Highlight mode, it will return to standby mode. (This behaviour could be changed easily if for some reason you wanted the lights to go out when the pir is activated). * - Macros can be chained so you could do almost anything, such as have standby mode also turn on the nightlight function with a new time delay. * * Segment Notes: * - It's easier to save the segment selections in preset than apply via macro while we a limited to preset 16. (Ie, instead of selecting sections at the point of activating standby/highlight modes). * - Because only preset 16 saves segments, for now we are having to use additional macros to control segments where they are involved. Macros can be chained so this works but it would be better if macros also accepted json-api commands. (Testing http api segment behaviour of SS with SB left me a little confused). * * Future: * - Maybe a second timer/timetable that turns on/off standby mode also after set inactivity period / date & times. For now this can be achieved others ways so may not be worth eating more processing power. |
||
---|---|---|
.. | ||
PIR_Highlight_Standby | ||
readme.md | ||
usermod_PIR_sensor_switch.h |
PIR sensor switch
This usermod-v2 modification allows the connection of a PIR sensor to switch on the LED strip when motion is detected. The switch-off occurs ten minutes after no more motion is detected.
Story:
I use the PIR Sensor to automatically turn on the WLED analog clock in my home office room when I am there. The LED strip is switched using a relay to keep the power consumption low when it is switched off.
Webinterface
The info page in the web interface shows the items below
- the state of the sensor. By clicking on the state the sensor can be deactivated/activated. I recommend to deactivate the sensor before installing an OTA update.
- the remaining time of the off timer.
JSON API
The usermod supports the following state changes:
JSON key | Value range | Description |
---|---|---|
PIRenabled | bool | Deactivdate/activate the sensor |
PIRoffSec | 60 to 43200 | Off timer seconds |
Sensor connection
My setup uses an HC-SR501 sensor, a HC-SR505 should also work.
The usermod uses GPIO13 (D1 mini pin D7) for the sensor signal. This example page describes how to connect the sensor.
Use the potentiometers on the sensor to set the time-delay to the minimum and the sensitivity to about half, or slightly above.
Usermod installation
- Copy the file
usermod_PIR_sensor_switch.h
to thewled00
directory. - Register the usermod by adding
#include "usermod_PIR_sensor_switch.h"
in the top andregisterUsermod(new PIRsensorSwitch());
in the bottom ofusermods_list.cpp
.
Example usermods_list.cpp:
#include "wled.h"
/*
* Register your v2 usermods here!
* (for v1 usermods using just usermod.cpp, you can ignore this file)
*/
/*
* Add/uncomment your usermod filename here (and once more below)
* || || ||
* \/ \/ \/
*/
//#include "usermod_v2_example.h"
//#include "usermod_temperature.h"
//#include "usermod_v2_empty.h"
#include "usermod_PIR_sensor_switch.h"
void registerUsermods()
{
/*
* Add your usermod class name here
* || || ||
* \/ \/ \/
*/
//usermods.add(new MyExampleUsermod());
//usermods.add(new UsermodTemperature());
//usermods.add(new UsermodRenameMe());
usermods.add(new PIRsensorSwitch());
}
Have fun - @gegu