Hello,
I've just started with EspEasy, looks great, but I have some problems with tyhe Rules section
I use the Dummy plugin P033 with the name "Dummy" and first parameter named "Value"=199, compiled with sources of 20231225.
(I didn't see a change related to this problem in the newer released software)
I've the following Rules:
On Dummy#Value > 100 Do
LogEntry,"Test1"
Endon
On [Dummy#Value] > 100 Do
LogEntry,"Test2"
Endon
On Dummy#Value Do
LogEntry,"Test3"
If Dummy#Value > 100
LogEntry,"Test4" // giving Error : Calculate: Unknown token input: dummy#value = 0
endif
If [Dummy#Value] > 100
LogEntry,"Test5"
endif
LogEntry,"Test6"
Endon
And the result is:
01:12:53.583 : (215656) Info : Dummy: value 1: 199.00
01:12:53.595 : (215516) Info : EVENT: Dummy#Value=199.00
01:12:53.611 : (215420) Info : ACT : LogEntry,"Test3"
01:12:53.615 : (215372) Info : Test3
01:12:53.618 : (215356) Error : Calculate: Unknown token input: dummy#value = 0
01:12:53.628 : (215420) Info : ACT : LogEntry,"Test5"
01:12:53.632 : (215372) Info : Test5
01:12:53.635 : (215420) Info : ACT : LogEntry,"Test6"
01:12:53.639 : (215372) Info : Test6
Why aren't Test1, Test2 and Test4 not working ?
cheers, Stef
Value checking in Rules sometines don't work
Moderators: grovkillen, Stuntteam, TD-er
Re: Value checking in Rules sometines don't work
That's the difference between using square brackets or not:
- For event handlers do NOT use square brackets
- For variable values to be used DO use square brackets
This is the intended and documented behavior

/Ton (PayPal.me)
Re: Value checking in Rules sometines don't work
There's actually another issue with your rules.
Once a matching rule is found, rules processing is stopped to (greatly) improve performance.
This implies that test2 and later will only be reached if [Dummy#Value] is less than 100. Best way to handle a variable that has to be checked for multiple values, is to have the generic handler, like your test3 situation, and check for all (corner-)cases you need to handle.
And you could wrap your rules examples in code tags (the </> button in the forum toolbar) (and add some indenting spaces for readability please):
Once a matching rule is found, rules processing is stopped to (greatly) improve performance.
This implies that test2 and later will only be reached if [Dummy#Value] is less than 100. Best way to handle a variable that has to be checked for multiple values, is to have the generic handler, like your test3 situation, and check for all (corner-)cases you need to handle.
And you could wrap your rules examples in code tags (the </> button in the forum toolbar) (and add some indenting spaces for readability please):
Code: Select all
On Dummy#Value > 100 Do // --> This could be valid
LogEntry,"Test1"
Endon
On [Dummy#Value] > 100 Do // --> This variable is replaced when loading the rules into memory, and won't be parsed again, so most likely won't work as expected
LogEntry,"Test2"
Endon
On Dummy#Value Do // --> This is probably the best way to handle multiple values
LogEntry,"Test3"
If Dummy#Value > 100 // --> Variable values will be used when the task value is wrapped in square brackets: [taskname#valuename]
LogEntry,"Test4" // giving Error : Calculate: Unknown token input: dummy#value = 0
endif
If [Dummy#Value] > 100 // --> This is a valid test
LogEntry,"Test5"
endif
LogEntry,"Test6"
Endon
/Ton (PayPal.me)
Re: Value checking in Rules sometines don't work
thanks for the answers Ath
first of all I didn't know how to insert code in to this message, so I'll try again
I now understand the use of [] thanks !
And for the moment I assume that it's not possible to test for a specific value in the On .. Do clause directly.
cheers, Stef
first of all I didn't know how to insert code in to this message, so I'll try again
I now understand the use of [] thanks !
And for the moment I assume that it's not possible to test for a specific value in the On .. Do clause directly.
Code: Select all
On Dummy#Value > 100 Do // <-- this isn't allowed, I guess, although there is an example "on PIR#State=1 do"
LogEntry,"Test1" // so this is never executed
Endon
Re: Value checking in Rules sometines don't work
There are some limitations on comparing the value in the on...do clause.
Also you have to keep in mind the rules parsing stops at the first matching rules block.
Best practice is to do the compares inside the rules block, like this:
Also you have to keep in mind the rules parsing stops at the first matching rules block.
Best practice is to do the compares inside the rules block, like this:
Code: Select all
On Dummy#Value Do
if %eventvalue1% > 100
LogEntry,"Test1, %eventvalue1% > 100"
else
LogEntry,"Test2, %eventvalue1% <= 100"
endif
Endon
Who is online
Users browsing this forum: Bing [Bot] and 10 guests