How flexible are if statements w/ %eventvalue%v?

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
User avatar
Methuselah
Normal user
Posts: 45
Joined: 04 Feb 2018, 01:39
Location: Boston, MA

How flexible are if statements w/ %eventvalue%v?

#1 Post by Methuselah » 20 Feb 2018, 16:15

Given the following code:

Code: Select all

on SetOutsideTemp do
if %eventvalue% <> [T1#A]
TaskValueSet 9,1,%eventvalue%
else
Test1 Failed
endif
if [T1#A] <> %eventvalue%
TaskValueSet 9,1,%eventvalue%
else
Test2 failed
endif
T1#A=[T1#A]
endon
Given [T1#A] equals 55.5, executing the following:

http://my.ip/control?cmd=event,SetOutsideTemp=55.3

yields the following in my output log:

EVENT: SetOutsideTemp=55.3
ACT: Test1 failed
ACT: TestValueSet 9,1,55.3
ACT: [T1#A]=55.3
EVENT: Processing time 1712 milliseconds


From this output, should I conclude %eventvalue% is only evaluated on the right of the conditional expression?
N00b to the world of ESPEasy, but I've been programming since the days of punch cards and paper tape :)

User avatar
Methuselah
Normal user
Posts: 45
Joined: 04 Feb 2018, 01:39
Location: Boston, MA

Re: How flexible are if statements w/ %eventvalue%v?

#2 Post by Methuselah » 20 Feb 2018, 16:30

Also.... The test condition does not seem to like a device value initialized to zero, e.g.

Code: Select all

on System#Boot do
 TaskValueSet 9,1,0.0
endon

on SetOutsideTemp do
if %eventvalue% <> [T1#A]
TaskValueSet 9,1,%eventvalue%
else
Test1 Failed
endif
if [T1#A] <> %eventvalue%
TaskValueSet 9,1,%eventvalue%
else
Test2 failed
endif
T1#A=[T1#A]
endon
Yields:

http://my.ip/control?cmd=event,SetOutsideTemp=55.3

yields the following in my output log:

EVENT: SetOutsideTemp=55.3
ACT: Test1 failed
ACT: Test2 failed
ACT: [T1#A]=0.0
EVENT: Processing time 1676 milliseconds


I can only get the test condition to evaluate correctly if [T1#A] is initialized to a value greater than 0 in System#Boot. Negative values also do not seem to evaluate properly (e.g. a TaskSetValue of -100 in System#Boot will likewise cause the test conditions to evaluate false when when they should be true)

(using the mega 2018-20-19 build)
N00b to the world of ESPEasy, but I've been programming since the days of punch cards and paper tape :)

User avatar
vader
Normal user
Posts: 241
Joined: 21 Mar 2017, 17:35

Re: How flexible are if statements w/ %eventvalue%v?

#3 Post by vader » 20 Feb 2018, 21:22

Only one operator is allowed. <> is not allowed. See source code...

switch (compare)
{
case '>':
if (Value1 > Value2)
match = true;
break;

case '<':
if (Value1 < Value2)
match = true;
break;

case '=':
if (Value1 == Value2)
match = true;
break;

User avatar
Methuselah
Normal user
Posts: 45
Joined: 04 Feb 2018, 01:39
Location: Boston, MA

Re: How flexible are if statements w/ %eventvalue%v?

#4 Post by Methuselah » 20 Feb 2018, 23:59

Thanks. Interesting. I didn't realize there was no inequality operator.
what would be the proper way to check for inequality then?

if something
else
do commands
endif

or

if something
delay 0
else
do commands
endif

?
N00b to the world of ESPEasy, but I've been programming since the days of punch cards and paper tape :)

User avatar
budman1758
Normal user
Posts: 301
Joined: 15 Apr 2017, 05:13
Location: Riverside CA USA

Re: How flexible are if statements w/ %eventvalue%v?

#5 Post by budman1758 » 21 Feb 2018, 03:01

Perhaps a study of this link will help?
https://www.letscontrolit.com/wiki/inde ... rial_Rules
"The glass is twice as big as it needs to be".

User avatar
vader
Normal user
Posts: 241
Joined: 21 Mar 2017, 17:35

Re: How flexible are if statements w/ %eventvalue%v?

#6 Post by vader » 21 Feb 2018, 13:45

You can try this:

on %eventvalue% < [T1#A] do //Check 1st if lower
if %eventvalue% > [T1#A] //Check 2nd if higher, so we also have a <> comparison ;)
bla, bla....
else
more bla, bla.... :mrgreen:
endif
endon

User avatar
Methuselah
Normal user
Posts: 45
Joined: 04 Feb 2018, 01:39
Location: Boston, MA

Re: How flexible are if statements w/ %eventvalue%v?

#7 Post by Methuselah » 21 Feb 2018, 18:14

vader wrote: 21 Feb 2018, 13:45 You can try this:
Thanks for your input Vader. I guess I need to make it a point of looking through the code base more than I have in the past.
N00b to the world of ESPEasy, but I've been programming since the days of punch cards and paper tape :)

duytruong
New user
Posts: 1
Joined: 14 Jan 2018, 03:18

Re: How flexible are if statements w/ %eventvalue%v?

#8 Post by duytruong » 24 Feb 2018, 04:24

Methuselah wrote: 20 Feb 2018, 16:15 Given the following code:
if %eventvalue% <> [T1#A]
You'd better assign %eventvalue% to a Dummy device than using it directly.

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

Re: How flexible are if statements w/ %eventvalue%v?

#9 Post by TD-er » 24 Feb 2018, 17:31

vader wrote: 20 Feb 2018, 21:22 Only one operator is allowed. <> is not allowed. See source code...
[...]
I added this as suggestion to this PR/issue: https://github.com/letscontrolit/ESPEas ... -368237502

User avatar
Methuselah
Normal user
Posts: 45
Joined: 04 Feb 2018, 01:39
Location: Boston, MA

Re: How flexible are if statements w/ %eventvalue%v?

#10 Post by Methuselah » 26 Feb 2018, 00:16

TD-er wrote: 24 Feb 2018, 17:31
vader wrote: 20 Feb 2018, 21:22 Only one operator is allowed. <> is not allowed. See source code...
[...]
I added this as suggestion to this PR/issue: https://github.com/letscontrolit/ESPEas ... -368237502
Read the thread. Sweet. Image
N00b to the world of ESPEasy, but I've been programming since the days of punch cards and paper tape :)

Post Reply

Who is online

Users browsing this forum: No registered users and 47 guests