We want to turn on a pump every 5 minutes for 20 seconds using a sonoff Pow. Currently we solve this by this nasty piece of code:
# Create self repeating rule
rule1 on Rules#Timer=1 do backlog power on; ruletimer 300 endon
# Auto Turn off after 20 seconds
pulsetime 200
# Enable timer/trigger
ruletimer 1
Using a minute trigger which accepts a modulo would be easy to implement and solve the problem in a clean fashion such as :
rule 1 on Time#Minute%5 do ... endon
That's no nasty, but you can do it without pulsetime
rule1 on Rules#Timer=1 do backlog power on;delay 200;power off;ruletimer 300 endon
Thanks, unfortunately the piece of code you suggest did not work for us since the delay was not respected (the pump turned off after 1 second)
No it works as expected (using current v6.1.1 from Release)
dev/stat/tasmota/esp01/STATUS2 = {"StatusFWR":{"Version":"6.1.1","BuildDateTime":"2018-07-31T17:59:09","Boot":31,"Core":"2_3_0","SDK":"1.5.3(aec24ac9)"}}
Disable previous set PulseTime, this interfer with your rule
PulseTime1 0
# Disable PulseTime
PulseTime1 0
# create rule
rule1 on Rules#Timer=1 do backlog power on;delay 200;power off;ruletimer 300 endon
# enable rule
rule1 1
# trigger rule
ruletimer1 1
Result
11:55:21 MQT: dev/stat/tasmota/esp01/RESULT = {"POWER1":"ON"}
11:55:21 MQT: dev/stat/tasmota/esp01/POWER1 = ON
11:55:21 MQT: dev/stat/tasmota/esp01/RESULT = {"Delay":200}
11:55:41 MQT: dev/stat/tasmota/esp01/RESULT = {"POWER1":"OFF"}
11:55:41 MQT: dev/stat/tasmota/esp01/POWER1 = OFF
11:55:41 MQT: dev/stat/tasmota/esp01/RESULT = {"RuleTimer1":300}
12:00:41 MQT: dev/stat/tasmota/esp01/RESULT = {"POWER1":"ON"}
12:00:41 MQT: dev/stat/tasmota/esp01/POWER1 = ON
12:00:41 MQT: dev/stat/tasmota/esp01/RESULT = {"Delay":200}
12:01:01 MQT: dev/stat/tasmota/esp01/RESULT = {"POWER1":"OFF"}
12:01:01 MQT: dev/stat/tasmota/esp01/POWER1 = OFF
12:01:01 MQT: dev/stat/tasmota/esp01/RESULT = {"RuleTimer1":300}
I have to agree with @curzon01
But as I liked the modulo option too I just released 6.1.1.6 with this option. Keep in mind to use the "|" sign for modulo as the "%" is already used for variables and discriminating them makes the code unwanted larger.
So in your case this worked for me:
rule1 on Time#Minute|5 do backlog power on;delay 200;power off endon
rule1 1
rule1 4
results in this:
13:10:00 RUL: TIME#MINUTE|5 performs "backlog power on;delay 200;power off"
13:10:00 SRC: Rule
13:10:00 RSL: Group 0, Index 1, Command BACKLOG, Data power on;delay 200;power off
13:10:00 SRC: Backlog
13:10:00 RSL: Group 0, Index 1, Command POWER, Data on
13:10:00 MQT: stat/ring2/POWER = {"POWER":"ON"}
13:10:00 MQT: stat/ring2/POWER = ON
13:10:00 SRC: Backlog
13:10:00 RSL: Group 0, Index 1, Command DELAY, Data 200
13:10:00 MQT: stat/ring2/DELAY = {"Delay":200}
13:10:20 SRC: Backlog
13:10:20 RSL: Group 0, Index 1, Command POWER, Data off
13:10:20 MQT: stat/ring2/POWER = {"POWER":"OFF"}
13:10:20 MQT: stat/ring2/POWER = OFF
@arendst : i would have liked the option of @curzon01 too, but did not work for me, i will recheck this if i had a typo there, thanks for implementing the | modulo feature though, its a more neat way imho!
Hi Guys,
i just checked again and for me the delay version as stated above does not work. Any ideas?
11:33:57 CMD: rule1 on Rules#Timer=1 do backlog power on; delay 200; power off; ruletimer 200 endon
11:33:57 RSL: RESULT = {"Rule1":"ON","Once":"OFF","Free":431,"Rules":"on Rules#Timer=1 do backlog power on; delay 200; power off; ruletimer 200 endon "}
11:34:16 CMD: ruletimer 1
11:34:16 RSL: RESULT = {"RuleTimer1":1}
11:34:18 RUL: RULES#TIMER=1 performs "backlog power on; delay 200; power off; ruletimer 200"
11:34:18 RSL: RESULT = {"POWER1":"ON"}
11:34:18 RSL: POWER1 = ON
11:34:18 RSL: RESULT = {"POWER1":"OFF"}
11:34:18 RSL: POWER1 = OFF
11:34:18 RSL: RESULT = {"Delay":200}
can we reopen it or open a new issue?
Pls enable more logging with weblog 3 to find out where the POWER1 OFF comes from.
Most helpful comment
I have to agree with @curzon01
But as I liked the modulo option too I just released 6.1.1.6 with this option. Keep in mind to use the "|" sign for modulo as the "%" is already used for variables and discriminating them makes the code unwanted larger.
So in your case this worked for me:
results in this: