Timer question

188 views
Skip to first unread message

Anil Garg

unread,
Sep 28, 2023, 8:40:31 PM9/28/23
to TasmotaUsers
Folks

I have time question that I could use set at a fix time.

Example:

exactly at 23:10 hrs, on all days, and forever repeat:

Turn on Relay 8
delay 5 seconds
Turn on Relay 2
delay 6,000 seconds  /* 10 minutes
turn off relay  2
turn off relay 8
delay 36,000 seconds  /* 1 hour
Turn on Relay 8
delay 5 seconds
Turn on Relay 3
delay 6,000 seconds  /* 10 minutes
turn off relay  2
turn off relay 8

End

I am sorry if I shoukd find it easy but any pointers would help would be appreciated. I can use this, then, to simulate more tests to see how it is designed to work.

Thanks


Anil Garg

unread,
Sep 28, 2023, 9:08:37 PM9/28/23
to TasmotaUsers
I tested and got this timer to work:

Timer1 {"Enable":1,"Time":"18:03","Window":0,"Days":"SMTWTFS","Repeat":1,"Output":8,"Action":1}

I have 16 timers and so it should now be easy for me to do this.

I did run into trouble earlier and that was because my time internally in tasmota was messed up. I found it on Tasmota Wiki and entered this to make it work:

Backlog0 Timezone 99; TimeStd 0,1,11,1,2,-480; TimeDst 0,2,3,1,2,-420


So, my problem is solved using very basic baby steps. However, I would love to hear how the Ninja solves this. What other elegant ways might be there...

Thank you.

Philip Knowles

unread,
Sep 29, 2023, 2:41:13 AM9/29/23
to Anil Garg, TasmotaUsers
Easiest way is to use Timers as you have but you could use 2 Timers plus rules and pulsetime 6100 for 2.
on power8#state=1 do backlog delay 50; power2 1 endon on power2#state=0 do power8 0 endon



From: sonof...@googlegroups.com <sonof...@googlegroups.com> on behalf of Anil Garg <anilga...@gmail.com>
Sent: Friday, September 29, 2023 2:08:37 AM
To: TasmotaUsers <sonof...@googlegroups.com>
Subject: Re: Timer question
 
--
You received this message because you are subscribed to the Google Groups "TasmotaUsers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sonoffusers...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/sonoffusers/b09e63c8-3af5-476c-a5f0-855976dfee2cn%40googlegroups.com.

Anil Garg

unread,
Sep 29, 2023, 12:51:25 PM9/29/23
to TasmotaUsers
Fascinating stuff. I read some more, and although I did not understand Pulsetime just as yet, I did find something that might work on my drip:

Rule1 on clock#Timer=16 do backlog power8 on; interlock 2,3,4,5,6,7; power2 on; delay 100; power3 on; delay 100; power4 on; delay 100; power4 on; delay 100; power5 on; delay 100; power6 on; delay 100; power7 on; delay 100; power7 off;power8 off; endon
Rule1 1
Timer16 {"Arm":1,"Mode":0,"Time":"09:30","Days":"1111111","Repeat":1,"Action":3}
#
Meaning:
   Only one of the relays (2,3,4,5,6,7) can be on at one time.
#
   Power8 on /* apply power to the relays actuators.
#
   Exactly at 9:30 AM every day and forever
   Turn on Relay2 and wait for 10 minutes
   Turn on Relay3 and wait for 10 minutes   /* previous relay turned off due to interlock
   Turn on Relay4 and wait for 10 minutes   /* previous relay turned off due to interlock
   Turn on Relay5 and wait for 10 minutes   /* previous relay turned off due to interlock
   Turn on Relay6 and wait for 10 minutes   /* previous relay turned off due to interlock
   Turn on Relay7 and wait for 10 minutes   /* previous relay turned off due to interlock
   Turn off Relay7 and wait for 10 minutes
#
   Power8 off /* disable power to the relays actuators.

Will this work?
I tried, and it did not work even once.... and I wonder what is an obvious error.

Thank you and much appreciate.

Anil



Anil Garg

unread,
Sep 29, 2023, 1:48:27 PM9/29/23
to TasmotaUsers
Sorry....

I take it back..

It has worked.

Now how can I make delay 100 to be a variable.  Love to find that.

Philip Knowles

unread,
Sep 29, 2023, 4:46:57 PM9/29/23
to Anil Garg, TasmotaUsers
You don't need Interlock in the rule. It will 'stick' if done as a command. If you're worried about losing it on restart you can put it a system start rule. 
Pulsetime just actuates the relay for a fixed time.
Sent: Friday, September 29, 2023 6:48:27 PM

Anil Garg

unread,
Sep 29, 2023, 7:34:33 PM9/29/23
to TasmotaUsers
Like:

rule2 ON System#Boot DO Backlog interlock 2,3,4,5,6,7;  EndON

Is there a way to specify delay of one hour? It turns out that the delay of 100 that I used in example earlier makes it 10 seconds and there is no way it can be more than 3600 (6 minutes).

Andrew L

unread,
Sep 30, 2023, 3:27:06 AM9/30/23
to TasmotaUsers
How about something like 
```
rule1
on system#boot do backlog interlock 2,3,4,5,6,7; var1 2 endon
on event#t1<8 do backlog power%value% 1; ruletimer1 3600; add1 1 endon
on rules#timer=1 do event t1=%var1% endon
on event#t1=8 do backlog var1 2; power%var1% 0; ruletimer1 0

rule2
on time#minute=1083 do backlog power8 1; event t1=%var1% endon

backlog rule2 5; rule2 1; rule1 1
```
Explanation:
on system#boot, interlock the relays, set var1 to 2

rule2: when time is 18:03, turn on the relay current, trigger event "t1" with a value of var1 (initially 2)
this is a separate rule so it can be one-shot, otherwise this will trigger every .2 seconds or so during the minute of 18:03.

rule1: each time event "t1" is triggered (less than 8), it turns on relay(x), then starts a 1 hour timer (ruletimer1), then adds 1 to var1 for the next time "t1" is triggered
when ruletimer1 ends (rules#timer=1), trigger event "t1" again with the next relay (because var1 was incremented with add1 1)
when var1 gets to 8, time to turn everything off, so var1 resets until tomorrow, relay 8 is turned off, and the running ruletimer is turned off

A little complicated, but illustrates some of the possibilities of rules, especially the programatic incrementing of var1 and how it can be used to avoid making long lists of triggers.

*I haven't tested this, but it should work.  

Philip Knowles

unread,
Sep 30, 2023, 4:23:31 AM9/30/23
to Andrew L, TasmotaUsers
Use pulsetime and the use the relay going off to trigger the next one
Pulsetime can be as long as 18 hours. You need to add 100 to the number of seconds you need.
Pulsetime2 3700 would be 1 hour
Trigger first relay on your timer then
On power2#state=0 do power3 1 Endon
And so on 
From: sonof...@googlegroups.com <sonof...@googlegroups.com> on behalf of Andrew L <pkkr...@gmail.com>
Sent: Saturday, September 30, 2023 8:27:06 AM

Anil Garg

unread,
Sep 30, 2023, 7:56:26 PM9/30/23
to TasmotaUsers
Yes,  Its something I tested and even tried switchmode 14 but have not cracked the string yet.

If I want to run each relay for fixed minutes in sequence it would be easy. Like this:
Pulsetime2  700
pulsetime3 700
...
pulsetime7 700
interlock 2,3,4,5,6,7   /* this is not really needed but as a safety

Time to trigger relay2 on at 12:30 am

rule1 on power2#state=0 do power3=1 endo       on power3#state=0 do power4=1 endo on power4#state=0 do power5=1 endo on power5#state=0 do power6=1 endo on power6#state=0 do power7=1 endo




HOWEVER

If I wanted to have Power2 come on for 10 minutes at 12:30 am and then power3 at 1:30 am etc.. meaning no water use between 1240 am - 1:30 am.  I find it a difficult play..

I thinking that switchmode 14 may offer a path in the sense it can offer 50 minutes of wait (pulsetime 3100) before turning it on

I will keep thinking.

Anil

Anil Garg

unread,
Sep 30, 2023, 9:25:28 PM9/30/23
to TasmotaUsers
I  love this. From what I can tell, it is creating a do loop of do while var=2 to 8.   A programming language!

Anil Garg

unread,
Oct 1, 2023, 6:32:19 AM10/1/23
to TasmotaUsers
Inspired by your code, I wrote up a real case and instead of VAR used MEM as it will survive a power failure.  And it gives me capability to change its execution a little bit.  I tried it on the relay, and it does not work.  There is no sign of Rule 1 getting executed.  I will check again tomorrow but thought I will post here for some one to spot any stupid / obvious error I may have made.


mem1=30      /* No of minutes after midnight the drip system will be triggered  (Usually 30 -- 30 minutes past midnight)
mem2=540     /* Time when duration is reset to default after mem3 manually changed during the day (usually 540 for 9:00 am)
mem3=700     /* controls the duration of drip station in 1/10th of seccond until 111 and in seconds minus 100 from value of 112   (usually 700 -- 10 minutes)
mem4=2       /* Control the relay<> that gets actuated (usually 2   -- for relay 2,3,4,5,6,and 7)
mem5=3600    /* duration of relaytimer1   (usually 3600 -- one hour)

rule3
        on time#minute=%mem1% do backlog power8 1; event t1=2000; event t1=%mem4% endon    /* per git time#minute= gets executed only once  & Should be power8 1

rule1
        on time#minutes=%mem2% do backlog mem3=700 endo
        on event#t1<8  do backlog pulsetime%mem4%=%%mem3%; power%mem4%=1; ruletimer1=%mem5%; mem4=mem4+1 endon
        on ruletimer1=1 do backlog event t1=%mem4% endo
        on event#t1=8 do backlog mem4 2 endo
        on system#boot do backlog interlock 2,3,4,5,6,7; mem4=2 endo

Rule1 1
Rule3 1



On Saturday, September 30, 2023 at 12:27:06 AM UTC-7 pkkr...@gmail.com wrote:

Philip Knowles

unread,
Oct 1, 2023, 8:05:56 AM10/1/23
to Anil Garg, TasmotaUsers
Well you have time#minutes not time#minute in rule 1
Sent: Sunday, October 1, 2023 11:32:19 AM

Andrew L

unread,
Oct 1, 2023, 8:43:00 AM10/1/23
to TasmotaUsers
A couple errors I see:

- on time#minutes=%mem2% needs to be on time#minute=%mem2%
 - backlog mem3=700 endo needs to be  backlog mem3 700 endon (this occurs multiple times, endo instead of endon)

Why call event t1=2000 then immediately call event t1=2?

- power%mem4%=1 needs to be power%mem4% 1
- ruletimer1=%mem5% needs to be ruletimer1 %mem5%
- mem4=mem4+1 is not possible. Need to use add1 to adjust the value of var1 then transfer to mem4
- pulsetime is a "set once" command. Do "pulsetime1 700", "pulsetime2 700" etc and then all you have to do is Power1 1 and it will run for pulsetime. Dont use pulsetime in the rule.
- on ruletimer1=1 needs to be on rules#timer=1 
- when do you turn off Power8?
- each time you write to mem it wears the flash. You will rack up a lot of flash writes with this code.

rule3
        on time#minute=%mem1% do backlog power8 1; event t1=2000; event t1=%mem4% endon    /* per git time#minute= gets executed only once  & Should be power8 1

rule1
        on time#minutes=%mem2% do backlog mem3=700 endo
        on event#t1<8  do backlog pulsetime%mem4%=%%mem3%; power%mem4%=1; ruletimer1=%mem5%; mem4=mem4+1 endon
        on ruletimer1=1 do backlog event t1=%mem4% endo
        on event#t1=8 do backlog mem4 2 endo
        on system#boot do backlog interlock 2,3,4,5,6,7; mem4=2 endo

Rule1 1
Rule3 1


Andrew L

unread,
Oct 1, 2023, 9:03:00 AM10/1/23
to TasmotaUsers
Looks like you're wanting to be able to adjust the time and duration of the drippers, and then have it reset to defaults once a day? Seems to be to be no reason for using mem over var, since you reset everything to defaults at boot anyway. What part do you want to survive a reboot? 

On Sunday, October 1, 2023 at 10:32:19 AM UTC anilga...@gmail.com wrote:

Anil Garg

unread,
Oct 2, 2023, 12:30:05 AM10/2/23
to TasmotaUsers
I found a relay on which I was testing this. 
The construct
     power%value% 1
turns into POWER2.000=1  and therefore it issues a off command because of decimal zeros.  Is there a way to say use only the integer value?

On Saturday, September 30, 2023 at 12:27:06 AM UTC-7 pkkr...@gmail.com wrote:

Andrew L

unread,
Oct 2, 2023, 4:42:21 PM10/2/23
to TasmotaUsers
Yes, use the command "calcres 0" to limit decimals in add, sub, mult commands.

Anil Garg

unread,
Oct 2, 2023, 5:25:49 PM10/2/23
to TasmotaUsers
Eureka.  I got it to work and now I will test the calres.

var1 30      /* No of minutes after midnight the drip system will be triggered  (Usually 30 -- 30 minutes past midnight)
var2 2       /* Control the relay<> that gets actuated for tonight's drip schedule (usually 2   -- for all relay 2,3,4,5,6,and 7)


Rule3
on time#minute=%var1% do backlog power1 1; event t1=2000; event t1=%var2% endon
on rules#timer=1 do backlog event t1=%var2% endon
on event#t1=2.000 do backlog power2 1; ruletimer1 36; add2 1 endon
on event#t1=3.000 do backlog power3 1; ruletimer1 36; add2 1 endon
on event#t1=4.000 do backlog power4 1; ruletimer1 36; add2 1 endon
on event#t1=5.000 do backlog power5 1; ruletimer1 36; add2 1 endon
on event#t1=6.000 do backlog power6 1; ruletimer1 36; add2 1 endon
on event#t1=7.000 do backlog power7 1; ruletimer1 36; add2 1 endon
on event#t1=8.000 do backlog var2 2 endon


rule1
on system#boot do backlog interlock 2,3,4,5,6,7; pulsetime2 120; pulsetime3 120; pulsetime4 120; pulsetime5 120; pulsetime6 120; pulsetime7 120;  endon



Anil Garg

unread,
Oct 2, 2023, 5:43:14 PM10/2/23
to TasmotaUsers
And, now with the calcres defining decimal place to 0, it also enabled doing a loop and yes the power%var% also works.

The new rules:

rule1
on system#boot do backlog interlock 2,3,4,5,6,7; pulsetime2 120; pulsetime3 120; pulsetime4 120; pulsetime5 120; pulsetime6 120; pulsetime7 120;  endon

Rule3
on time#minute=%var1% do backlog calcres 0; power1 1; event t1=2000; event t1=%var2% endon
on rules#timer=1 do backlog event t1=%var2% endon
on event#t1<8 do backlog power%var2% 1; ruletimer1 36; add2 1 endon
on event#t1=8 do backlog var2 2 endon


Thank you so much.
I will put this in operation and order a bunch of these little devices to do more stuff!!!

I would like to findout how to make pulsetime%var% or ruletimer%var2%=%var3% work.

Philip Knowles

unread,
Oct 3, 2023, 1:47:24 AM10/3/23
to Anil Garg, TasmotaUsers
Please add this to the docs if it works.
Sent: Monday, October 2, 2023 10:43:14 PM

Anil Garg

unread,
Oct 3, 2023, 2:56:11 AM10/3/23
to TasmotaUsers
OK. I will add that.

Is it at this location?
Message has been deleted

Andrew L

unread,
Oct 4, 2023, 3:46:27 AM10/4/23
to TasmotaUsers
You cannot use equal sign (=) in ruletimer (and most other) commands. if you do ruletimer%var1% %var3% it will work. ruletimer%var1%=%var3% will not work.

Anil Garg

unread,
Oct 4, 2023, 7:42:12 PM10/4/23
to TasmotaUsers
The expression ruletimer%var1% %var3% works in the rules, on my version of the firmware, as we discussed earlier.  I went to study the expression rules you pointed out and then found some literature on IF and ENDIF. I set IF & ENDIF pair inside an ON & ENDON and set it to an unused rule to test and found that this too works on my version of the pre-compiled binary.

Anil

Philip Knowles

unread,
Oct 5, 2023, 2:57:31 AM10/5/23
to Anil Garg, TasmotaUsers
Just a cautionary word.
When you are describing your issues please make clear that you have Expressions compiled.
The syntax of commands changes with Expressions and people will make incorrect suggestions unless they know Expressions is compiled.
Sent: Thursday, October 5, 2023 12:42:12 AM
Reply all
Reply to author
Forward
0 new messages