What's wrong with my time-dependent rule?

72 views
Skip to first unread message

W.P.

unread,
Jun 3, 2025, 10:52:52 AMJun 3
to sonof...@googlegroups.com
Hi there,
I wrote a rule to:
1) not act between 9:30am and 11pm,
2) after 11pm switch off another Tasmota via mqtt,
3) finally if Voltage on INA226 sensor is above stored value switch that device on.

But this is working as if there were no time-based rules. Always act upon Voltage value.

Rule:

on Time#minute > 1380 do backlog publish cmnd/tasmota_B8165A.Power1 0; break on Time#minute < 570 do backlog publish cmnd/tasmota_B8165A.Power1 0; var7 %mem7%; break on INA226-1#Voltage > %var8% do var1 120 endon on INA226-1#Voltage > %var7% do publish cmnd/tasmota_B8165A/Power1 1 endon

Dots between publish xxx an Power?

Laurent

Philip Knowles

unread,
Jun 3, 2025, 3:47:41 PMJun 3
to W.P., sonof...@googlegroups.com
on Time#minute > 1380 do backlog publish cmnd/tasmota_B8165A; Power1 0 break
on Time#minute < 570 do backlog publish cmnd/tasmota_B8165A; Power1 0; var7 %mem7% break
on INA226-1#Voltage > %var8% do var1 120 endon
on INA226-1#Voltage > %var7% do publish cmnd/tasmota_B8165A/Power1 1 endon
No need for ; before break

From: sonof...@googlegroups.com <sonof...@googlegroups.com> on behalf of W.P. <wyszk...@gmail.com>
Sent: Tuesday, June 03, 2025 15:49
To: sonof...@googlegroups.com <sonof...@googlegroups.com>
Subject: What's wrong with my time-dependent rule?
--
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, visit https://groups.google.com/d/msgid/sonoffusers/90DC2CFE-7C07-4B34-88CA-6B8F6F0AE04C%40gmail.com.

Wyszków On

unread,
Jun 4, 2025, 5:23:21 AMJun 4
to Philip Knowles, TasmotaUsers
Hi Philip, 
Changed «;» to «/». Didn't help.
Will remove «;» before exit and test.
 
Laurent

Philip Knowles

unread,
Jun 4, 2025, 3:54:29 PMJun 4
to Wyszków On, TasmotaUsers
No. You need to replace <.> with <;>

From: Wyszków On <wyszk...@gmail.com>
Sent: 04 June 2025 10:23
To: Philip Knowles <knowles...@gmail.com>
Cc: TasmotaUsers <sonof...@googlegroups.com>
Subject: Re: What's wrong with my time-dependent rule?
 

Philip Knowles

unread,
Jun 5, 2025, 8:26:37 AMJun 5
to Wyszków On, TasmotaUsers
Sorry, just re-read should be publish cmnd/tasmota_B8165A/power1 0 break 
As you have in the second INA226 one

From: Wyszków On <wyszk...@gmail.com>
Sent: 04 June 2025 10:23
To: Philip Knowles <knowles...@gmail.com>
Cc: TasmotaUsers <sonof...@googlegroups.com>
Subject: Re: What's wrong with my time-dependent rule?
 

Wyszków On

unread,
Jun 9, 2025, 6:59:43 PMJun 9
to Philip Knowles, TasmotaUsers
Hi, 
partially works, but Time#minute is executed every minute, and Voltage every second.
And it seems there is no Time#second :(
Any proposals how to make my requirements (first post) work?

Laurent 

Wyszków On

unread,
Jun 10, 2025, 12:33:12 PMJun 10
to Philip Knowles, TasmotaUsers
Changed again, still works partially: 
Now up to "var5 %var5%"
Rule:

on Time#minute > 1380 do backlog publish cmnd/tasmota_B8165A/Power1 0 break on Time#minute < 570 do backlog publish cmnd/tasmota_B8165A/Power1 0; var7 %mem7% break on ina226-1#voltage do var5 %value% Endon on Time#minute > -1 do var6 %var5%  endon on var6 > %var8% do var1 120 endon on var6 > %var7% do publish cmnd/tasmota_B8165A/Power1 1 endon

