Help with rules and timer.

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
WhiWhi
New user
Posts: 2
Joined: 26 Aug 2021, 13:06

Help with rules and timer.

#1 Post by WhiWhi » 26 Aug 2021, 13:11

I would like help with how to solve a rule in EspEasy.

My thought is that if the temperature is above 24 degrees, it should send an email and then an email should be sent once an hour until the temperature is below 24 degrees.

How should I solve this?

My thought was like this but it does not work.

Code: Select all

on BME280#Temperature do 
   if [BME280#Temperature] > 24 and !Rules#Timer=1 
     Notify,1 
     timerSet,1,3600 
   endif 
endon

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

Re: Help with rules and timer.

#2 Post by TD-er » 26 Aug 2021, 13:18

I think you also need to set a flag, like in a variable.

See the 'let' command.

Then on the temperature event you check this flag if it is above your threshold and if it isn't set, set it and also start a timer like you do now. (just start the initial timer in 1 second)
If the flag is set, leave the timer running.

On the timer event you send a notification and restart the timer.
Since it was initially set to 1 second, you also immediately send a notification.

If the temp is lower than your threshold, clear the flag and clear the timer.

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

Re: Help with rules and timer.

#3 Post by Micha_he » 26 Aug 2021, 13:41

This could work (untestet):

Code: Select all

on BME280#Temperature do 
  if [BME280#Temperature] > 24
    if %v1% = 0 AND %v2% = 0
      Notify,1
      Let,1,1  // 1h timer is running
      Let,2,1  // temp is not lower than limit
      timerSet,1,3600
    endif
  elseif %v2% = 1
    Let,2,0
  endif 
endon

on Rules#Timer=1
  Let,1,0
endon
Edit: 'elseif' added

I read the first post again... And if you resend it after one hour, this version could work:

Code: Select all

on BME280#Temperature do 
  if [BME280#Temperature] > 24
    if %v1% = 0 // not paused
      Notify,1
      Let,1,1
      timerSet,1,3600
    endif
  else
    Let,1,0
    timerSet,1,0
  endif 
endon

on Rules#Timer=1
  Let,1,0
endon

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

Re: Help with rules and timer.

#4 Post by TD-er » 26 Aug 2021, 14:08

I think it can be simpler

Code: Select all

on BME280#Temperature do 
  if [BME280#Temperature] > 24
    if %v1% = 0 // not paused
      Let,1,1
      timerSet,1,1
    endif
  else
    Let,1,0
    timerSet,1,0
  endif 
endon

on Rules#Timer=1
  timerSet,1,3600
  notify,1  
endon

WhiWhi
New user
Posts: 2
Joined: 26 Aug 2021, 13:06

Re: Help with rules and timer.

#5 Post by WhiWhi » 26 Aug 2021, 18:24

I will test your suggestions. I managed to solve it myself after your first post. But it is not as nice as your solutions but works.

Code: Select all

on BME280#Temperature do
    if [BME280#Temperature] > 24 and %v1%=0
        let,1,1
        timerSet,1,3600
        timerSet,2,1
    endif
endon    

On Rules#Timer=2 do
    Notify,1
    timerSet,2,0
endon

On Rules#Timer=1 do
   if [BME280#Temperature] > 24 and %v1%=1
       Notify,1
       timerSet,1,3600
   else
       let,1,0
       timerSet,1,0
endon

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

Re: Help with rules and timer.

#6 Post by TD-er » 26 Aug 2021, 20:51

Well the most important thing to realize is that you managed to do it yourself, and thus now know how it works :)

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot] and 34 guests