hi
so a add some events (forward,reverse,stop)
i want to repeat the
start forward event for 5 min
then reverse event for 5 min
then forward event for 5 min
then reverse event for 5 min
.....
maybe 10 times or more...
an when the pseudoloop is done
i want to stop with the event stop
the trigger i want to use to start this repeating events i a do on button....
to understand i want to clean my pool and the poolcleaner goes 5 min forward und 5 min backward... and so on...
May anyone have an idea.
TIA
Rira
Repeat an event x times (like a loop) (for-while)
Moderators: grovkillen, Stuntteam, TD-er
Re: Repeat an event x times (like a loop) (for-while)
Have you looked at the looptimer? https://espeasy.readthedocs.io/en/lates ... oop-timers
This can be used to set a loop timer and also set the number of loops.
To switch between "forward" and "reverse", you could set a variable (see the "let" command) and set the looptimer for 5 minutes.
Every loop you just toggle the variable to switch between forward and reverse mode.
This can be used to set a loop timer and also set the number of loops.
To switch between "forward" and "reverse", you could set a variable (see the "let" command) and set the looptimer for 5 minutes.
Every loop you just toggle the variable to switch between forward and reverse mode.
Re: Repeat an event x times (like a loop) (for-while)
hi
many thx for your help... but i didnt understand the exact commands
tried this one;
on cleanstart do
looptimerset,3,15,10 // loop 1 forward 15 sec / 10 times repead
looptimerset,4,15,10 // loop 2 reverse 15 sec / 10 times repead
endon
On Rules#Timer=3 do
if %eventvalue2% >= 5 // -> what does the >=5 mean ??!
timerSet,3,0 // Stop timer 3 /why the timer will stoped there
endif
event forward
logentry,%eventvalue2% // log the loop count
endon
On Rules#Timer=4 do
if %eventvalue2% = 2 // -> what does the =2 mean ??!
loopTimerSet,4,15 // Restart loop timer 4 (thus clearing loop count)
timerResume,3 // why this what du this
event reverse
else
timerPause,3 // why this what du this
endif
endon
..........................................................
on cleanstop do
event stop
timerSet,3,0
timerSet,4,0
endon
but it didnt works it olny starts one time forward und this was it...
Sorry for my poor programing skills but my last time i program something it was in pascal in the 1990s....
to understand
i only want to do a loop with
--------------------------------------------------------
15 sec the event forward |
then 15 sec the event reverse |
-------------------------------------------------------
-----> do this 10 times....
tia
Rira
many thx for your help... but i didnt understand the exact commands
tried this one;
on cleanstart do
looptimerset,3,15,10 // loop 1 forward 15 sec / 10 times repead
looptimerset,4,15,10 // loop 2 reverse 15 sec / 10 times repead
endon
On Rules#Timer=3 do
if %eventvalue2% >= 5 // -> what does the >=5 mean ??!
timerSet,3,0 // Stop timer 3 /why the timer will stoped there
endif
event forward
logentry,%eventvalue2% // log the loop count
endon
On Rules#Timer=4 do
if %eventvalue2% = 2 // -> what does the =2 mean ??!
loopTimerSet,4,15 // Restart loop timer 4 (thus clearing loop count)
timerResume,3 // why this what du this
event reverse
else
timerPause,3 // why this what du this
endif
endon
..........................................................
on cleanstop do
event stop
timerSet,3,0
timerSet,4,0
endon
but it didnt works it olny starts one time forward und this was it...
Sorry for my poor programing skills but my last time i program something it was in pascal in the 1990s....
to understand
i only want to do a loop with
--------------------------------------------------------
15 sec the event forward |
then 15 sec the event reverse |
-------------------------------------------------------
-----> do this 10 times....
tia
Rira
Re: Repeat an event x times (like a loop) (for-while)
I think it can be as simple as this:rira2005 wrote: ↑20 May 2021, 22:59 hi
many thx for your help... but i didnt understand the exact commands
tried this one;but it didnt works it olny starts one time forward und this was it...Code: Select all
on cleanstart do looptimerset,3,15,10 // loop 1 forward 15 sec / 10 times repead looptimerset,4,15,10 // loop 2 reverse 15 sec / 10 times repead endon On Rules#Timer=3 do if %eventvalue2% >= 5 // -> what does the >=5 mean ??! timerSet,3,0 // Stop timer 3 /why the timer will stoped there endif event forward logentry,%eventvalue2% // log the loop count endon On Rules#Timer=4 do if %eventvalue2% = 2 // -> what does the =2 mean ??! loopTimerSet,4,15 // Restart loop timer 4 (thus clearing loop count) timerResume,3 // why this what du this event reverse else timerPause,3 // why this what du this endif endon .......................................................... on cleanstop do event stop timerSet,3,0 timerSet,4,0 endon
Sorry for my poor programing skills but my last time i program something it was in pascal in the 1990s....
to understand
i only want to do a loop with
--------------------------------------------------------
15 sec the event forward |
then 15 sec the event reverse |
-------------------------------------------------------
-----> do this 10 times....
tia
Rira
Code: Select all
on cleanstart do
looptimerset,3,15,20 // every 15 seconds, repeat 20 times (10 times forward, 10 reverse)
endon
On Rules#Timer=3 do
let,1,%eventvalue2% // Store the loop count in a variable
if [int#1]%2=0 // Check if the loop count modulo (%) 2 = 0
asyncevent,forward
else
asyncevent,reverse
endif
endon
It does start a single loop timer for 20 loops (10 forward, 10 reverse) with 15 sec interval.
I store the loop counter in a variable first since I need to use the "%" operator and I was not sure if that would interfere with the % in %eventvalue2%. It may be possible to have it even shorter.
What the modulo (%) operator does is, it is computing what is 'left' if you divide an integer number.
e.g. 9%2 = 1 as you can four times subtract '2' from '9' and then are left with '1'
Thus:
- N%2=0 -> even numbers
- N%2=1 -> odd numbers
So on the 'even loops' you call the event "forward" and on the odd loops you call the even "reverse".
I changed "event" to "asyncevent" to add the event to an event queue so the ESP will not be too long in processing the rules.
Re: Repeat an event x times (like a loop) (for-while)
hi i done it lite this, many thanks to all!
on cleanstart do
Publish domoticz/in,'{"idx":158,"nvalue":1,"svalue":""}' //mqtt info to start the event
asyncevent,reverse //start yet not to wait 30 seconds
let,2,1 //forward and reverse var to for the if set to 1 --> forward
looptimerset,3,30,200 // every 30 seconds, repeat 200 times (100 times forward, 100 reverse)
endon
On Rules#Timer=3 do
logentry,%eventvalue2% // log the loop count
if %eventvalue2% >= 200 //check the loop count is more the 200 if
asyncevent,cleanstop //call the event cleanstop
elseif [int#2]=1 // if direction var is 1(reverse) do the event forward
asyncevent,forward //call the forward event
let,2,0 //forward and reverse var to for the if set to 0 --> reverse
else // else direction var is 0(forward) do the event reverse
asyncevent,reverse //call the reverse event //call the forward event
let,2,1 //forward and reverse var to for the if set to 0 --> reverse
endif
endon
on cleanstop do
Publish domoticz/in,'{"idx":158,"nvalue":0,"svalue":""}' //mqtt info to stop the event
event,stop //call the stop event
looptimerset,3,0 //stop the timer before the loops ends (to stop it with buttoon or http req. via domoticz)
endon
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
on forward do
if [R2#state]=0
gpio,13,1
gpio,12,1
TimerSet_ms,1,1000
else
gpio,13,0
GPIO,14,1
let,1,1
endif
endon
on stop do
gpio,12,1
gpio,13,1
GPIO,14,0
let,1,0
endon
on reverse do
if [R1#state]=0
gpio,13,1
gpio,12,1
TimerSet_ms,2,1000
else
gpio,12,0
GPIO,14,1
let,1,1
endif
endon
on rules#timer=1 do
gpio,13,0
GPIO,14,1
let,1,1
endon
on rules#timer=2 do
gpio,12,0
GPIO,14,1
let,1,1
endon
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
on cleanstart do
Publish domoticz/in,'{"idx":158,"nvalue":1,"svalue":""}' //mqtt info to start the event
asyncevent,reverse //start yet not to wait 30 seconds
let,2,1 //forward and reverse var to for the if set to 1 --> forward
looptimerset,3,30,200 // every 30 seconds, repeat 200 times (100 times forward, 100 reverse)
endon
On Rules#Timer=3 do
logentry,%eventvalue2% // log the loop count
if %eventvalue2% >= 200 //check the loop count is more the 200 if
asyncevent,cleanstop //call the event cleanstop
elseif [int#2]=1 // if direction var is 1(reverse) do the event forward
asyncevent,forward //call the forward event
let,2,0 //forward and reverse var to for the if set to 0 --> reverse
else // else direction var is 0(forward) do the event reverse
asyncevent,reverse //call the reverse event //call the forward event
let,2,1 //forward and reverse var to for the if set to 0 --> reverse
endif
endon
on cleanstop do
Publish domoticz/in,'{"idx":158,"nvalue":0,"svalue":""}' //mqtt info to stop the event
event,stop //call the stop event
looptimerset,3,0 //stop the timer before the loops ends (to stop it with buttoon or http req. via domoticz)
endon
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
on forward do
if [R2#state]=0
gpio,13,1
gpio,12,1
TimerSet_ms,1,1000
else
gpio,13,0
GPIO,14,1
let,1,1
endif
endon
on stop do
gpio,12,1
gpio,13,1
GPIO,14,0
let,1,0
endon
on reverse do
if [R1#state]=0
gpio,13,1
gpio,12,1
TimerSet_ms,2,1000
else
gpio,12,0
GPIO,14,1
let,1,1
endif
endon
on rules#timer=1 do
gpio,13,0
GPIO,14,1
let,1,1
endon
on rules#timer=2 do
gpio,12,0
GPIO,14,1
let,1,1
endon
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Re: Repeat an event x times (like a loop) (for-while)
The expression processing actually handles that correctly, so this code:
Code: Select all
if %eventvalue2%%2=0 // Check if the loop count modulo (%) 2 = 0
/Ton (PayPal.me)
Who is online
Users browsing this forum: No registered users and 5 guests