Laurent 

wt., 3 cze 2025, 21:47 użytkownik Philip Knowles <knowles...@gmail.com> napisał:

Philip Knowles

unread,
Jun 10, 2025, 3:56:24 PMJun 10
to Wyszków On, TasmotaUsers
Timer1 {"Enable":1,"Mode":0,"Time":"09:30","Days":"1111111","Repeat":1,"Action":3}
Timer2 {"Enable":1,"Mode":0,"Time":"23:00","Days":"1111111","Repeat":1,"Action":3}

on clock#timer=2 do backlog publish cmnd/tasmota_B165A/Power1 0; var1 1 endon  //set var1 to 1 at 930am
on clock#timer=1 do backlog publish cmnd/tasmota_B165A/Power1 0; var1 0 endon  //set var1 to 0 at 1100pm
on ina226-1#voltage>%var2% do publish cmnd/tasmota_B165A/Power1 %var1% endon  //set power1 to var1 (off if after 11pm on if after 930am
on ina226-1#voltage<%var2% do publish cmnd/tasmota_B165A/Power1 0 endon  //set power1 to off if voltage less than previous value
on ina226-1#voltage do var2 %value% endon  //update var2

This should work because Tasmota is sequential so the 3rd and 4th lines will trigger before var2 is updated. However, there is no hysteresis so you might get a lot of 'nuisance' tripping. It would help if you explained what the voltage is measuring
It's worth looking at transmit-sensor-value-only-when-a-delta-is-reached
Documentation (Wiki) for Tasmota

Documentation (Wiki) for Tasmota


From: Wyszków On <wyszk...@gmail.com>
Sent: Tuesday, June 10, 2025 17:32
To: Philip Knowles <knowles...@gmail.com>; TasmotaUsers <sonof...@googlegroups.com>
Subject: Re: What's wrong with my time-dependent rule?

Wyszków On

unread,
Jun 11, 2025, 7:48:35 AMJun 11
to TasmotaUsers
---------- Forwarded message ---------
Od: Wyszków On <wyszk...@gmail.com>
Date: śr., 11 cze 2025, 13:39
Subject: Re: What's wrong with my time-dependent rule?
To: Philip Knowles <knowles...@gmail.com>


