Page 1 of 1
How flexible are if statements w/ %eventvalue%v?
Posted: 20 Feb 2018, 16:15
by Methuselah
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?
Re: How flexible are if statements w/ %eventvalue%v?
Posted: 20 Feb 2018, 16:30
by Methuselah
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)
Re: How flexible are if statements w/ %eventvalue%v?
Posted: 20 Feb 2018, 21:22
by vader
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;
Re: How flexible are if statements w/ %eventvalue%v?
Posted: 20 Feb 2018, 23:59
by Methuselah
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
?
Re: How flexible are if statements w/ %eventvalue%v?
Posted: 21 Feb 2018, 03:01
by budman1758
Re: How flexible are if statements w/ %eventvalue%v?
Posted: 21 Feb 2018, 13:45
by vader
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....
endif
endon
Re: How flexible are if statements w/ %eventvalue%v?
Posted: 21 Feb 2018, 18:14
by Methuselah
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.
Re: How flexible are if statements w/ %eventvalue%v?
Posted: 24 Feb 2018, 04:24
by duytruong
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.
Re: How flexible are if statements w/ %eventvalue%v?
Posted: 24 Feb 2018, 17:31
by TD-er
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
Re: How flexible are if statements w/ %eventvalue%v?
Posted: 26 Feb 2018, 00:16
by Methuselah
Read the thread. Sweet.
![Image](https://images.fastcompany.net/image/upload/fc/3021307-inline-fb-thumbsup-printpackaging.jpg)