rules isue

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
Dick60
Normal user
Posts: 242
Joined: 11 Feb 2018, 17:35
Location: The Netherlands

rules isue

#1 Post by Dick60 » 09 Feb 2023, 16:39

ESP8266 with the latest firmware.
I am strugling with a rule. I have a Thermo Copler and it works fine. If a certain temp is in reach, I want to switch-on a switch.

Code: Select all

On Thermokoppel#Temperature do
If [Thermokoppel#Temperature]>23 and [Kachelswitch#State]=0
GPIO,4,1
Endif
Endon
If this Kachelswitch (GPIO4} switch is On and the temp is <20

Code: Select all

On Kachelswitch#State do
if [Kachelswitch#State]=0 and [Thermokoppel#Temperature]<21
GPIO,5,0
GPIO,15,1
GPIO,4,0
timerset,1,10
timerset,2,20
endif
EndOn

On Rules#Timer=1 do
GPIO,5,1
EndOn

On Rules#Timer=2 do
GPIO,15,0
EndOn
The problem is, I can switch on and off the GPIO4 on the temperature setting but adding the criteria the Status of the GPIO 4 (Kachelswitch) nothing happens.
Do I something wrong?

User avatar
Ath
Normal user
Posts: 3417
Joined: 10 Jun 2018, 12:06
Location: NL

Re: rules isue

#2 Post by Ath » 09 Feb 2023, 17:02

To explicitly check the current status of a GPIO pin, you can use the Plugin variables, as documented here
so that would turn out to be:

Code: Select all

On Kachelswitch#State do
  if [Plugin#GPIO#Pinstate#4]=0 and [Thermokoppel#Temperature]<21
    GPIO,5,0
    GPIO,15,1
    GPIO,4,0
    timerset,1,10
    timerset,2,20
  endif
EndOn
Also on that page there is a description of the use of %eventvalue%
That would be useful in this rule:

Code: Select all

On Thermokoppel#Temperature do
  If %eventvalue1%>23 and [Plugin#GPIO#Pinstate#4]=0
    GPIO,4,1
  Endif
Endon
The advantage being that the value at the time the event was generated is used by the rule, nut the current sensor value.

TL;DR: Reading through that entire Rules documentation page will teach you a few things about the use of rules :D
/Ton (PayPal.me)

Dick60
Normal user
Posts: 242
Joined: 11 Feb 2018, 17:35
Location: The Netherlands

Re: rules isue

#3 Post by Dick60 » 09 Feb 2023, 17:06

thanks, I give it a try. Keep you posted.

Dick60
Normal user
Posts: 242
Joined: 11 Feb 2018, 17:35
Location: The Netherlands

Re: rules isue

#4 Post by Dick60 » 10 Feb 2023, 10:03

The first part of the script is working fine

Code: Select all

On Thermokoppel#Temperature do
  If %eventvalue1%>23 and [Plugin#GPIO#Pinstate#4]=0
    GPIO,4,1
  Endif
Endon
but the second script does nothing. I simplified the second one to reduce the error magin.

Code: Select all

On Kachelswitch#State do
  If [Thermokoppel#Temperature]<22 and [Plugin#GPIO#Pinstate#4]=0
    GPIO,4,0
  Endif
Endon

TD-er
Core team member
Posts: 8643
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: rules isue

#5 Post by TD-er » 10 Feb 2023, 10:11

You try to set the pinstate of GPIO to 0 if it is already 0....
Or am I missing something?

Dick60
Normal user
Posts: 242
Joined: 11 Feb 2018, 17:35
Location: The Netherlands

Re: rules isue

#6 Post by Dick60 » 10 Feb 2023, 13:41

Sorry, my mistake I couldn't copy the script so I retyped it. The real situation is:

Code: Select all

On Kachelswitch#State do
  If [Thermokoppel#Temperature]<22 and [Plugin#GPIO#Pinstate#4]=1
    GPIO,4,0
  Endif
Endon
I expected Pin 4 change to 0 as soon as the temp is below 22. but that is not what happens. Also no reaction in my LOG.

User avatar
Ath
Normal user
Posts: 3417
Joined: 10 Jun 2018, 12:06
Location: NL

Re: rules isue

#7 Post by Ath » 10 Feb 2023, 13:57

Dick60 wrote: 10 Feb 2023, 13:41

Code: Select all

On Kachelswitch#State do
  If [Thermokoppel#Temperature]<22 and [Plugin#GPIO#Pinstate#4]=1
    GPIO,4,0
  Endif
Endon
I expected Pin 4 change to 0 as soon as the temp is below 22. but that is not what happens. Also no reaction in my LOG.
That event will only be executed if the value of Kachelswitch#State changes.
Maybe it's better to add this check to the On Thermokoppel#Temperature do event

Code: Select all

On Thermokoppel#Temperature do
  If %eventvalue1%>23 and [Plugin#GPIO#Pinstate#4]=0
    GPIO,4,1
  Endif
  If %eventvalue1%<22 and [Plugin#GPIO#Pinstate#4]=1
    GPIO,4,0
  Endif
Endon
/Ton (PayPal.me)

Dick60
Normal user
Posts: 242
Joined: 11 Feb 2018, 17:35
Location: The Netherlands

Re: rules isue

#8 Post by Dick60 » 10 Feb 2023, 14:24

Thanks ATH, that did the job. Now it works. :lol:

bonti69
Normal user
Posts: 119
Joined: 08 Apr 2021, 12:16

Re: rules isue

#9 Post by bonti69 » 11 Feb 2023, 20:36

Hello again,
Me too same kind of problem.
ADC is monitoring my solar battery. I want to on/off some relays according to the voltage.
Rule is:

On [Baterie#custom1]<11.5 do
GPIO,5,0
Endon
On [Baterie#custom1]>12.5 Do
GPIO,5,1
Endon
On [Baterie#custom1]<11.0 do
GPIO,15,0
Endon
On [Baterie#custom1]>12.6 Do
GPIO,15,1
Endon

Works fine only the gpio5 command , gpio15 does nothing, in log no event regarding threshold for gpio15. I'm confused... seems so simple
Task Baterie has 5 seconds interval, for testing purposes, later I will increase to few minutes...

bonti69
Normal user
Posts: 119
Joined: 08 Apr 2021, 12:16

Re: rules isue

#10 Post by bonti69 » 11 Feb 2023, 20:46

Solved
Created a new task Bat on analog input

Code: Select all

On [Baterie#custom1]<11.5 do
GPIO,5,0
Endon
On [Baterie#custom1]>12.5 Do
GPIO,5,1
Endon
On [Bat#custom2]<11.0 do
GPIO,15,0
Endon
On [Bat#custom2]>12.6 Do
GPIO,15,1
Endon
Somehow not very intuitive, needs a new task, I have the feeling could be better solution...
Is there a command to enable/ disable a rule? ... something like : ruleset1,1 or ruleset1, 0 ...
Not all the rules : Rules enabled (1) or rules disabled (0) Rules,<1/0> , a specific rule .
Last edited by bonti69 on 11 Feb 2023, 21:07, edited 1 time in total.

User avatar
Ath
Normal user
Posts: 3417
Joined: 10 Jun 2018, 12:06
Location: NL

Re: rules isue

#11 Post by Ath » 11 Feb 2023, 21:04

bonti69 wrote: 11 Feb 2023, 20:36 Hello again,
Me too same kind of problem.
ADC is monitoring my solar battery. I want to on/off some relays according to the voltage.
Rule is:

On [Baterie#custom1]<11.5 do
GPIO,5,0
Endon
On [Baterie#custom1]>12.5 Do
GPIO,5,1
Endon
On [Baterie#custom1]<11.0 do
GPIO,15,0
Endon
On [Baterie#custom1]>12.6 Do
GPIO,15,1
Endon

Works fine only the gpio5 command , gpio15 does nothing, in log no event regarding threshold for gpio15. I'm confused... seems so simple
Task Baterie has 5 seconds interval, for testing purposes, later I will increase to few minutes...
There are 2 big issues here:
1) The syntax is wrong
"On [Baterie#custom1]<11.5 do" is processed replacing variables, and will be parsed something like: "on 10<11.5 do" and then stored in Cache, so will always end up being true...
should be written like:
On Baterie#custom1<11.5 do

2) Because of optimized Rules processing, after a matching rule is handled, rules processing for the event is stopped

A more efficient way to handle this would be:

Code: Select all

On Baterie#custom1 do
  If [Baterie#custom1]<11.5
    GPIO,5,0
  Endif
  If [Baterie#custom1]>12.5
    GPIO,5,1
  Endif
  If [Baterie#custom1]<11.0
    GPIO,15,0
  Endif
  If [Baterie#custom1]>12.6
    GPIO,15,1
  Endif
Endon
So:
a) A single rule (event handler) to match all "Baterie#Custom" values
b) Extendable with as much logic you need :)
/Ton (PayPal.me)

bonti69
Normal user
Posts: 119
Joined: 08 Apr 2021, 12:16

Re: rules isue

#12 Post by bonti69 » 11 Feb 2023, 21:14

Thank you , Ath
Works fine
Missing elementary school :oops:

User avatar
Ath
Normal user
Posts: 3417
Joined: 10 Jun 2018, 12:06
Location: NL

Re: rules isue

#13 Post by Ath » 11 Feb 2023, 21:24

bonti69 wrote: 11 Feb 2023, 21:14 Missing elementary school :oops:
There's a solution for that: https://espeasy.readthedocs.io/en/lates ... Rules.html :lol:
/Ton (PayPal.me)

bonti69
Normal user
Posts: 119
Joined: 08 Apr 2021, 12:16

Re: rules isue

#14 Post by bonti69 » 11 Feb 2023, 21:35

I read the book, fast forward actually
I want to propose some feature (Tasmota has):
Possibility to enable /disable rules independently

rule1,0 or rule1,1
rule2,0 or rule2,1
rule3,0 or rule3,1
rule4,0 or rule4,1

Commands also available via http, mqtt

In case of remote device would be very helpful

User avatar
Ath
Normal user
Posts: 3417
Joined: 10 Jun 2018, 12:06
Location: NL

Re: rules isue

#15 Post by Ath » 11 Feb 2023, 22:17

That's not going to happen, has been discussed before, doesn't seem useful, or needed, for ESPEasy, as rules don't have an order or index.
/Ton (PayPal.me)

bonti69
Normal user
Posts: 119
Joined: 08 Apr 2021, 12:16

Re: rules isue

#16 Post by bonti69 » 13 Feb 2023, 08:23

I just upgraded firmware to Build: ESP_Easy_mega_20221224_normal_ESP8266_4M1M Dec 24 2022. I have a dummy device which collect data from sensors and send to mqtt controller every 5 minutes. Dummy doesn't work anymore. All values are 0.0. Something like that:

Code: Select all

On System#Boot do 
TaskValueSet 12,1,[bmp#Temperature]
TaskValueSet 12,2,[bmp#Pressure]
TaskValueSet 12,3,[ds#temp]
timerSet,1,60
endon

On Rules#Timer=1 do
TaskValueSet 12,1,[bmp#Temperature]
TaskValueSet 12,2,[bmp#Pressure]
TaskValueSet 12,3,[ds#temp]
timerSet,1,60
endon
Are some synthax issues?
Screenshot 2023-02-13 at 09-24-41 WemosD1R2.png
Screenshot 2023-02-13 at 09-24-41 WemosD1R2.png (7.82 KiB) Viewed 2866 times

User avatar
Ath
Normal user
Posts: 3417
Joined: 10 Jun 2018, 12:06
Location: NL

Re: rules isue

#17 Post by Ath » 13 Feb 2023, 08:48

Are the "bmp" and "ds" tasks still enabled, and showing proper values?
/Ton (PayPal.me)

bonti69
Normal user
Posts: 119
Joined: 08 Apr 2021, 12:16

Re: rules isue

#18 Post by bonti69 » 13 Feb 2023, 10:13

yes, all works fine, just firmware update

Code: Select all

35116932: Scheduler stats: (called/tasks/max_length/idle%) 188562/1906/14/80.51
35120197: DS: SP: 97,0,55,5,7f,a5,81,66,a3,OK,1,32,142
35120199: DS : Temperature: 9.4 (28-1f-28-07-d6-01-3c-30 [DS18B20])
35120211: EVENT: ds#temp=9.4
35120216: EVENT: ds#temp=9.4 Processing time:6 milliSeconds
35122238: BMP : Temperature: 9.1
35122239: BMP : Barometric Pressure: 1022.7
35122252: EVENT: bmp#Temperature=9.1
35122258: EVENT: bmp#Temperature=9.1 Processing time:5 milliSeconds
35122265: EVENT: bmp#Pressure=1022.7
35122270: EVENT: bmp#Pressure=1022.7 Processing time:6 milliSeconds
35130197: DS: SP: 97,0,55,5,7f,a5,81,66,a3,OK,1,33,142
35130199: DS : Temperature: 9.4 (28-1f-28-07-d6-01-3c-30 [DS18B20])
35130213: EVENT: ds#temp=9.4
35130218: EVENT: ds#temp=9.4 Processing time:6 milliSeconds
35132237: BMP : Temperature: 9.1
35132239: BMP : Barometric Pressure: 1022.7
35132252: EVENT: bmp#Temperature=9.1
35132258: EVENT: bmp#Temperature=9.1 Processing time:6 milliSeconds
35132264: EVENT: bmp#Pressure=1022.7
35132270: EVENT: bmp#Pressure=1022.7 Processing time:5 milliSeconds
35140200: DS: SP: 97,0,55,5,7f,a5,81,66,a3,OK,1,32,141
35140202: DS : Temperature: 9.4 (28-1f-28-07-d6-01-3c-30 [DS18B20])
35140213: EVENT: ds#temp=9.4
35140219: EVENT: ds#temp=9.4 Processing time:5 milliSeconds
35142241: BMP : Temperature: 9.1
35142243: BMP : Barometric Pressure: 1022.7
35142325: EVENT: bmp#Temperature=9.1
35142331: EVENT: bmp#Temperature=9.1 Processing time:6 milliSeconds
35142337: EVENT: bmp#Pressure=1022.7
35142342: EVENT: bmp#Pressure=1022.7 Processing time:6 milliSeconds
35146042: WD : Uptime 586 ConnectFailures 0 FreeMem 17328 WiFiStatus WL_CONNECTED 3 ESPeasy internal wifi status: Conn. IP Init
35146931: LoopStats: shortestLoop: 94 longestLoop: 7303773 avgLoopDuration: 155.33 loopCounterMax: 319148 loopCounterLast: 187462
35146932: Scheduler stats: (called/tasks/max_length/idle%) 187462/1902/14/79.57
35147192: Dummy: value 1: 0.0
35147194: Dummy: value 2: 0.0
35147195: Dummy: value 3: 0.0
35147197: Dummy: value 4: 0
35147218: MQTT : u9149f/dc3/t1 0.0
35147221: MQTT : u9149f/dc3/p1 0.0
35147224: MQTT : u9149f/dc3/ds1 0.0
35147227: MQTT : u9149f/dc3/custom1 0
35147234: EVENT: dummy#All=0.0,0.0,0.0,0
35147239: EVENT: dummy#All=0.0,0.0,0.0,0 Processing time:6 milliSeconds
35150203: DS: SP: 96,0,55,5,7f,a5,81,66,e0,OK,1,33,142
35150205: DS : Temperature: 9.4 (28-1f-28-07-d6-01-3c-30 [DS18B20])
35150216: EVENT: ds#temp=9.4
35150222: EVENT: ds#temp=9.4 Processing time:5 milliSeconds
35152238: BMP : Temperature: 9.1
35152240: BMP : Barometric Press
Screenshot 2023-02-13 at 11-11-32 WemosD1R2.png
Screenshot 2023-02-13 at 11-11-32 WemosD1R2.png (204.57 KiB) Viewed 2853 times

bonti69
Normal user
Posts: 119
Joined: 08 Apr 2021, 12:16

Re: rules isue

#19 Post by bonti69 » 13 Feb 2023, 10:34

rolled back firmware ,to Build: ESP_Easy_mega_20211224_normal_ESP8266_4M1M Dec 24 2021... works again
Attachments
Screenshot 2023-02-13 at 11-32-35 WemosD1R2.png
Screenshot 2023-02-13 at 11-32-35 WemosD1R2.png (197.15 KiB) Viewed 2847 times

TD-er
Core team member
Posts: 8643
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: rules isue

#20 Post by TD-er » 13 Feb 2023, 10:41

Hmm, I don't see why it shouldn't work...
My first idea was that you may need to check "Allow TaskValueSet on all plugins" on the Tools->Advanced page, but you are setting a value to a dummy task, so that should not be a problem here.

Also using a space instead of a comma should still be possible in the rules.

So the only thing that may come to mind here is that you may have >1 entry for the "On Rules#Timer=1 do" and "On System#Boot do " in your rules.
Do you?

User avatar
Ath
Normal user
Posts: 3417
Joined: 10 Jun 2018, 12:06
Location: NL

Re: rules isue

#21 Post by Ath » 13 Feb 2023, 10:42

It seems your rules are not executed, are there any other rules for system#boot or rules#timer=1 ?
If so, then combine them into a single rule, because since summer 2022 the rules engine has gotten some optimizations, with a major improvement that once an event is handled, the rules file is not parsed any further, so only one event-instance will be executed.
/Ton (PayPal.me)

bonti69
Normal user
Posts: 119
Joined: 08 Apr 2021, 12:16

Re: rules isue

#22 Post by bonti69 » 13 Feb 2023, 13:35

Actually I have some rule in ruleset2, the dummy task was in ruleset3, but was disabled...

Code: Select all

//on Clock#Time=All,**:** do
//lcdcmd,on
//timerSet,1,5
endon
//on Rules#Timer=1 do
//lcdcmd,off
endon
Maybe the new builds didn't like it this way :D
this module share the same lcd with environemental sensor, most of the time, and a voltage/current sensor ina219 on longpress of a switch, which I used to measure power of various devices, to detect the energy vampires. A small relay engaged used about 1W of power for energizing coil. 3 relays=3W wasted...So I'm moving to Mosfet's.
robojax_e-switch_IRF5305S_schematic.jpg
robojax_e-switch_IRF5305S_schematic.jpg (37.49 KiB) Viewed 2808 times
Thank you for your time, Ath, appreciate your help
Respect, chapeau!
Last edited by bonti69 on 13 Feb 2023, 16:07, edited 1 time in total.

TD-er
Core team member
Posts: 8643
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: rules isue

#23 Post by TD-er » 13 Feb 2023, 13:48

You didn't comment out the "endon".
I think that's what causing issues here?

bonti69
Normal user
Posts: 119
Joined: 08 Apr 2021, 12:16

Re: rules isue

#24 Post by bonti69 » 13 Feb 2023, 13:55

Also thanks TD-er, magnificent job
I parse here all the rules from device, just in case...
ruleset1

Code: Select all

on system#boot do
let,2,0
TaskEnable,5
endon
//on Virtualfosa#custom1=1 do
TaskDisable,5
TaskDisable,8
timerSet,2,0
TaskEnable,9
lcdcmd,on
LCD,1,1,"ATENTIE"
LCD,2,1,"Pompa ON   %systime%"
LCD,3,1, "Verifica pompa fosa"
LCD,4,1,
endon
//on Virtualfosa#custom1=0 do
//lcdcmd,on
LCD,4,1,"Pompa OFF  %systime%"
endon
on switch#state=3 do  //doublepress revine lcdtemp
TaskEnable,5
endon
//on switch#state=3 do
lcdcmd,on
LCD,1,1,"WARNING"
LCD,2,1,"Firealarm ON %systime%"
LCD,3,1, "CHECK WATER PUMPS"
//endon
//on switch#state=0 do
gpio,14,0
//publish ,u9149f/568/cmnd/power ,0                    //nu merge nefiind conectat la server mqtt
//SendToHTTP ,192.168.4.31,80,"/control?cmd=GPIO,5,0" //another espeasy device
//SendToHTTP ,192.168.4.50,80,"/cm?cmnd=Power%20Off" //another tasmota device,uneori rateaza comanda
endon
//on switch#state=1 do
gpio,14,1
//publish ,u9149f/568/cmnd/power,1                    //nu merge nefiind conectat la server mqtt
//SendToHTTP ,192.168.4.31,80,"/control?cmd=GPIO,5,1" //another espeasy device
//SendToHTTP ,192.168.4.50,80,"/cm?cmnd=Power%20On" //another tasmota device,uneori rateaza comanda
endon
ruleset2

Code: Select all

//on releu1#out0=1 do
//on Virtualfosa#custom1=0 do
//let,3,0
timerSet,3,1
let,3,=!%v3% // flip state
if %v3%=1
lcdcmd,on
else 
lcdcmd,off
endif
endon

On Rules#Timer=3 do
let,3,=!%v3% // flip state
if %v3%=1
lcdcmd,on
else 
lcdcmd,off
endif
timerSet,3,1
endon
//on releu1#out0=0 do //on doubleclick, stop blinking
timerSet,3,0
endon

//on Clock#Time=All,**:** do
//lcdcmd,on
//timerSet,1,5
endon
//on Rules#Timer=1 do
//lcdcmd,off
endon
ruleset3

Code: Select all

On System#Boot do 
TaskValueSet 12,1,[bmp#Temperature]
TaskValueSet 12,2,[bmp#Pressure]
TaskValueSet 12,3,[ds#temp]
TaskValueSet 12,4,[VirtualOUTfosa#custom1]
timerSet,1,60
endon

On Rules#Timer=1 do
TaskValueSet 12,1,[bmp#Temperature]
TaskValueSet 12,2,[bmp#Pressure]
TaskValueSet 12,3,[ds#temp]
TaskValueSet 12,4,[VirtualOUTfosa#custom1]
timerSet,1,10
endon
ruleset4

Code: Select all

on switch#state=11 do  //longpress 
let,2,=!%v2% // flip state
if %v2%=1
// enable lcdpower,ina
TaskEnable,7
TaskEnable,8
TaskDisable,5
timerSet,2,120
else
TaskEnable,5
TaskDisable,8
TaskDisable,7
 endif
endon
on Rules#Timer=2 do  //switch back to lcdtemp after 2 minutes
TaskEnable,5
TaskDisable,8
TaskDisable,7
endon
A lots of unused lines, trial&error, forgotten...
Needs time and desire to clean up, sort things.
Maybe the new build is more demanding, I see it offer suggestions during writing.
My mistake,sorry :oops:

bonti69
Normal user
Posts: 119
Joined: 08 Apr 2021, 12:16

Re: rules isue

#25 Post by bonti69 » 13 Feb 2023, 16:04

Everything OK, back to latest firmware, cleaned the rules
GOOD TO KNOW
DO NOT have same instructions on different rules:
on system#boot do
On Rules#Timer=1 do
on switch#state=11 do

etc
Not very happy with that, might be a reason, anyway...
I think that should be advertise before updating certain firmware, maybe it is ,but who reads the readme.txt 8-)

TD-er
Core team member
Posts: 8643
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: rules isue

#26 Post by TD-er » 13 Feb 2023, 16:12

To be honest, I think this behavior was more like a bug than a feature.
Problem is when someone has forgotten some event handler already exists in the rules, then it is probably also forgotten what is done there.

Not sure how much it will add to the binary size if I actively try to pre-parse the rules to notify the user about possible mistakes.
But given that I can think of lots and lots of possible mistakes, I can imagine it will be adding a lot of code as this is only one possible issue.

Another thing that has effectively been changed on the rules parsing is when having multiple rules blocks which can match the same event.
So not just the same event string between the on...do part.

For example:

Code: Select all

on switch#state=11 do

endon
on switch#state do

endon
Both will match the event "switch#state=11".
But is it expected behavior for a user that they both matched?
Not naming it a "bug" or a "feature", but just asking whether it is "expected"?

bonti69
Normal user
Posts: 119
Joined: 08 Apr 2021, 12:16

Re: rules isue

#27 Post by bonti69 » 13 Feb 2023, 17:39

Ath wrote: 13 Feb 2023, 10:42 It seems your rules are not executed, are there any other rules for system#boot or rules#timer=1 ?
If so, then combine them into a single rule, because since summer 2022 the rules engine has gotten some optimizations, with a major improvement that once an event is handled, the rules file is not parsed any further, so only one event-instance will be executed.
If I understand properly, Ath mentioned "since summer 2022 the rules engine has gotten some optimizations, with a major improvement that once an event is handled, the rules file is not parsed any further, so only one event-instance will be executed."
My skills on programming are so limited, for me was a challenge to do some things with ESP, little things, so I 'm not taking the right to make suggestion.
Anyway, What I am expected, intuitive way, through my own perception and expectations:
You have four rules
Make it enable/disable independently.Via console,http,mqtt. Needs only 4(four)bits . Like tasmota. rule1,on...rule2,0
Prioritize the rule according to the index. Rule1 first, rule2 second, etc
When "stranger things" happens, disabling the rules ,one by one, helps to isolate the problem. You have a remote device, via enabling/disabling the rule you can change the whole behaviour of the device. Trust, believe...

At last, do a small favour to all the espeasy users. In device page, when you hover the mouse over switch#state icon, make the gpio toggle, if this is driving a relay, for example
click.jpg
click.jpg (44.52 KiB) Viewed 2761 times
Keep going the good work
Regarding the

Code: Select all

on switch#state=11 do

endon
on switch#state do

endon
I think "switch#state" happens first , so "on switch#state do...endon" is launched. If you keep pressing the button, event "switch#state=11" is accomplished so "on switch#state=11 do...something...endon" must be executed. Clean. No fuss. Plenty of time to think about...longpress means seconds

bonti69
Normal user
Posts: 119
Joined: 08 Apr 2021, 12:16

Re: rules isue

#28 Post by bonti69 » 14 Feb 2023, 18:43

Analog input is monitoring solar battery. When voltage drop under certain level, disconnect load. When voltage rise above high level, connect load. But after some time, checking the voltage is not below high level, clouds etc.
Rule:

Code: Select all

On Bat#voltage do
  If [Bat#voltage]<11.5
    GPIO,5,0
  Endif
  If [Bat#voltage]>12.5
  TimerSet,1,120
  Endif
  On  Rules#Timer=1
  If [Bat#voltage]>=12.5
    GPIO,5,1
  Endif
  Endon
Endon
error
Screenshot 2023-02-14 at 19-44-19 ESP_Easy pocio.png
Screenshot 2023-02-14 at 19-44-19 ESP_Easy pocio.png (53.67 KiB) Viewed 2682 times
Bat#voltage has 10s interval, during tests... means every 10s the timer is set to 120s?

User avatar
Ath
Normal user
Posts: 3417
Joined: 10 Jun 2018, 12:06
Location: NL

Re: rules isue

#29 Post by Ath » 14 Feb 2023, 19:16

bonti69 wrote: 14 Feb 2023, 18:43 Analog input is monitoring solar battery. When voltage drop under certain level, disconnect load. When voltage rise above high level, connect load. But after some time, checking the voltage is not below high level, clouds etc.
Rule:

Code: Select all

On Bat#voltage do
  If [Bat#voltage]<11.5
    GPIO,5,0
  Endif
  If [Bat#voltage]>12.5
  TimerSet,1,120
  Endif
  On  Rules#Timer=1
  If [Bat#voltage]>=12.5
    GPIO,5,1
  Endif
  Endon
Endon
You have a few syntax errors in your rule, and also some points of improvement:

Code: Select all

On Bat#voltage do
  If %eventvalue1%<11.5 // Use %eventvalue1% where possible
    GPIO,5,0
  Endif
  If %eventvalue1%>12.5
    TimerSet,1,120
  Endif
  // On  Rules#Timer=1 <- Can't have nested rules, and the Do is missing
  //   If [Bat#voltage]>=12.5
  //     GPIO,5,1
  //   Endif
  // Endon
Endon

On Rules#Timer=1 Do
  If [Bat#voltage]>=12.5
    GPIO,5,1
  Endif
Endon
(Nesting possibly caused by a copy/paste error?)
Tried to modify it into what it is probably supposed to do
/Ton (PayPal.me)

bonti69
Normal user
Posts: 119
Joined: 08 Apr 2021, 12:16

Re: rules isue

#30 Post by bonti69 » 14 Feb 2023, 20:14

Thanks, Ath... great teacher
At the moment I'm in trial&error phase. I have two tasks on analog input, Baterie#custom1 , with 300s interval, also send value to mqtt server and another one, same ADC, with 5-10s interval, for experiments, for testing, Bat#voltage.
Screenshot 2023-02-14 at 21-21-36 ESP_Easy pocio.png
Screenshot 2023-02-14 at 21-21-36 ESP_Easy pocio.png (137.88 KiB) Viewed 2671 times
A working code is:

Code: Select all

On Bat#voltage do
  If [Bat#voltage]<11.5
    GPIO,5,0
  Endif
Endon
On Baterie#custom1 do
  If [Baterie#custom1]>12.5
    GPIO,5,1
  Endif
Endon
I'm a little bit confused, I think rules on latest builds are requesting more precision, synthax... or maybe a long vacation I took last months.
Good point to use %eventvalue% instead of [event#value]
Actually the device has 3 outputs, driving relays (actually mosfets) , on a remote location, power delivered by a small solar system, panels,charge controller,lead battery. The solar controller, shuts down the load at about 11v, to protect the battery. The ESP, will monitor the battery voltage and will connect/disconnect the loads according to the voltage implemented in rules. The loads are actually 2 ip cameras one NVR. When the voltage is up all three are awake, sun goes, voltage drop , first goes nvr off, then camera 2, at last camera 1. There is a backup 12V grid connected, for long winter cloudy days. With "rules,0" sent via mqtt to ESP, the rules are disabled, and the outputs can be activated regardless of solar voltage, for a glimpse on the location.
20230214_211109_cr.jpg
20230214_211109_cr.jpg (847.4 KiB) Viewed 2673 times
Schematics
20230214_211626.jpg
20230214_211626.jpg (400.9 KiB) Viewed 2672 times

bonti69
Normal user
Posts: 119
Joined: 08 Apr 2021, 12:16

Re: rules isue

#31 Post by bonti69 » 14 Feb 2023, 20:43

I think even your scripts does not work

Code: Select all

⚙Config
💬Controllers
📌Hardware
🔌Devices
⧴Rules
✉Notifications
🔧Tools
Log
Logging: Debug (3)
4820748: timeStringToSeconds: '12' --> invalid
4820749: timeStringToSeconds: '12' --> invalid
4820750: conditionMatch: '12.76>12.5' --> '12.76' > '12.5' --> true (12.76 > 12.5)
4820751: conditionMatchExtended: true '12.76>12.5'
4820751: Lev.1: [if true]=true
4820753: ACT : TimerSet,1,120
4820756: Command: TimerSet
4820756: TimerSet,1,120
4820757: Par1: 1 Par2: 120 Par3: 0 Par4: 0 Par5: 0
4820833: EVENT: bat#voltage=12.76 Processing time:96 milliSeconds
4830742: timeStringToSeconds: '12' --> invalid
4830742: timeStringToSeconds: '11' --> invalid
4830745: conditionMatch: '12.76<11.5' --> '12.76' < '11.5' --> false (12.76 < 11.5)
4830745: conditionMatchExtended: false '12.76<11.5'
4830745: Lev.1: [if false]=false
4830749: timeStringToSeconds: '12' --> invalid
4830749: timeStringToSeconds: '12' --> invalid
4830751: conditionMatch: '12.76>12.5' --> '12.76' > '12.5' --> true (12.76 > 12.5)
4830751: conditionMatchExtended: true '12.76>12.5'
4830751: Lev.1: [if true]=true
4830753: ACT : TimerSet,1,120
4830754: Command: TimerSet
4830754: TimerSet,1,120
4830755: Par1: 1 Par2: 120 Par3: 0 Par4: 0 Par5: 0
4830761: EVENT: bat#voltage=12.76 Processing time:25 milliSeconds
4831704: BMP280 : Address: 0x76
4831707: BMP280 : Temperature: 14.2
4831708: BMP280 : Barometric Pressure: 1016.3
4831724: MQTT : u9149f/7d2/t1 14.2
4831727: MQTT : u9149f/7d2/h1 0
4831730: MQTT : u9149f/7d2/p1 1016.3
4831736: EVENT: BMP#t1=14.2
4831739: EVENT: BMP#t1=14.2 Processing time:3 milliSeconds
4831750: EVENT: BMP#h1=0
4831752: EVENT: BMP#h1=0 Processing time:3 milliSeconds
4831754: EVENT: BMP#p1=1016.3
4831757: EVENT: BMP#p1=1016.3 Processing time:2 milliSeconds
4840742: timeStringToSeconds: '12' --> invalid
4840742: timeStringToSeconds: '11' --> invalid
4840744: conditionMatch: '12.75<11.5' --> '12.75' < '11.5' --> false (12.75 < 11.5)
4840744: conditionMatchExtended: false '12.75<11.5'
4840745: Lev.1: [if false]=false
4840748: timeStringToSeconds: '12' --> invalid
4840749: timeStringToSeconds: '12' --> invalid
4840750: conditionMatch: '12.75>12.5' --> '12.75' > '12.5' --> true (12.75 > 12.5)
4840751: conditionMatchExtended: true '12.75>12.5'
4840751: Lev.1: [if true]=true
4840753: ACT : TimerSet,1,120
4840754: Command: TimerSet
4840754: TimerSet,1,120
4840755: Par1: 1 Par2: 120 Par3: 0 Par4: 0 Par5: 0
4840759: EVENT: bat#voltage=12.75 Processing time:23 milliSeconds
4842242: WD : Uptime 81 ConnectFailures 0 FreeMem 18216 WiFiStatus WL_CONNECTED 3 ESPeasy internal wifi status: Conn. IP Init
4843131: LoopStats: shortestLoop: 94 longestLoop: 906367 avgLoopDuration: 151.57 loopCounterMax: 319148 loopCounterLast: 192037
4843131: Scheduler stats: (called/tasks/max_length/idle%) 192037/1923/14/82.16
4850737: timeStringToSeconds: '12' --> invalid
4850737: timeStringToSeconds: '11' --> invalid
4850739: conditionMatch: '12.73<11.5' --> '12.73' < '11.5' --> false (12.73 < 11.5)
4850739: conditionMatchExtended: false '12.73<11.5'
4850739: Lev.1: [if false]=false
4850743: timeStringToSeconds: '12' --> invalid
4850743: timeStringToSeconds: '12' --> invalid
4850745: conditionMatch: '12.73>12.5' --> '12.73' > '12.5' --> true (12.73 > 12.5)
4850745: conditionMatchExtended: true '12.73>12.5'
4850745: Lev.1: [if true]=true
4850747: ACT : TimerSet,1,120
4850749: Command: TimerSet
4850749: TimerSet,1,120
4850749: Par1: 1 Par2: 120 Par3: 0 Par4: 0 Par5: 0
4850754: EVENT: bat#voltage=12.73 Processing time:23 milliSeconds
4855688: EVENT: Clock#Time=Tue,21:37
4855690: EVENT: Clock#Time=Tue,21:37 Processing time:2 milliSeconds
4860739: timeStringToSeconds: '12' --> invalid
4860739: timeStringToSeconds: '11' --> invalid
4860741: conditionMatch: '12.75<11.5' --> '12.75' < '11.5' --> false (12.75 < 11.5)
4860741: conditionMatchExtended: false '12.75<11.5'
4860741: Lev.1: [if false]=false
4860745: timeStringToSeconds: '12' --> invalid
4860745: timeStringToSeconds: '12' --> invalid
4860747: conditionMatch: '12.75>12.5' --> '12.75' > '12.5' --> true (12.75 > 12.5)
4860747: conditionMatchExtended: true '12.75>12.5'
4860748: Lev.1: [if true]=true
4860749: ACT : TimerSet,1,120
4860751: Command: TimerSet
4860751: TimerSet,1,120
4860751: Par1: 1 Par2: 120 Par3: 0 Par4: 0 Par5: 0
4860756: EVENT: bat#voltage=12.75 Processing time:23 milliSeconds
4870779: timeStringToSeconds: '12' --> invalid
4870780: timeStringToSeconds: '11' --> invalid
4870782: conditionMatch: '12.75<11.5' --> '12.75' < '11.5' --> false (12.75 < 11.5)
4870782: conditionMatchExtended: false '12.75<11.5'
4870782: Lev.1: [if false]=false
4870786: timeStringToSeconds: '12' --> invalid
4870786: timeStringToSeconds: '12' --> invalid
4870788: conditionMatch: '12.75>12.5' --> '12.75' > '12.5' --> true (12.75 > 12.5)
4870788: conditionMatchExtended: true '12.75>12.5'
4870788: Lev.1: [if true]=true
4870790: ACT : TimerSet,1,120
4870792: Command: TimerSet
4870792: TimerSet,1,120
4870793: Par1: 1 Par2: 120 Par3: 0 Par4: 0 Par5: 0
4870799: EVENT: bat#voltage=12.75 Processing time:25 milliSeconds
4872243: WD : Uptime 81 ConnectFailures 0 FreeMem 18216 WiFiStatus WL_CONNECTED 3 ESPeasy internal wifi status: Conn. IP Init
4873131: LoopStats: shortestLoop: 94 longestLoop: 906367 avgLoopDuration: 150.69 loopCounterMax: 319148 loopCounterLast: 193136
4873131: Scheduler stats: (called/tasks/max_length/idle%) 193136/1918/14/82.31
4880737: timeStringToSeconds: '12' --> invalid
4880737: timeStringToSeconds: '11' --> invalid
4880739: conditionMatch: '12.73<11.5' --> '12.73' < '11.5' --> false (12.73 < 11.5)
4880739: conditionMatchExtended: false '12.73<11.5'
4880739: Lev.1: [if false]=false
4880743: timeStringToSeconds: '12' --> invalid
4880743: timeStringToSeconds: '12' --> invalid
4880745: conditionMatch: '12.73>12.5' --> '12.73' > '12.5' --> true (12.73 > 12.5)
4880745: conditionMatchExtended: true '12.73>12.5'
4880746: Lev.1: [if true]=true
4880747: ACT : TimerSet,1,120
4880749: Command: TimerSet
4880749: TimerSet,1,120
4880749: Par1: 1 Par2: 120 Par3: 0 Par4: 0 Par5: 0
4880754: EVENT: bat#voltage=12.73 Processing time:22 milliSeconds
4890739: timeStringToSeconds: '12' --> invalid
4890739: timeStringToSeconds: '11' --> invalid
4890741: conditionMatch: '12.73<11.5' --> '12.73' < '11.5' --> false (12.73 < 11.5)
4890741: conditionMatchExtended: false '12.73<11.5'
4890741: Lev.1: [if false]=false
4890745: timeStringToSeconds: '12' --> invalid
4890745: timeStringToSeconds: '12' --> invalid
4890747: conditionMatch: '12.73>12.5' --> '12.73' > '12.5' --> true (12.73 > 12.5)
4890747: conditionMatchExtended: true '12.73>12.5'
4890748: Lev.1: [if true]=true
4890749: ACT : TimerSet,1,120
4890751: Command: TimerSet
4890751: TimerSet,1,120
4890751: Par1: 1 Par2: 120 Par3: 0 Par4: 0 Par5: 0
4890756: EVENT: bat#voltage=12.73 Processing time:22 milliSeconds
4900739: timeStringToSeconds: '12' --> invalid
4900739: timeStringToSeconds: '11' --> invalid
4900741: conditionMatch: '12.75<11.5' --> '12.75' < '11.5' --> false (12.75 < 11.5)
4900741: conditionMatchExtended: false '12.75<11.5'
4900741: Lev.1: [if false]=false
4900745: timeStringToSeconds: '12' --> invalid
4900745: timeStringToSeconds: '12' --> invalid
4900747: conditionMatch: '12.75>12.5' --> '12.75' > '12.5' --> true (12.75 > 12.5)
4900747: conditionMatchExtended: true '12.75>12.5'
4900747: Lev.1: [if true]=true
4900749: ACT : TimerSet,1,120
4900751: Command: TimerSet
4900751: TimerSet,1,120
4900751: Par1: 1 Par2: 120 Par3: 0 Par4: 0 Par5: 0
4900756: EVENT: bat#voltage=12.75 Processing time:22 milliSeconds
4902242: WD : Uptime 82 ConnectFailures 0 FreeMem 18216 WiFiStatus WL_CONNECTED 3 ESPeasy internal wifi status: Conn. IP Init
4903132: LoopStats: shortestLoop: 94 longestLoop: 906367 avgLoopDuration: 150.04 loopCounterMax: 319148 loopCounterLast: 193953
4903133: Scheduler stats: (called/tasks/max_length/idle%) 193953/1916/14/81.96
4910741: timeStringToSeconds: '12' --> invalid
4910741: timeStringToSeconds: '11' --> invalid
4910743: conditionMatch: '12.73<11.5' --> '12.73' < '11.5' --> false (12.73 < 11.5)
4910743: conditionMatchExtended: false '12.73<11.5'
4910743: Lev.1: [if false]=false
4910747: timeStringToSeconds: '12' --> invalid
4910747: timeStringToSeconds: '12' --> invalid
4910749: conditionMatch: '12.73>12.5' --> '12.73' > '12.5' --> true (12.73 > 12.5)
4910749: conditionMatchExtended: true '12.73>12.5'
4910749: Lev.1: [if true]=true
4910751: ACT : TimerSet,1,120
4910753: Command: TimerSet
4910753: TimerSet,1,120
4910753: Par1: 1 Par2: 120 Par3: 0 Par4: 0 Par5: 0
4910758: EVENT: bat#voltage=12.73 Processing time:22 milliSeconds
4915688: EVENT: Clock#Time=Tue,21:38
4915690: EVENT: Clock#Time=Tue,21:38 Processing time:2 milliSeconds
4920738: timeStringToSeconds: '12' --> invalid
4920738: timeStringToSeconds: '11' --> invalid
4920740: conditionMatch: '12.73<11.5' --> '12.73' < '11.5' --> false (12.73 < 11.5)
4920740: conditionMatchExtended: false '12.73<11.5'
4920740: Lev.1: [if false]=false
4920744: timeStringToSeconds: '12' --> invalid
4920744: timeStringToSeconds: '12' --> invalid
4920746: conditionMatch: '12.73>12.5' --> '12.73' > '12.5' --> true (12.73 > 12.5)
4920746: conditionMatchExtended: true '12.73>12.5'
4920746: Lev.1: [if true]=true
4920748: ACT : TimerSet,1,120
4920750: Command: TimerSet
4920750: TimerSet,1,120
4920750: Par1: 1 Par2: 120 Par3: 0 Par4: 0 Par5: 0
4920755: EVENT: bat#voltage=12.73 Processing time:22 milliSeconds
4930725: ADC : Analog value: 881 = 12.75
4930812: timeStringToSeconds: '11' --> invalid
4930814: conditionMatch: '12.75<11.5' --> '12.75' < '11.5' --> false (12.75 < 11.5)
4930814: conditionMatchExtended: false '12.75<11.5'
4930814: Lev.1: [if false]=false
4930818: timeStringToSeconds: '12' --> invalid
4930818: timeStringToSeconds: '12' --> invalid
4930820: conditionMatch: '12.75>12.5' --> '12.75' > '12.5' --> true (12.75 > 12.5)
4930820: conditionMatchExtended: true '12.75>12.5'
4930821: Lev.1: [if true]=true
4930822: ACT : TimerSet,1,120
4930824: Command: TimerSet
4930824: TimerSet,1,120
4930824: Par1: 1 Par2: 120 Par3: 0 Par4: 0 Par5: 0
4930829: EVENT: bat#voltage=12.75 Processing time:23 milliSeconds
4932242: WD : Uptime 82 ConnectFailures 0 FreeMem 17360 WiFiStatus WL_CONNECTED 3 ESPeasy internal wifi status: Conn. IP Init
4933131: LoopStats: shortestLoop: 94 longestLoop: 906367 avgLoopDuration: 150.48 loopCounterMax: 319148 loopCounterLast: 193380
4933131: Scheduler stats: (called/tasks/max_length/idle%) 193380/1917/14/82.05
4940740: timeStringToSeconds: '12' --> invalid
4940740: timeStringToSeconds: '11' --> invalid
4940743: conditionMatch: '12.73<11.5' --> '12.73' < '11.5' --> false (12.73 < 11.5)
4940743: conditionMatchExtended: false '12.73<11.5'
4940743: Lev.1: [if false]=false
4940747: timeStringToSeconds: '12' --> invalid
4940747: timeStringToSeconds: '12' --> invalid
4940749: conditionMatch: '12.73>12.5' --> '12.73' > '12.5' --> true (12.73 > 12.5)
4940749: conditionMatchExtended: true '12.73>12.5'
4940749: Lev.1: [if true]=true
4940751: ACT : TimerSet,1,120
4940752: Command: TimerSet
4940752: TimerSet,1,120
4940753: Par1: 1 Par2: 120 Par3: 0 Par4: 0 Par5: 0
4940757: EVENT: bat#voltage=12.73 Processing time:23 milliSeconds
4941256: WiFi : Set TX power to 15dBm sensitivity: -72dBm RSSI: -67dBm
4942072: WiFi : Set TX power to 14dBm sensitivity: -72dBm RSSI: -66dBm
4942684: WiFi : Set TX power to 15dBm sensitivity: -72dBm RSSI: -67dBm
4944424: WiFi : Set TX power to 16dBm sensitivity: -72dBm RSSI: -68dBm
4950737: timeStringToSeconds: '12' --> invalid
4950737: timeStringToSeconds: '11' --> invalid
4950739: conditionMatch: '12.73<11.5' --> '12.73' < '11.5' --> false (12.73 < 11.5)
4950739: conditionMatchExtended: false '12.73<11.5'
4950739: Lev.1: [if false]=false
4950743: timeStringToSeconds: '12' --> invalid
4950743: timeStringToSeconds: '12' --> invalid
4950745: conditionMatch: '12.73>12.5' --> '12.73' > '12.5' --> true (12.73 > 12.5)
4950745: conditionMatchExtended: true '12.73>12.5'
4950746: Lev.1: [if true]=true
4950747: ACT : TimerSet,1,120
4950749: Command: TimerSet
4950749: TimerSet,1,120
4950749: Par1: 1 Par2: 120 Par3: 0 Par4: 0 Par5: 0
4950754: EVENT: bat#voltage=12.73 Processing time:23 milliSeconds
4960739: timeStringToSeconds: '12' --> invalid
4960739: timeStringToSeconds: '11' --> invalid
4960741: conditionMatch: '12.73<11.5' --> '12.73' < '11.5' --> false (12.73 < 11.5)
4960742: conditionMatchExtended: false '12.73<11.5'
4960742: Lev.1: [if false]=false
4960746: timeStringToSeconds: '12' --> invalid
4960746: timeStringToSeconds: '12' --> invalid
4960748: conditionMatch: '12.73>12.5' --> '12.73' > '12.5' --> true (12.73 > 12.5)
4960748: conditionMatchExtended: true '12.73>12.5'
4960748: Lev.1: [if true]=true
4960750: ACT : TimerSet,1,120
4960751: Command: TimerSet
4960751: TimerSet,1,120
4960752: Par1: 1 Par2: 120 Par3: 0 Par4: 0 Par5: 0
4960756: EVENT: bat#voltage=12.73 Processing time:23 milliSeconds
4962242: WD : Uptime 83 ConnectFailures 0 FreeMem 18216 WiFiStatus WL_CONNECTED 3 ESPeasy internal wifi status: Conn. IP Init
4963131: LoopStats: shortestLoop: 94 longestLoop: 906367 avgLoopDuration: 150.39 loopCounterMax: 319148 loopCounterLast: 193505
4963131: Scheduler stats: (called/tasks/max_length/idle%) 193505/1922/14/81.72
4970737: timeStringToSeconds: '12' --> invalid
4970737: timeStringToSeconds: '11' --> invalid
4970739: conditionMatch: '12.75<11.5' --> '12.75' < '11.5' --> false (12.75 < 11.5)
4970739: conditionMatchExtended: false '12.75<11.5'
4970739: Lev.1: [if false]=false
4970743: timeStringToSeconds: '12' --> invalid
4970743: timeStringToSeconds: '12' --> invalid
4970745: conditionMatch: '12.75>12.5' --> '12.75' > '12.5' --> true (12.75 > 12.5)
4970745: conditionMatchExtended: true '12.75>12.5'
4970745: Lev.1: [if true]=true
4970747: ACT : TimerSet,1,120
4970750: Command: TimerSet
4970750: TimerSet,1,120
4970750: Par1: 1 Par2: 120 Par3: 0 Par4: 0 Par5: 0
4970755: EVENT: bat#voltage=12.75 Processing time:24 milliSeconds
4972290: static_file: esp.css
4972291: HTML : Request file esp.css
4973093: WiFi : Set TX power to 15dBm sensitivity: -72dBm RSSI: -67dBm
4973194: WiFi : Set TX power to 14dBm sensitivity: -72dBm RSSI: -66dBm
4973513: WiFi : Set TX power to 15dBm sensitivity: -72dBm RSSI: -67dBm
4974125: WiFi : Set TX power to 16dBm sensitivity: -72dBm RSSI: -68dBm
4975688: EVENT: Clock#Time=Tue,21:39
4975690: EVENT: Clock#Time=Tue,21:39 Processing time:3 milliSeconds
4976076: static_file: esp.css
4976078: Serve 304: 1676410525 esp.css
4976078: HTML : Request file esp.css
4976986: WiFi : Set TX power to 15dBm sensitivity: -72dBm RSSI: -67dBm
4977618: WiFi : Set TX power to 16dBm sensitivity: -72dBm RSSI: -68dBm
4980782: timeStringToSeconds: '12' --> invalid
4980782: timeStringToSeconds: '11' --> invalid
4980784: conditionMatch: '12.75<11.5' --> '12.75' < '11.5' --> false (12.75 < 11.5)
4980784: conditionMatchExtended: false '12.75<11.5'
4980784: Lev.1: [if false]=false
4980788: timeStringToSeconds: '12' --> invalid
4980788: timeStringToSeconds: '12' --> invalid
4980790: conditionMatch: '12.75>12.5' --> '12.75' > '12.5' --> true (12.75 > 12.5)
4980790: conditionMatchExtended: true '12.75>12.5'
4980791: Lev.1: [if true]=true
4980792: ACT : TimerSet,1,120
4980794: Command: TimerSet
4980794: TimerSet,1,120
4980794: Par1: 1 Par2: 120 Par3: 0 Par4: 0 Par5: 0
4980799: EVENT: bat#voltage=12.75 Processing time:63 milliSeconds
4987332: WiFi : Set TX power to 15dBm sensitivity: -72dBm RSSI: -67dBm
4988252: WiFi : Set TX power to 16dBm sensitivity: -72dBm RSSI: -68dBm
4990739: timeStringToSeconds: '12' --> invalid
4990739: timeStringToSeconds: '11' --> invalid
4990741: conditionMatch: '12.73<11.5' --> '12.73' < '11.5' --> false (12.73 < 11.5)
4990741: conditionMatchExtended: false '12.73<11.5'
4990741: Lev.1: [if false]=false
4990745: timeStringToSeconds: '12' --> invalid
4990745: timeStringToSeconds: '12' --> invalid
4990747: conditionMatch: '12.73>12.5' --> '12.73' > '12.5' --> true (12.73 > 12.5)
4990747: conditionMatchExtended: true '12.73>12.5'
4990747: Lev.1: [if true]=true
4990749: ACT : TimerSet,1,120
4990751: Command: TimerSet
4990751: TimerSet,1,120
4990751: Par1: 1 Par2: 120 Par3: 0 Par4: 0 Par5: 0
4990756: EVENT: bat#voltage=12.73 Processing time:23 milliSeconds
4992242: WD : Uptime 83 ConnectFailures 0 FreeMem 17624 WiFiStatus WL_CONNECTED 3 ESPeasy internal wifi status: Conn. IP Init
4993133: LoopStats: shortestLoop: 94 longestLoop: 906367 avgLoopDuration: 153.39 loopCounterMax: 319148 loopCounterLast: 189835
4993133: Scheduler stats: (called/tasks/max_length/idle%) 189835/1889/14/81.58
5000736: timeStringToSeconds: '12' --> invalid
5000737: timeStringToSeconds: '11' --> invalid
5000739: conditionMatch: '12.73<11.5' --> '12.73' < '11.5' --> false (12.73 < 11.5)
5000739: conditionMatchExtended: false '12.73<11.5'
5000739: Lev.1: [if false]=false
5000743: timeStringToSeconds: '12' --> invalid
5000743: timeStringToSeconds: '12' --> invalid
5000745: conditionMatch: '12.73>12.5' --> '12.73' > '12.5' --> true (12.73 > 12.5)
5000745: conditionMatchExtended: true '12.73>12.5'
5000745: Lev.1: [if true]=true
5000747: ACT : TimerSet,1,120
5000749: Command: TimerSet
5000750: TimerSet,1,120
5000750: Par1: 1 Par2: 120 Par3: 0 Par4: 0 Par5: 0
5000755: EVENT: bat#voltage=12.73 Processing time:25 milliSeconds
5010736: timeStringToSeconds: '12' --> invalid
5010736: timeStringToSeconds: '11' --> invalid
5010739: conditionMatch: '12.75<11.5' --> '12.75' < '11.5' --> false (12.75 < 11.5)
5010739: conditionMatchExtended: false '12.75<11.5'
5010739: Lev.1: [if false]=false
5010743: timeStringToSeconds: '12' --> invalid
5010743: timeStringToSeconds: '12' --> invalid
5010745: conditionMatch: '12.75>12.5' --> '12.75' > '12.5' --> true (12.75 > 12.5)
5010745: conditionMatchExtended: true '12.75>12.5'
5010745: Lev.1: [if true]=true
5010747: ACT : TimerSet,1,120
5010748: Command: TimerSet
5010748: TimerSet,1,120
5010749: Par1: 1 Par2: 120 Par3: 0 Par4: 0 Par5: 0
5010753: EVENT: bat#voltage=12.75 Processing time:23 milliSeconds
5020737: timeStringToSeconds: '12' --> invalid
5020738: timeStringToSeconds: '11' --> invalid
5020740: conditionMatch: '12.75<11.5' --> '12.75' < '11.5' --> false (12.75 < 11.5)
5020740: conditionMatchExtended: false '12.75<11.5'
5020740: Lev.1: [if false]=false
5020744: timeStringToSeconds: '12' --> invalid
5020744: timeStringToSeconds: '12' --> invalid
5020746: conditionMatch: '12.75>12.5' --> '12.75' > '12.5' --> true (12.75 > 12.5)
5020746: conditionMatchExtended: true '12.75>12.5'
5020746: Lev.1: [if true]=true
5020748: ACT : TimerSet,1,120
5020750: Command: TimerSet
5020750: TimerSet,1,120
5020750: Par1: 1 Par2: 120 Par3: 0 Par4: 0 Par5: 0
5020755: EVENT: bat#voltage=12.75 Processing time:24 milliSeconds
5022242: WD : Uptime 84 ConnectFailures 0 FreeMem 17624 WiFiStatus WL_CONNECTED 3 ESPeasy internal wifi status: Conn. IP Init
5023131: LoopStats: shortestLoop: 94 longestLoop: 906367 avgLoopDuration: 149.74 loopCounterMax: 319148 loopCounterLast: 194303
5023131: Scheduler stats: (called/tasks/max_length/idle%) 194303/1924/14/81.16
5030738: timeStringToSeconds: '12' --> invalid
5030738: timeStringToSeconds: '11' --> invalid
5030741: conditionMatch: '12.75<11.5' --> '12.75' < '11.5' --> false (12.75 < 11.5)
5030741: conditionMatchExtended: false '12.75<11.5'
5030741: Lev.1: [if false]=false
5030745: timeStringToSeconds: '12' --> invalid
5030745: timeStringToSeconds: '12' --> invalid
5030747: conditionMatch: '12.75>12.5' --> '12.75' > '12.5' --> true (12.75 > 12.5)
5030747: conditionMatchExtended: true '12.75>12.5'
5030747: Lev.1: [if true]=true
5030749: ACT : TimerSet,1,120
5030752: Command: TimerSet
5030752: TimerSet,1,120
5030752: Par1: 1 Par2: 120 Par3: 0 Par4: 0 Par5: 0
5030757: EVENT: bat#voltage=12.75 Processing time:25 milliSeconds
5035688: EVENT: Clock#Time=Tue,21:40
5035690: EVENT: Clock#Time=Tue,21:40 Processing time:3 milliSeconds
5040737: timeStringToSeconds: '12' --> invalid
5040737: timeStringToSeconds: '11' --> invalid
5040739: conditionMatch: '12.73<11.5' --> '12.73' < '11.5' --> false (12.73 < 11.5)
5040739: conditionMatchExtended: false '12.73<11.5'
5040739: Lev.1: [if false]=false
5040743: timeStringToSeconds: '12' --> invalid
5040743: timeStringToSeconds: '12' --> invalid
5040745: conditionMatch: '12.73>12.5' --> '12.73' > '12.5' --> true (12.73 > 12.5)
5040745: conditionMatchExtended: true '12.73>12.5'
5040745: Lev.1: [if true]=true
5040747: ACT : TimerSet,1,120
5040748: Command: TimerSet
5040748: TimerSet,1,120
5040749: Par1: 1 Par2: 120 Par3: 0 Par4: 0 Par5: 0
5040753: EVENT: bat#voltage=12.73 Processing time:22 milliSeconds
Looks like timer is restarting over and over...
If %eventvalue1%>12.5
TimerSet,1,120
Endif
eventvalue1 needs some synhax caution? why eventvalue1? ... just in case could be more eventvalue? ... eventvalue2, eventvalue3
Screenshot 2023-02-14 at 21-56-26 ESP_Easy pocio.png
Screenshot 2023-02-14 at 21-56-26 ESP_Easy pocio.png (21.03 KiB) Viewed 2664 times
After voltage rise over 12.5V, event Bat#voltage take place every 10s, so the timer is set on 120 every 10s... so the gpio,5,1 never happens...
This works

Code: Select all

On Bat#voltage do
  If [Bat#voltage]<11.5 // Use %eventvalue1% where possible
    GPIO,5,0
  Endif
  If [Bat#voltage]>12.5
    Let,1,12.7
  Endif
  If [Bat#voltage]>=%v1%
    GPIO,5,1
  Endif
Endon
Last edited by bonti69 on 14 Feb 2023, 21:44, edited 1 time in total.

User avatar
Ath
Normal user
Posts: 3417
Joined: 10 Jun 2018, 12:06
Location: NL

Re: rules isue

#32 Post by Ath » 14 Feb 2023, 21:17

Please do not use Loglevel Debug, as that will show all kinds of irrelevant logging, only useful when actually debugging ESPEasy internals, not your setup.

Read up here on Rules (with lots of examples) and %eventvalue% specifically.

The timer is indeed started every time the voltage changes, as that's what you put in originally, I just cleaned up your code a bit, removing syntax errors etc.
An extra check can be added so the timer is only started if GPIO-5 = 0:

Code: Select all

On Bat#voltage do
  If %eventvalue1%<11.5 // %eventvalue1% is the first argument provided with the event -> the value of [Bat#Voltage] at the moment the event was generated
    GPIO,5,0 // Turn off load
  Endif
  If %eventvalue1%>=12.5 and [Plugin#GPIO#pinstate#5]=0 // Start timer to switch on load if not yet on (using same condition as below)
    TimerSet,1,120
  Endif
Endon

On Rules#Timer=1 Do
  If [Bat#voltage]>=12.5
    GPIO,5,1
  Endif
Endon
/Ton (PayPal.me)

bonti69
Normal user
Posts: 119
Joined: 08 Apr 2021, 12:16

Re: rules isue

#33 Post by bonti69 » 14 Feb 2023, 21:54

Die hard

Code: Select all

9250751: ADC  : Analog value: 883 = 12.77
9250764: EVENT: bat#voltage=12.77
9250782: ACT  : TimerSet,1,120
9252242: WD   : Uptime 154 ConnectFailures 0 FreeMem 17232 WiFiStatus WL_CONNECTED 3 ESPeasy internal wifi status: Conn. IP Init
9260725: ADC  : Analog value: 882 = 12.76
9260739: EVENT: bat#voltage=12.76
9260756: ACT  : TimerSet,1,120
9270727: ADC  : Analog value: 882 = 12.76
9270738: EVENT: bat#voltage=12.76
9270756: ACT  : TimerSet,1,120
9280725: ADC  : Analog value: 883 = 12.77
9280740: EVENT: bat#voltage=12.77
9280758: ACT  : TimerSet,1,120
9282386: WD   : Uptime 155 ConnectFailures 0 FreeMem 17784 WiFiStatus WL_CONNECTED 3 ESPeasy internal wifi status: Conn. IP Init
9290725: ADC  : Analog value: 882 = 12.76
9290736: EVENT: bat#voltage=12.76
9290754: ACT  : TimerSet,1,120
Seems it's very difficult to extract an event only when analogue value trip over a treshold, to start the timer... leading edge / trailing edge
Found a working rule:

Code: Select all

On Bat#voltage do
  If %eventvalue1%<11.5 // %eventvalue1% is the first argument provided with the event -> the value of [Bat#Voltage] at the moment the event was generated
    GPIO,5,0   // Turn off load
    GPIO,4,0  
  Endif
  If %eventvalue1%>=12.5
  GPIO,4,1
  Endif
 Endon
  
On GPIO#4=1 do // Start timer to switch on load if not yet on (using same condition as below)
    TimerSet,1,120
Endon
 
On Rules#Timer=1 Do
  If [Bat#voltage]>=12.5
    GPIO,5,1
  Endif
Endon
Used gpio4 as a virtual switch, over 12.5V pinstate1
The problem was that all the rule was under the wing of "On Bat#voltage do", very fast , every 10sec, so the timer keep restarting. Putting the timer outside the "On Bat#voltage do" solve the headache
Many thanks for your unvaluable support. Good to know you're here ;)
Last edited by bonti69 on 14 Feb 2023, 23:14, edited 1 time in total.

User avatar
Ath
Normal user
Posts: 3417
Joined: 10 Jun 2018, 12:06
Location: NL

Re: rules isue

#34 Post by Ath » 14 Feb 2023, 22:15

There's an extra Endon in your code that shouldn't be there, just before this: If [Plugin#GPIO...

And instead of using GPIO 4 as a state flag, you could use a variable:

Code: Select all

On Bat#voltage do
  If %eventvalue1%<11.5 // %eventvalue1% is the first argument provided with the event -> the value of [Bat#Voltage] at the moment the event was generated
    GPIO,5,0   // Turn off load
    let,4,0  
  Endif
  If %eventvalue1%>=12.5
    let,4,1
  Endif
  
  If [var#4]=1 // Start timer to switch on load if not yet on (using same condition as below)
    TimerSet,1,120
  Endif
Endon
On Rules#Timer=1 Do
  If [Bat#voltage]>=12.5
    GPIO,5,1
  Endif
Endon
But effectively that doesn't make it different from your earlier attempt, it will be restarting the timer every time bat#voltage changes...

Can't wrap my head around it at the moment, will have another look tomorrow.
/Ton (PayPal.me)

bonti69
Normal user
Posts: 119
Joined: 08 Apr 2021, 12:16

Re: rules isue

#35 Post by bonti69 » 14 Feb 2023, 23:22

Not start the timer

Code: Select all

On Bat#voltage do
  If %eventvalue1%<11.5 // %eventvalue1% is the first argument provided with the event -> the value of [Bat#Voltage] at the moment the event was generated
    GPIO,5,0   // Turn off load
    Let,4,0  
  Endif
  If %eventvalue1%>=12.5
  Let,4,1
  Endif
 Endon
  
On [var#4]=1 do // Start timer to switch on load if not yet on (using same condition as below)
    TimerSet,1,120
Endon
 
On Rules#Timer=1 Do
  If [Bat#voltage]>=12.5
    GPIO,5,1
  Endif
Endon
This one seems to work:

Code: Select all

On Bat#voltage do
  If %eventvalue1%<11.5 // %eventvalue1% is the first argument provided with the event -> the value of [Bat#Voltage] at the moment the event was generated
    GPIO,5,0   // Turn off load
    GPIO,4,0  
  Endif
  If %eventvalue1%>=12.5
  GPIO,4,1
  Endif
 Endon
  
On GPIO#4=1 do // Start timer to switch on load if not yet on (using same condition as below)
    TimerSet,1,120
Endon
 
On Rules#Timer=1 Do
  If [Bat#voltage]>=12.5
    GPIO,5,1
  Endif
Endon
On GPIO#4=1 do // Start timer to switch on load if not yet on (using same condition as below)
TimerSet,1,120
Endon
ONLY WORKS IF this rule is on boot: Monitor GPIO,4

Code: Select all

On System#Boot Do
GPIO,5,1
GPIO,15,1
GPIO,14,1
Monitor GPIO,4
Endon
The point break is how to extract/start an event from a certain value of an internal variable, or when variable is changing value... with a gpio the trick was to monitor the gpio ( On GPIO#4=1 do ) . Not sure if it's working with [Plugin#GPIO#pinstate#4]=1

bonti69
Normal user
Posts: 119
Joined: 08 Apr 2021, 12:16

Re: rules isue

#36 Post by bonti69 » 16 Feb 2023, 15:37

Why this simple rule not working?

Code: Select all

On Clock#Time = All , **:** do
   //If [var#3]=1 // Start timer to switch on load
    TimerSet,3,2
  //Endif
 Endon
  
 On Rules#Timer=3 Do
  //If [Bat#voltage]>=12.0
    pulse,GPIO,15,1,1
  //Endif
Endon

User avatar
Ath
Normal user
Posts: 3417
Joined: 10 Jun 2018, 12:06
Location: NL

Re: rules isue

#37 Post by Ath » 16 Feb 2023, 15:44

You might try to write this

Code: Select all

On Clock#Time = All , **:** Do
as

Code: Select all

On Clock#Time=All,**:** Do
Not sure how well it will handle all the extra spaces there
/Ton (PayPal.me)

bonti69
Normal user
Posts: 119
Joined: 08 Apr 2021, 12:16

Re: rules isue

#38 Post by bonti69 » 16 Feb 2023, 16:26

Tried already, no chance
Screenshot 2023-02-16 at 17-25-20 ESP_Easy pocio.png
Screenshot 2023-02-16 at 17-25-20 ESP_Easy pocio.png (31.65 KiB) Viewed 2536 times
it's ok

Code: Select all

On Clock#Time=All,**:** Do
   //If [var#3]=1 // Start timer to switch on load
    TimerSet,3,2
  //Endif
 Endon
  
 On Rules#Timer=3 Do
  //If [Bat#voltage]>=12.0
   longpulse,15,1,1
  //Endif
Endon
longpulse,15,1,1 was the fault

Post Reply

Who is online

Users browsing this forum: No registered users and 23 guests