Page 1 of 1
Problem with timer syntax ?
Posted: 08 Feb 2025, 23:09
by romainperea
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
Re: Problem with timer syntax ?
Posted: 08 Feb 2025, 23:17
by Ath
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
Re: Problem with timer syntax ?
Posted: 08 Feb 2025, 23:20
by Ath
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
Re: Problem with timer syntax ?
Posted: 08 Feb 2025, 23:24
by romainperea
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
Re: Problem with timer syntax ?
Posted: 08 Feb 2025, 23:25
by TD-er
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
Re: Problem with timer syntax ?
Posted: 08 Feb 2025, 23:42
by romainperea
Thanks for your really fast responses team
Unfortunatly, it does not works...
But i'll try to figure it ou tomorrow

Re: Problem with timer syntax ?
Posted: 09 Feb 2025, 00:06
by romainperea
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
Re: Problem with timer syntax ?
Posted: 09 Feb 2025, 00:07
by TD-er
What isn't working?
Or maybe I didn't understand your requirements.
Re: Problem with timer syntax ?
Posted: 09 Feb 2025, 11:53
by romainperea
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.
Re: Problem with timer syntax ?
Posted: 09 Feb 2025, 12:05
by TD-er
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)
Re: Problem with timer syntax ?
Posted: 09 Feb 2025, 12:10
by romainperea
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
