Control LED strip by PIR sensor (with timer function?)

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
Cheaps
Normal user
Posts: 10
Joined: 25 Nov 2017, 19:56

Control LED strip by PIR sensor (with timer function?)

#1 Post by Cheaps » 22 Jan 2018, 16:23

I'm busy with an ESP easy project in my bathroom. I have a small LED strip (powered by GPIO 5, 3.3 volt from the NodeMCU). I want the following result: If the PIR sensor is positive, I want to have the LED strip lit-up for 1 or 2 minutes. I use a PIR sensor without delay on it (self-delay is 2 seconds frome the PIR sensor itself)

https://www.ebay.com/itm/Mini-IR-Infrar ... 2204291166


I already tried a lot of things, but it's quite annoying to configure it well!

The current ESP easy configuration:
Image

The current Domoticz configuration:

Image

I already have tried to set the off delay in Domoticz on 120 seconds, but because my ESP easy already gives the off status at the same time as the on status is triggered, the LED is turning into a disco light!

I also tried to control it via a Domoticz event
Image

And it also doesn't really work (becaus I entered the value of 20.000 in the URL to open, there is a quite 'long' delay, but it's not the 40 seconds. The logic of the 'wait' command doesn't really make sense.

I think this should be

kimot
Normal user
Posts: 190
Joined: 12 Oct 2017, 20:46

Re: Control LED strip by PIR sensor (with timer function?)

#2 Post by kimot » 25 Jan 2018, 10:11

Why using Domoticz fot this task?
Simply use rules on your ESPeasy.
It works then without Domoticz.

If PIR sensor triggers, set gpio pin for your LEDs on and set Timer1 to 120sec.
And On Timer1 event set gpio pin for your LEDs off.

Or if your PIR and LEDs are on different ESPEasys, send command directly between this units - again without Domoticz.
Instead PIR trigger in the example above use event trigger from incoming command.
And then you can report state of PIR and LED to Domoticz, if you need it.
Advantage - this way it will work even if Domoticz or your controller computer crashes.

https://www.letscontrolit.com/wiki/inde ... rial_Rules

User avatar
toffel969
Normal user
Posts: 469
Joined: 03 Jan 2017, 10:58
Location: Germany

Re: Control LED strip by PIR sensor (with timer function?)

#3 Post by toffel969 » 25 Jan 2018, 11:41

kimot wrote: 25 Jan 2018, 10:11 Why using Domoticz fot this task?
Simply use rules on your ESPeasy.
It works then without Domoticz.

If PIR sensor triggers, set gpio pin for your LEDs on and set Timer1 to 120sec.
And On Timer1 event set gpio pin for your LEDs off.

Or if your PIR and LEDs are on different ESPEasys, send command directly between this units - again without Domoticz.
Instead PIR trigger in the example above use event trigger from incoming command.
And then you can report state of PIR and LED to Domoticz, if you need it.
Advantage - this way it will work even if Domoticz or your controller computer crashes.

https://www.letscontrolit.com/wiki/inde ... rial_Rules
What you actually want in this kind of setup is: When PIR sees movement light up the LED. When it hasn't seen movement for 90 sec, switch the LED off. Right?
I agree, this need to be done in rules, not Domoticz (its actually not possible). Activate rules under the advanced tab. Then write a rule with a timer. Setup the PIR as switch input, named PIR.

a rule for that will look something like that :

Code: Select all

On PIR#switch=1 do 
gpio,5,1
timerset,1,90
Endon

On Rules#Timer=1 do 
gpio,5,0
Endon
Domoticz on Raspi 2 -- 14 ESP units (hacked Sonoff,NodeMCUs, Wemos, self-built units) running with RC140- Mega 2.0.0 dev8

Cheaps
Normal user
Posts: 10
Joined: 25 Nov 2017, 19:56

Re: Control LED strip by PIR sensor (with timer function?)

#4 Post by Cheaps » 25 Jan 2018, 19:56

Thank you very much for your help! I'm not a hardcore programmer, so it's all quite difficult for me, sorry for that!
I tried to setup the rule with the same rule as you said above, and I see in the logging the following:

Image

I see that the event is triggered, but I don't see the action (set GPIO 5 to 1, or to 1000, I've also tried that...)

Note: the PIR sensor is really quick in the off-state, so after 1 or 2 seconds it already give the status '0' .

I also tried only the above script

Code: Select all

On PIR#switch=1 do 
gpio,5,1
timerset,1,90
Endon
But it also doesn't give any results.


Edit: I finally got it, with the following code.

Code: Select all

On PIR#switch=1 do 
 PWM,5,1000,200
 timerset,1,90
Endon

On Rules#Timer=1 do 
PWM,5,0,200
Endon
The thing I forgot was the 'value' from device, to set it as 'switch' ! See the picture here:
Image

Thanks everyone!

User avatar
grovkillen
Core team member
Posts: 3621
Joined: 19 Jan 2017, 12:56
Location: Hudiksvall, Sweden
Contact:

Re: Control LED strip by PIR sensor (with timer function?)

#5 Post by grovkillen » 25 Jan 2018, 20:53

As you see in the log you have named both the device and value "PIR" so your rule should be :

Code: Select all

On PIR#PIR=1 do 
gpio,5,1
timerset,1,90
Endon
The log show all the events that is triggering.

Edit : you beat me to it! :lol:
ESP Easy Flasher [flash tool and wifi setup at flash time]
ESP Easy Webdumper [easy screendumping of your units]
ESP Easy Netscan [find units]
Official shop: https://firstbyte.shop/
Sponsor ESP Easy, we need you :idea: :idea: :idea:

Post Reply

Who is online

Users browsing this forum: No registered users and 80 guests