Page 1 of 1

IF statement on %eventvalue%

Posted: 23 Oct 2017, 12:50
by rayE
Hi,
V2.0

I set up a rule as follows.

on configFlowSensor do
if [%eventvalue%] = 1
// Do something like set a GPIO output
endif
endon

I send the following HTTP request.
http://<your esp ip>/control?cmd=event,configFlowSenor=1

With the IF statement i get no response, without the IF statement it will set the digital output. The IF statement seems to ignore the value in %eventvalue% although it does trigger the rule.

Any pointers?

TIA
Ray

Re: IF statement on %eventvalue%

Posted: 23 Oct 2017, 14:39
by grovkillen
As seen in the wiki here: https://www.letscontrolit.com/wiki/inde ... _Reference you cannot pass values with the event command.

To do so I suggest you try the TaskValueSet together with a dummy device (if you insist on using HTTP). If you use MQTT you could resolve the matter by using the MQTT import or use the TaskValueSet via cmd.

Re: IF statement on %eventvalue%

Posted: 23 Oct 2017, 15:15
by vader
What about the rule

on configFlowSensor do
if [configFlowSensor#ValueOfDevice] = 1
// Do something like set a GPIO output
endif
endon

@grovkillen: You wrote "use the TaskValueSet via cmd". TaskValueSet is declared in the Wiki as rule command only, not for external usage!

Re: IF statement on %eventvalue%

Posted: 23 Oct 2017, 16:16
by grovkillen
vader wrote: 23 Oct 2017, 15:15 @grovkillen: You wrote "use the TaskValueSet via cmd". TaskValueSet is declared in the Wiki as rule command only, not for external usage!
Aaah!! You're right. Sorry, wrote it on my phone and didn't think straight :oops:

Re: IF statement on %eventvalue%

Posted: 23 Oct 2017, 18:23
by toffel969
grovkillen wrote: 23 Oct 2017, 16:16
vader wrote: 23 Oct 2017, 15:15 @grovkillen: You wrote "use the TaskValueSet via cmd". TaskValueSet is declared in the Wiki as rule command only, not for external usage!
Aaah!! You're right. Sorry, wrote it on my phone and didn't think straight :oops:
It is possible with TaskValueSet

You sent event value and write it into a dummy using taskvalueset within the event. Then you can check the dummys value within rules.

Re: IF statement on %eventvalue%

Posted: 23 Oct 2017, 18:30
by toffel969
You still start by sending http command with event value:
http://<your esp ip>/control?cmd=event,configFlowSenor=1

On the receiving ESP you create a Dummy device, lets say as device 1 in the device Tab. You name the value , for example memory

Code: Select all

On configFlowSensor do 
TaskValueSet 1,%eventvalue%
if [Dummy#memory]=1 
// Do something 
endif 
endon

That should work!

Re: IF statement on %eventvalue%

Posted: 23 Oct 2017, 19:20
by vader
Not working. Messed the rules! BTW: TaskValueSet need 3 parameter...

Re: IF statement on %eventvalue%

Posted: 23 Oct 2017, 19:28
by toffel969
vader wrote: 23 Oct 2017, 19:20 Not working. Messed the rules! BTW: TaskValueSet need 3 parameter...
You are right about the TaskValueSet needing 3 parameters. But then there is no reason y th shouldn't work

Re: IF statement on %eventvalue%

Posted: 23 Oct 2017, 19:44
by vader
I've tested it and does not work for me. I mean, you can not transmit values to an event. The parser seems to ignore more than 1 value after "event". It is only interested in the event name.... :D

The messed rules seem to be an issue of core 2.4.0.... :?

Re: IF statement on %eventvalue%

Posted: 23 Oct 2017, 19:58
by toffel969
I just tested this on one of my nodes running R142

it definitly works the way I described

Re: IF statement on %eventvalue%

Posted: 23 Oct 2017, 19:59
by toffel969
vader wrote: 23 Oct 2017, 19:44 I've tested it and does not work for me. I mean, you can not transmit values to an event. The parser seems to ignore more than 1 value after "event". It is only interested in the event name.... :D

The messed rules seem to be an issue of core 2.4.0.... :?
You can send values, check the wiki
https://www.letscontrolit.com/wiki/inde ... _Variables

Re: IF statement on %eventvalue%

Posted: 23 Oct 2017, 20:10
by vader
Ok, now I got it. The "=" after event name was wrong (I had ",")... :oops:

Re: IF statement on %eventvalue%

Posted: 23 Oct 2017, 23:16
by danmero

Code: Select all

on testevent do
  TaskValueSet 5,4,%eventvalue%
endon

Code: Select all

http://x.x.x.x/control?cmd=event,testevent=3
This works on 2.0.0.x

Re: IF statement on %eventvalue%

Posted: 24 Oct 2017, 02:53
by rayE
Thanks guy's, this works a treat :-)

Re: IF statement on %eventvalue%

Posted: 24 Oct 2017, 07:54
by grovkillen
toffel969 wrote: 23 Oct 2017, 19:59
vader wrote: 23 Oct 2017, 19:44 I've tested it and does not work for me. I mean, you can not transmit values to an event. The parser seems to ignore more than 1 value after "event". It is only interested in the event name.... :D

The messed rules seem to be an issue of core 2.4.0.... :?
You can send values, check the wiki
https://www.letscontrolit.com/wiki/inde ... _Variables
I have now moved this section to its correct section 8-)

https://www.letscontrolit.com/wiki/inde ... alue.25.29

I hope more people will use this awesome technique (I sure hadn't seen it before you pointed it out).

Re: IF statement on %eventvalue%

Posted: 20 Nov 2017, 15:20
by danmero
I use this rule set to pass GPIO # as event argument.

Code: Select all

on sniff#a do
  event event1=%eventvalue%
endon

on event1 do
  pcfpulse %eventvalue%,0,200
endon
Regards,

Re: IF statement on %eventvalue%

Posted: 20 Nov 2017, 16:32
by grovkillen
danmero wrote: 20 Nov 2017, 15:20 I use this rule set to pass GPIO # as event argument.

Code: Select all

on sniff#a do
  event event1=%eventvalue%
endon

on event1 do
  pcfpulse %eventvalue%,0,200
endon
Regards,
Clever, will try to add this to the wiki as well.