Execute rule once

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
bonsai307
New user
Posts: 2
Joined: 31 Mar 2020, 17:25

Execute rule once

#1 Post by bonsai307 » 02 Sep 2020, 22:34

Hello everybody,

short question about the rule below for ESPEasy:

My rule starts over and over again because the brightness value is constant
is above the threshold. What would I have to build in to make the rule only
once if the lux value is over or undercut for 5 seconds.
is performed?

Thanks in advance!

greets bonsai

Code: Select all

On Licht#Lux>25 do
   event,Tag 
 endon
 
On Licht#Lux<25 do
   event,Nacht 
 endon

on Tag do
   WemosMotorShieldCMD,0,Forward,20  // open tuer
   timerSet 1,5 // 5 sec timer
 endon
 On Rules#Timer=1 do  //When Timer1 expires, do
   WemosMotorShieldCMD,0,Stop
 endon


 on Nacht do
   WemosMotorShieldCMD,0,Forward,20  // close tuer
   timerSet 2,1 // 1 sec timer
 endon
 On Rules#Timer=2 do  //When Timer2 expires, do
   WemosMotorShieldCMD,0,Stop
 endon
 

TD-er
Core team member
Posts: 8736
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Execute rule once

#2 Post by TD-er » 02 Sep 2020, 23:08

Have you also seen/tried the Level plugin?
That one can also use some hysteresis.

Micha_he
Normal user
Posts: 372
Joined: 07 Feb 2018, 19:14
Location: Helmstedt, Germany

Re: Execute rule once

#3 Post by Micha_he » 02 Sep 2020, 23:44

Or use a var to remember a state:

Code: Select all

on Licht#Lux>25 do
  if [VAR#1]=0
    event,Tag
    Let,1,1
  endif 
endon
 
on Licht#Lux<25 do
  if [VAR#1]=1
    event,Nacht
    Let,1,0
  endif 
endon

on Tag do
  WemosMotorShieldCMD,0,Forward,20  // open tuer
  timerSet 1,5 // 5 sec timer
endon

on Rules#Timer=1 do  //When Timer1 expires, do
  WemosMotorShieldCMD,0,Stop
endon

on Nacht do
  WemosMotorShieldCMD,0,Forward,20  // close tuer
  timerSet 2,1 // 1 sec timer
endon

on Rules#Timer=2 do  //When Timer2 expires, do
  WemosMotorShieldCMD,0,Stop
endon

TD-er
Core team member
Posts: 8736
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Execute rule once

#4 Post by TD-er » 03 Sep 2020, 08:54

@Micha_he Yep, that's also an option, although I am not 100% sure the rules will parse 2 event blocks with the same event name only different eventvalues.
At least you have a hysteresis of 1 lux in your example :)

Another option can be to do it like this:

Code: Select all

on Licht#Lux do
  if %eventvalue% > 25
    if [VAR#1]=0
      event,Tag
      Let,1,1
    endif 
  else 
    if [VAR#1]=1
      event,Nacht
      Let,1,0
    endif 
  endif
endon

[...]
That one doesn't have a hysteresis, so it may toggle a few times if the sensor reading switches between values around your threshold.

Micha_he
Normal user
Posts: 372
Joined: 07 Feb 2018, 19:14
Location: Helmstedt, Germany

Re: Execute rule once

#5 Post by Micha_he » 03 Sep 2020, 12:47

You're right, thats better :)
I was just taking bonsai's example and integrate quickly the if-condition of VAR#1...

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Google [Bot] and 14 guests