# PIR sensor working on specific hours

**URL:** <https://wled.discourse.group/t/pir-sensor-working-on-specific-hours/9173>\
**Category:** Questions\
**Created:** [September 9, 2023, 8:19pm UTC](https://wled.discourse.group/t/pir-sensor-working-on-specific-hours/9173 "2023-09-09T20:19:22Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![wmk8](https://avatars.discourse-cdn.com/v4/letter/w/a9a28c/32.png) [@wmk8](https://wled.discourse.group/u/wmk8)\
**Post date:** [September 9, 2023, 8:19pm UTC](https://wled.discourse.group/t/pir-sensor-working-on-specific-hours/9173/1 "2023-09-09T20:19:23Z")

</div>

Hello everyone. I do have a question. Is it possible to run PIR only on specific hours? Like “Nighttime only” function on fixed hours. Thank you for Your help.

---

<div class="post-metadata">

**Author:** ![dherkes](https://yyz2.discourse-cdn.com/free1/user_avatar/wled.discourse.group/dherkes/32/797_2.png) [@dherkes](https://wled.discourse.group/u/dherkes)\
**Post date:** [September 10, 2023, 8:54pm UTC](https://wled.discourse.group/t/pir-sensor-working-on-specific-hours/9173/2 "2023-09-10T20:54:58Z")

</div>

Yes, but I use the Home Assistant program to control the PIR.

---

<div class="post-metadata">

**Author:** ![blazoncek](https://yyz2.discourse-cdn.com/free1/user_avatar/wled.discourse.group/blazoncek/32/1886_2.png) [@blazoncek](https://wled.discourse.group/u/blazoncek)\
**Post date:** [September 11, 2023, 4:54am UTC](https://wled.discourse.group/t/pir-sensor-working-on-specific-hours/9173/3 "2023-09-11T04:54:30Z")

</div>

Yes.  
You can schedule presets with on and off for PIR sensor.  
`{"PIRsensorSwitch":{"PIRenabled":true}}` for on and `{"PIRsensorSwitch":{"PIRenabled":false}}` for off.

---

<div class="post-metadata">

**Author:** ![wmk8](https://avatars.discourse-cdn.com/v4/letter/w/a9a28c/32.png) [@wmk8](https://wled.discourse.group/u/wmk8)\
**Post date:** [September 12, 2023, 5:01pm UTC](https://wled.discourse.group/t/pir-sensor-working-on-specific-hours/9173/4 "2023-09-12T17:01:22Z")

</div>

It works. Thank you.

---

<div class="post-metadata">

**Author:** ![blazoncek](https://yyz2.discourse-cdn.com/free1/user_avatar/wled.discourse.group/blazoncek/32/1886_2.png) [@blazoncek](https://wled.discourse.group/u/blazoncek)\
**Post date:** [September 12, 2023, 6:47pm UTC](https://wled.discourse.group/t/pir-sensor-working-on-specific-hours/9173/5 "2023-09-12T18:47:29Z")

</div>

I know. I wrote the code. 🤣

---

<div class="post-metadata">

**Author:** ![WolfgangHusen](https://yyz2.discourse-cdn.com/free1/user_avatar/wled.discourse.group/wolfganghusen/32/5844_2.png) [@WolfgangHusen](https://wled.discourse.group/u/WolfgangHusen)\
**Post date:** [September 28, 2023, 3:20pm UTC](https://wled.discourse.group/t/pir-sensor-working-on-specific-hours/9173/6 "2023-09-28T15:20:58Z")

</div>

Hi guys,

this was exactly what I was looking for. But even though I (think I) followed the instruction, it doesnt work for me.

My setup:

- I am running WLED, version 0.14.0-b6, on a ESP8266.
- I configured a PIR under LED & Hardware setup: Button 0 GPIO=5, PIR sensor
- for PIR activation I did: Button action: Button 0, long off-\>on: “preset to switch on”

So far so good and it works. But the de-activation as shown by @blazoncek does not work.

- i added a preset to enable and a similar one (with a “false”) to disable:  
 ![grafik](https://global.discourse-cdn.com/free1/uploads/wled/original/2X/6/6eb61127e71ab20958deece73d17a87c5eec46a3.png)

But even though i activate the Preset to disable (directly via WLED Browser UI - or via HomeAssistant, calling the preset) → the PIR is always enabled.

Any ideas are welcomed!  
Thanks,  
Wolfgang

---

<div class="post-metadata">

**Author:** ![divsys](https://avatars.discourse-cdn.com/v4/letter/d/a3d4f5/32.png) [@divsys](https://wled.discourse.group/u/divsys)\
**Post date:** [September 28, 2023, 3:32pm UTC](https://wled.discourse.group/t/pir-sensor-working-on-specific-hours/9173/7 "2023-09-28T15:32:43Z")

</div>

Post your preset for “PIR Off”, showing the API content.

---

<div class="post-metadata">

**Author:** ![WolfgangHusen](https://yyz2.discourse-cdn.com/free1/user_avatar/wled.discourse.group/wolfganghusen/32/5844_2.png) [@WolfgangHusen](https://wled.discourse.group/u/WolfgangHusen)\
**Post date:** [September 28, 2023, 4:42pm UTC](https://wled.discourse.group/t/pir-sensor-working-on-specific-hours/9173/8 "2023-09-28T16:42:04Z")

</div>

there you go:  
 ![grafik](https://global.discourse-cdn.com/free1/uploads/wled/original/2X/7/7f9fa88b11a4d63ec13d6533db411594f83fb633.png)

---

<div class="post-metadata">

**Author:** ![blazoncek](https://yyz2.discourse-cdn.com/free1/user_avatar/wled.discourse.group/blazoncek/32/1886_2.png) [@blazoncek](https://wled.discourse.group/u/blazoncek)\
**Post date:** [September 29, 2023, 6:09am UTC](https://wled.discourse.group/t/pir-sensor-working-on-specific-hours/9173/9 "2023-09-29T06:09:46Z")

</div>

The API above only works for PIR sensor usermod, not if you use “buttons”.

---

<div class="post-metadata">

**Author:** ![WolfgangHusen](https://yyz2.discourse-cdn.com/free1/user_avatar/wled.discourse.group/wolfganghusen/32/5844_2.png) [@WolfgangHusen](https://wled.discourse.group/u/WolfgangHusen)\
**Post date:** [September 29, 2023, 11:07am UTC](https://wled.discourse.group/t/pir-sensor-working-on-specific-hours/9173/10 "2023-09-29T11:07:48Z")

</div>

Thanks for clarification.

---

<div class="post-metadata">

**Author:** ![kancleris](https://yyz2.discourse-cdn.com/free1/user_avatar/wled.discourse.group/kancleris/32/7326_2.png) [@kancleris](https://wled.discourse.group/u/kancleris)\
**Post date:** [March 9, 2024, 9:23pm UTC](https://wled.discourse.group/t/pir-sensor-working-on-specific-hours/9173/11 "2024-03-09T21:23:49Z")

</div>

Is there a solution to control these buttons state without using pir switch usermode?  
Maybe with some direct settings links?  
I have already programmed sensors logic with Arduino Nano and I am looking for preset, controlling PIR states in HA as switch.

---

<div class="post-metadata">

**Author:** ![monk5584](https://avatars.discourse-cdn.com/v4/letter/m/9fc29f/32.png) [@monk5584](https://wled.discourse.group/u/monk5584)\
**Post date:** [August 19, 2024, 1:16pm UTC](https://wled.discourse.group/t/pir-sensor-working-on-specific-hours/9173/12 "2024-08-19T13:16:14Z")

</div>

This doesn’t make sense to me. Is this done utilizing a Playlist? Currently I have two PIR sensors for my stairs and they work excellent to turn on the Playlist I have set, but I’m looking for a way I can turn the PIR sensors off during the day. Or is there a way I can schedule different Playlist to trigger from the PIR sensors at specified times? (I. E. Effect #1 during day and effect #2 at night). I’m new at this so I haven’t ventured into usermods or home assistant. Seems like usermods require a little bit of coding which is why I haven’t gone that route and home assistant I haven’t used bc wled so far has been so easy with the app. Looking for advice for turning the pir sensors on and off. Otherwise I can set a preset to come on at 6pm and it will, but as soon as someone walks by the sensor to go upstairs or downstairs it runs the effect and turns everything off since the pir overrides everything else.

---

<div class="post-metadata">

**Author:** ![divsys](https://avatars.discourse-cdn.com/v4/letter/d/a3d4f5/32.png) [@divsys](https://wled.discourse.group/u/divsys)\
**Post date:** [August 19, 2024, 7:13pm UTC](https://wled.discourse.group/t/pir-sensor-working-on-specific-hours/9173/13 "2024-08-19T19:13:22Z")

</div>

The use of “PIR sensor” as a button type enables a few different JSON API controls.

These are part of the PIR-Usermod, so you have to compile that in yourself or check one of the repositories that include various mods (try: [Serg Builds](https://github.com/srg74/WLED-wemos-shield/tree/master/resources/Firmware/@Aircoookie/Latest) )

This will allow you to use a PIR sensor like a switch to fire presets. With the API enable/disable you can turn the PIR sensor on and off via a Sunrise/Sunset preset or via some other system. This “turns off the stair lights in daytime” or similar features.  
Going further to use a different PIR-fired preset for different times of day is beyond the scope of the current WLED environment.

You can either do some coding of your own to modfy the current usermod, or try and integrate in something like Home Assistant to handle the controls outside of WLED.

PS: If you want to explore this further on the forum, it would be a good idea to repost this in your own topic so we don’t extend a (mostly) completed thread unnecessarily. 😉

---

<div class="post-metadata">

**Author:** ![monk5584](https://avatars.discourse-cdn.com/v4/letter/m/9fc29f/32.png) [@monk5584](https://wled.discourse.group/u/monk5584)\
**Post date:** [August 19, 2024, 9:14pm UTC](https://wled.discourse.group/t/pir-sensor-working-on-specific-hours/9173/14 "2024-08-19T21:14:32Z")

</div>

My apologies. In looking for answers I thought it would be better to repost in the same thread so we didn’t have multiple threads around the same issue, but I understand where you are coming from. It sounds like I may need to look Into using home assistant or possibly a user mod with some coding. I appreciate your support in responding to my question.