Ok, now I have set Timer(s(, and have 2 rules, rule1 doesn't fire last condition (Voltage), rule2 works ok.
Where is the problem?

rule1 on clock#timer=2 do backlog Power1 0; var2 1 endon on clock#timer=1 do backlog Power1 0; var2 0; endon on INA226-1#Voltage > %Var7% do Power1 %Var2% endon

rule2 on System#Boot do backlog var1 120; var2 0; var8 %mem8%; var7 %mem7%; endon on INA226-1#Voltage < %var8% do sub1 1 endon on var1#State < 1 do backlog publish cmnd/tasmota_B8165A/Power1 0; var1 120; endon on Power1#state=0 do var8 %mem8% break

Laurent 

Philip Knowles

unread,
Jun 11, 2025, 3:42:06 PMJun 11
to Wyszków On, TasmotaUsers
You need to simplify the rule to test it.

You have mem7 and mem8 which never have a value set to them (but are used to set var7 and var 8) and var1 seems to be doing some form of countdown function. It would help if you explained what the INA was measuring and what process you are trying to control. You talk about a 'stored value' but what is that and where does it come from?

From: sonof...@googlegroups.com <sonof...@googlegroups.com> on behalf of Wyszków On <wyszk...@gmail.com>
Sent: Wednesday, June 11, 2025 12:48
To: TasmotaUsers <sonof...@googlegroups.com>

Wyszków On

unread,
Jun 12, 2025, 11:15:47 AMJun 12
to TasmotaUsers
---------- Forwarded message ---------
Od: Wyszków On <wyszk...@gmail.com>
Date: czw., 12 cze 2025, 17:12
Subject: Re: What's wrong with my time-dependent rule?
To: Philip Knowles <knowles...@gmail.com>


Ok Philip, will try:
mem7 and mem8 are set once outside scripts, as they are permanent. It is lower and higher voltage threshold.
What INA measures is 24V lead-acid battery voltage in solar plant.
Charging thresholds are controlled elsewhere.
What I try to manage with this ESP is switching on/off load to inverter.
Off when battery voltage falls below mem8 (23.7V) for 120 measurements (120s), on when battery is higher than mem7 (28.0V) but only between 9:30am and 11:00pm. (My battery is worn, so it makes sense to switch on load only when you may expect firm sunlight).

What may You propose in such case? Imho trick with schedule timers is on.

Laurent 

Philip Knowles

unread,
Jun 12, 2025, 3:55:31 PMJun 12
to Wyszków On, TasmotaUsers
OK. This doesn't do exactly what you want because it will switch on or off every 2 minutes based on the latest reading but it will stop it flip-flopping

on clock#timer=2 do backlog publish cmnd/tasmota_B165A/Power1 0; var1 1 endon  //set var1 to 1 at 930am
on clock#timer=1 do backlog publish cmnd/tasmota_B165A/Power1 0; var1 0 endon  //set var1 to 0 at 1100pm
on ina226-1#voltage>%mem7% do var2 %var1% endon  
on ina226-1#voltage<%mem8% do var2 0 endon  
on time#minute|2 do publish cmnd/tasmota_B165A/Power1 %var2% endon //every 2 minutes publish the latest value

You could use a Rule Timer
on ina226-1#voltage>%mem7% do backlog ruletimer1 120; var2 %var1% endon //start 2 minute timer - this might need to be a one-shot rule
on ina226-1#voltage<%mem7% do backlog ruletimer1 0; var2 0 endon //cancel timer if voltage below high threshold
on rules#timer=1 do publish cmnd/tasmota_B165A/Power1 %var2% endon //publish command if timer times out
on ina226-1#voltage<%mem8% do backlog ruletimer1 120 endon //start 2 minute timer - this might need to be a one-shot rule
on ina226-1#voltage>%mem8% do backlog ruletimer1 0 endon //cancel timer if voltage above low threshold
on rules#timer=2 do publish cmnd/tasmota_B165A/Power1 0 endon //publish command if timer times out

If I'm honest, if you have a failing battery, I would use the first set but use a 5 minute timer and do this
on clock#timer=2 do backlog publish cmnd/tasmota_B165A/Power1 0; var1 1 endon  //set var1 to 1 at 930am
on clock#timer=1 do backlog publish cmnd/tasmota_B165A/Power1 0; var1 0 endon  //set var1 to 0 at 1100pm
on ina226-1#voltage>%mem7% do var2 %var1% endon  
on ina226-1#voltage<%mem8% do publish cmnd/tasmota_B165A/Power1 0 endon  
on time#minute|5 do publish cmnd/tasmota_B165A/Power1 %var2% endon

This will switch the load off at the first point that it drops below the lower threshold but wait up to 5 minutes after it reaches the higher threshold before switching on


Sent: Thursday, June 12, 2025 16:15
To: TasmotaUsers <sonof...@googlegroups.com>
Subject: Fwd: What's wrong with my time-dependent rule?

Wyszków On

unread,
Jun 13, 2025, 9:12:48 AMJun 13
to Philip Knowles, TasmotaUsers


pt., 13 cze 2025, 15:05 użytkownik Wyszków On <wyszk...@gmail.com> napisał:
Hi Philip, 
Something is wrong in my compiled (for INA226 instead of INA219) firmware.

Now rule2 looks like this 
rule2 on System#Boot do backlog var1 120; var2 0; var8 %mem8%; var7 %mem7%; endon on INA226-1#Voltage < %var8% do sub1 1 endon on var1#State < 1 do backlog publish cmnd/tasmota_B8165A/Power1 0; var1 120; endon on INA226-1#Voltage > %var7% do backlog  Power1 %Var2%; endon on Power1#state=0 do var8 %mem8% endon

And console output is:
15:00:13.745 RUL: INA226-1#VOLTAGE > %VAR7% DO BACKLOG  POWER1 %VAR2%; ENDON ON POWER1#STATE=0 performs "endon on Power1#state=0 do"
15:00:13.753 MQT: stat/tasmota_63D2FB/RESULT = {"Command":"Unknown"}

What the hell is going on?

Laurent 

Philip Knowles

unread,
Jun 13, 2025, 10:55:07 AMJun 13
to Wyszków On, TasmotaUsers
You shouldn't have ; before endon


From: Wyszków On <wyszk...@gmail.com>
Sent: Friday, June 13, 2025 14:05

To: Philip Knowles <knowles...@gmail.com>; TasmotaUsers <sonof...@googlegroups.com>
Subject: Re: What's wrong with my time-dependent rule?
Hi Philip, 
Something is wrong in my compiled (for INA226 instead of INA219) firmware.

Now rule2 looks like this 
rule2 on System#Boot do backlog var1 120; var2 0; var8 %mem8%; var7 %mem7%; endon on INA226-1#Voltage < %var8% do sub1 1 endon on var1#State < 1 do backlog publish cmnd/tasmota_B8165A/Power1 0; var1 120; endon on INA226-1#Voltage > %var7% do backlog  Power1 %Var2%; endon on Power1#state=0 do var8 %mem8% endon

And console output is:
15:00:13.745 RUL: INA226-1#VOLTAGE > %VAR7% DO BACKLOG  POWER1 %VAR2%; ENDON ON POWER1#STATE=0 performs "endon on Power1#state=0 do"
15:00:13.753 MQT: stat/tasmota_63D2FB/RESULT = {"Command":"Unknown"}

What the hell is going on?

Laurent 

Wyszków On

unread,
Jun 15, 2025, 12:39:58 PMJun 15
to TasmotaUsers
---------- Forwarded message ---------
Od: Wyszków On <wyszk...@gmail.com>
Date: niedz., 15 cze 2025, 18:19
Subject: Re: What's wrong with my time-dependent rule?
To: Philip Knowles <knowles...@gmail.com>


Ok, removed ";" but it is still the same:

18:15:08.114 MQT: stat/tasmota_63D2FB/RESULT = {"Command":"Unknown"}
18:15:08.002 RUL: INA226-1#VOLTAGE > %VAR7% DO POWER1 %VAR2% ENDON ON POWER1#STATE=0 performs "endon on Power1#state=0 do"

Current rule2:
rule2 on System#Boot do backlog var1 120; var2 0; var8 %mem8%; var7 %mem7% endon on INA226-1#Voltage < %var8% do sub1 1 endon on var1#State < 1 do backlog publish cmnd/tasmota_B8165A/Power1 0; var1 120 endon on INA226-1#Voltage > %var7% do Power1 %Var2% endon on Power1#state=0 do var8 %mem8% endon

Tasmota v11.1.0.2 

Laurent 

Wyszków On

unread,
Jun 17, 2025, 10:24:51 AMJun 17
to Philip Knowles, TasmotaUsers
Hi Philip, 
Something is wrong in my compiled (for INA226 instead of INA219) firmware.

Now rule2 looks like this 
rule2 on System#Boot do backlog var1 120; var2 0; var8 %mem8%; var7 %mem7%; endon on INA226-1#Voltage < %var8% do sub1 1 endon on var1#State < 1 do backlog publish cmnd/tasmota_B8165A/Power1 0; var1 120; endon on INA226-1#Voltage > %var7% do backlog  Power1 %Var2%; endon on Power1#state=0 do var8 %mem8% endon

And console output is:
15:00:13.745 RUL: INA226-1#VOLTAGE > %VAR7% DO BACKLOG  POWER1 %VAR2%; ENDON ON POWER1#STATE=0 performs "endon on Power1#state=0 do"
15:00:13.753 MQT: stat/tasmota_63D2FB/RESULT = {"Command":"Unknown"}

What the hell is going on?

Laurent 

Philip Knowles

unread,
Jun 17, 2025, 4:36:30 PMJun 17
to Wyszków On, TasmotaUsers
I THINK I have compiled with INA226 and Polish language using TasmoCompiler

From: Wyszków On <wyszk...@gmail.com>
Sent: 17 June 2025 20:42

To: Philip Knowles <knowles...@gmail.com>; TasmotaUsers <sonof...@googlegroups.com>
Subject: Re: What's wrong with my time-dependent rule?
 


wt., 17 cze 2025, 21:41 użytkownik Wyszków On <wyszk...@gmail.com> napisał:
Philip, 
Could You tell what (exact, have problems browsing sources on phone) options I need to:
Use ina226 instead of ina219, 
Set language to Polish
?
To let me build current firmware.

Laurent 

niedz., 15 cze 2025, 19:07 użytkownik Philip Knowles <knowles...@gmail.com> napisał:
There's something strange happening in the rule
Instead of it performing Power1 %var2% it's doing "endon on Power1#state=0 do"
It may just be that Version 11.1 is over 3 years old and there may have been changes in the rule syntax since then


From: Wyszków On <wyszk...@gmail.com>
Sent: Sunday, June 15, 2025 17:19
To: Philip Knowles <knowles...@gmail.com>

Subject: Re: What's wrong with my time-dependent rule?
Ok, removed ";" but it is still the same:

18:15:08.114 MQT: stat/tasmota_63D2FB/RESULT = {"Command":"Unknown"}
18:15:08.002 RUL: INA226-1#VOLTAGE > %VAR7% DO POWER1 %VAR2% ENDON ON POWER1#STATE=0 performs "endon on Power1#state=0 do"

Current rule2:
rule2
on System#Boot do backlog var1 120; var2 0; var8 %mem8%; var7 %mem7% endon
on INA226-1#Voltage < %var8% do sub1 1 endon
on var1#State < 1 do backlog publish cmnd/tasmota_B8165A/Power1 0; var1 120 endon
on INA226-1#Voltage > %var7% do Power1 %Var2% endon
on Power1#state=0 do var8 %mem8% endon

Tasmota v11.1.0.2 

Laurent 
tasmotaINA226PL.bin

Wyszków On

unread,
Jun 18, 2025, 9:52:08 AMJun 18
to Philip Knowles, TasmotaUsers
wt., 17 cze 2025, 21:41 użytkownik Wyszków On <wyszk...@gmail.com> napisał:
Philip, 
Could You tell what (exact, have problems browsing sources on phone) options I need to:
Use ina226 instead of ina219, 
Set language to Polish
?
To let me build current firmware.

Laurent 

niedz., 15 cze 2025, 19:07 użytkownik Philip Knowles <knowles...@gmail.com> napisał:
There's something strange happening in the rule
Instead of it performing Power1 %var2% it's doing "endon on Power1#state=0 do"
It may just be that Version 11.1 is over 3 years old and there may have been changes in the rule syntax since then


From: Wyszków On <wyszk...@gmail.com>

Sent: Sunday, June 15, 2025 17:19
To: Philip Knowles <knowles...@gmail.com>
Subject: Re: What's wrong with my time-dependent rule?
Ok, removed ";" but it is still the same:

18:15:08.114 MQT: stat/tasmota_63D2FB/RESULT = {"Command":"Unknown"}
18:15:08.002 RUL: INA226-1#VOLTAGE > %VAR7% DO POWER1 %VAR2% ENDON ON POWER1#STATE=0 performs "endon on Power1#state=0 do"

Current rule2:
rule2
on System#Boot do backlog var1 120; var2 0; var8 %mem8%; var7 %mem7% endon
on INA226-1#Voltage < %var8% do sub1 1 endon
on var1#State < 1 do backlog publish cmnd/tasmota_B8165A/Power1 0; var1 120 endon
on INA226-1#Voltage > %var7% do Power1 %Var2% endon
on Power1#state=0 do var8 %mem8% endon

Tasmota v11.1.0.2 

Laurent 

Wyszków On

unread,
Jun 18, 2025, 2:28:10 PMJun 18
to Philip Knowles, TasmotaUsers
Hi Philip, 
Have compiled myself using Gitpod, with:
#undef USE_INA219
#define USE_INA226
#define MY_LANGUAGE pl_PL

Works, only didn't know how to produce gzipped firmware, as *.bin was too large. Used my Orange pi to gzip.

But it looks problem is still there :( 

Laurent 
firmware.bin.gz

Wyszków On

unread,
Jun 18, 2025, 2:45:12 PMJun 18
to Philip Knowles, TasmotaUsers
If I make #Voltage condition to be last in rule, it doesn't fire at all, "silence".
If there is condition after it, results as I have already sent.

Laurent 

Wyszków On

unread,
Jun 18, 2025, 3:36:15 PMJun 18
to Philip Knowles, TasmotaUsers
My current rules: 

rule1 on clock#timer=2 do backlog Power1 0; var2 0 endon on clock#timer=1 do backlog Power1 0; var2 1 endon on INA226-1#Voltage > %Var7% do Power1 %Var2% endon

rule2 on System#Boot do backlog var1 120; var2 0; var8 %mem8%; var7 %mem7% endon on INA226-1#Voltage < %var8% do sub1 1 endon on var1#State < 1 do backlog publish cmnd/tasmota_9F03C7/Power1 0; publish cmnd/tasmota_B8165A/Power1 0; publish cmnd/tasmota_9F03C7/Power1 1; var1 120 endon on var5 > %var7% do Power1 %Var2% endon on Power1#state=0 do var8 %mem8% endon

rule3 on ina226-1#voltage do var5 %value% endon

Rule3 works as expected, all other too, EXCEPT "on var5> %var7% do Power1 %var2% enddo" which doesn't fire ;(

Have tried:
var5, %var5%, var5#value in comparison 

Any ideas?

Laurent 

Philip Knowles

unread,
Jun 18, 2025, 4:19:21 PMJun 18
to Wyszków On, TasmotaUsers
Can you cut and paste the console output before and after an INA226 update?

From: Wyszków On <wyszk...@gmail.com>
Sent: 18 June 2025 20:35

Philip Knowles

unread,
Jun 18, 2025, 4:28:57 PMJun 18
to Wyszków On, TasmotaUsers
It needs to be
on var5#state>%var7% do...

From: Wyszków On <wyszk...@gmail.com>

Sent: 18 June 2025 20:35

Wyszków On

unread,
Jun 18, 2025, 4:41:15 PMJun 18
to Philip Knowles, TasmotaUsers
Found what looks to work: 

rule3 on ina226-1#voltage do backlog var5 %value%; if (%var5% > %var7%) Power1 %var2% endif endon

As I have read that IF is now supported.

Still interested in console output?

Laurent 

Philip Knowles

unread,
Jun 18, 2025, 5:11:53 PMJun 18
to Wyszków On, TasmotaUsers
I think the issue was not having on var5#state > %var7% do

From: Wyszków On <wyszk...@gmail.com>
Sent: 18 June 2025 21:40

Wyszków On

unread,
Jun 21, 2025, 12:04:10 PMJun 21
to Philip Knowles, TasmotaUsers
Thank You Philip, 
As I discovered existence of IF/ELSE/AND/OR (in stock Tasmota), I think I will redesign logic. 
Making more IF than ON xx.

Laurent 

Philip Knowles

unread,
Jun 22, 2025, 1:31:24 AMJun 22
to Wyszków On, TasmotaUsers
Fair enough but you still need to understand that if you are using a var in an on statement it's
on var1#state do
otherwise you may still hit issues


From: Wyszków On <wyszk...@gmail.com>
Sent: Saturday, June 21, 2025 5:03:51 PM
To: Philip Knowles <knowles...@gmail.com>
Cc: TasmotaUsers <sonof...@googlegroups.com>
Reply all
Reply to author
Forward
0 new messages