Problem with timer syntax ?

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
romainperea
Normal user
Posts: 23
Joined: 20 Feb 2019, 15:15

Problem with timer syntax ?

#1 Post by romainperea » 08 Feb 2025, 23:09

Hello, i have a little problem with an ESP32 relay card.

I'm building an ozone device, triggered by a PIR sensor.

Everything is connected correctly, and the Devices are Populated correctly.

The goal of this Rules, is to "activate" the Relay for 4 seconds, when something trigger the PIR sensor.
When doing that, an ozone generator and a fan is activated.

What i want to add, is a secondary timer, to prevent the activation of the ozone genrator more than once in 2 minutes.

Unfortunatly my Rules does not work... Any idea ?



Code: Select all

On System#Boot do
 timerSet,2,120
Endon

On Infrarouge#State=1 do
 If [Rules#Timer]=2
  GPIO,23,1
  GPIO,16,1
  timerSet,1,4
 Endif
Endon

On Rules#Timer=1 do  //When Timer1 expires, do
 GPIO,23,0
 GPIO,16,0
 timerSet,2,120
endon

User avatar
Ath
Normal user
Posts: 4333
Joined: 10 Jun 2018, 12:06
Location: NL

Re: Problem with timer syntax ?

#2 Post by Ath » 08 Feb 2025, 23:17

What's supposed to happen when timer 2 expires? As you haven't added an event handler for timer 2

Code: Select all

On Rules#Timer=2 do  // When Timer2 expires, do
// some commands should go here
Endon
/Ton (PayPal.me)

User avatar
Ath
Normal user
Posts: 4333
Joined: 10 Jun 2018, 12:06
Location: NL

Re: Problem with timer syntax ?

#3 Post by Ath » 08 Feb 2025, 23:20

romainperea wrote: 08 Feb 2025, 23:09

Code: Select all

On Infrarouge#State=1 do
 If [Rules#Timer]=2
...
 Endif
Endon
That "If [Rules#Timer]=2" doesn't exist
/Ton (PayPal.me)

romainperea
Normal user
Posts: 23
Joined: 20 Feb 2019, 15:15

Re: Problem with timer syntax ?

#4 Post by romainperea » 08 Feb 2025, 23:24

When Timer2 expires, it is supposed to "allow" the PIR sensor to trigger the relay again.

I've tried this syntax with no more luck.
On System#Boot do
timerSet,2,120
Endon

On Infrarouge#State=1 And Rules#Timer=2 do
GPIO,23,1
GPIO,16,1
timerSet,1,4
Endon

On Rules#Timer=1 do //When Timer1 expires, do
GPIO,23,0
GPIO,16,0
timerSet,2,120
endon

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

Re: Problem with timer syntax ?

#5 Post by TD-er » 08 Feb 2025, 23:25

Code: Select all

If [Rules#Timer]=2
You cannot check for the rules timer state like that, you should use variables or better just check the state of the relay GPIO pin.

I think something like this should work (not tested)

Code: Select all

On Infrarouge#State=1 do
  if [Plugin#GPIO#Pinstate#23]=0 // Assume GPIO-32 is the relay?
    // Relay was not turned on, turn it on now and set timer to turn it off.
    gpio,23,1
    timerSet,1,4
    
    if [int#1]=0 and [Plugin#GPIO#Pinstate#16]=0
      gpio,16,1
      timerSet,2,120
      let,1,1 // Set flag for variable #1 to '1' to make sure we won't turn it on too often
    endif
  endif
endon


On Rules#Timer=1 do  // Timer #1 is used to turn off the fan and ozone generator
  GPIO,23,0
  GPIO,16,0
endon

On Rules#Timer=2 do  // Timer #2 is used to reset the flag limiting turning on the ozone generator too often.
  let,1,0  // Reset the flag
endon

romainperea
Normal user
Posts: 23
Joined: 20 Feb 2019, 15:15

Re: Problem with timer syntax ?

#6 Post by romainperea » 08 Feb 2025, 23:42

Thanks for your really fast responses team ;)

Unfortunatly, it does not works...
But i'll try to figure it ou tomorrow ;)

romainperea
Normal user
Posts: 23
Joined: 20 Feb 2019, 15:15

Re: Problem with timer syntax ?

#7 Post by romainperea » 09 Feb 2025, 00:06

I was not able to sleep without finding why, and here it is (thanks to you ;) ):
On Infrarouge#State=1 do
if [int#1]=0
gpio,23,1
gpio,16,1
TimerSet,1,4
Endif
endon

On Rules#Timer=1 do // Timer #1 is used to turn off the fan and ozone generator
GPIO,23,0
GPIO,16,0
Let,1,1
TimerSet,2,120
endon

On Rules#Timer=2 do // Timer #2 is used to reset the flag limiting turning on the ozone generator too often.
let,1,0 // Reset the flag
endon

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

Re: Problem with timer syntax ?

#8 Post by TD-er » 09 Feb 2025, 00:07

What isn't working?
Or maybe I didn't understand your requirements.

romainperea
Normal user
Posts: 23
Joined: 20 Feb 2019, 15:15

Re: Problem with timer syntax ?

#9 Post by romainperea » 09 Feb 2025, 11:53

TD-er wrote: 09 Feb 2025, 00:07 What isn't working?
Or maybe I didn't understand your requirements.
The thing that wasn't working was the second timer that prevent the device to release ozone to frequently.
Now, with the last code i posted (and your help), it works perfectly ;)


The device i'm building is something that i'm gonna install next to the liters of my cats.
It detect the presence of a cat, and release a small amount of ozone to neutralize the smells and the bacterias.

I'm probably code a third timer (now that i figured how it works ;) ) to make a "fuse time", once the presence of the cat is detected, to let the cat go after is done, to not send directly to him the ozone.

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

Re: Problem with timer syntax ?

#10 Post by TD-er » 09 Feb 2025, 12:05

Maybe you could add some VOC sensor (CCS811 if I'm not mistaken) to detect whether it may be needed to act against the smell.
Just make sure not to continue sending lots of ozone as it is for sure not healthy. (and it may interact with the readings of the VOC sensor)

romainperea
Normal user
Posts: 23
Joined: 20 Feb 2019, 15:15

Re: Problem with timer syntax ?

#11 Post by romainperea » 09 Feb 2025, 12:10

TD-er wrote: 09 Feb 2025, 12:05 Maybe you could add some VOC sensor (CCS811 if I'm not mistaken) to detect whether it may be needed to act against the smell.
Just make sure not to continue sending lots of ozone as it is for sure not healthy. (and it may interact with the readings of the VOC sensor)
Excellent idea ! I totally agree, i'll look for this and post my code and the total project once finished, if someone wants to build it ;)

Post Reply

Who is online

Users browsing this forum: No registered users and 16 guests