Rules using 'OR"

Moderators: grovkillen, TD-er, Stuntteam

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

Rules using 'OR"

#1 Post by Dick60 » 20 May 2020, 10:59

According the WIKI I can you the 'OR' statement in rules.
on test do
if [test#a]=0 or [test#b]=0 or [test#c]=0
event,ok
else
event,not_ok
endif
endon

I adjusted the example to my needs but it does not work. Can anybody help me around?
I have 2 switches I can make them 1 or 0. Depending the status it will (de-)activate the generalswitch.

On generalswitch do
if [switch1#State]=1 or [switch2#State]=1
gpio,0,0
else
gpio,0,1
endif
endon

User avatar
grovkillen
Core team member
Posts: 3584
Joined: 19 Jan 2017, 12:56
Location: Hudiksvall, Sweden
Contact:

Re: Rules using 'OR"

#2 Post by grovkillen » 20 May 2020, 11:04

What version?
ESP Easy Flasher [flash tool and wifi setup at flash time]
ESP Easy Webdumper [easy screendumping of your units]
ESP Easy Netscan [find units]
Official shop: https://firstbyte.shop/
Sponsor ESP Easy, we need you :idea: :idea: :idea:

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

Re: Rules using 'OR"

#3 Post by Dick60 » 20 May 2020, 11:48

Sorry forgot to mention, the latest one 15052020

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

Re: Rules using 'OR"

#4 Post by TD-er » 20 May 2020, 13:27

Code: Select all

if [switch1#State]=1 or [switch2#State]=1
Try printing the switch state into a logentry, just to make sure you compare to the correct value and also to see if you even get into that part of the rules.

For example is there a task named 'generalswitch' ?
You refer to it in the On ... do part

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

Re: Rules using 'OR"

#5 Post by Dick60 » 20 May 2020, 14:18

no there isn't a 'generalswitch' task. What I read in the wiki is that it is possible to use this kind of rule. Wrong intepretation. So what si the approch for me, do you have an example for me how to het this working?

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

Re: Rules using 'OR"

#6 Post by Dick60 » 20 May 2020, 15:40

is this the way to continue???? It does not work but advise please.

On switch1#State do
if [switch1#State]=1
event,generalswitch
endif
endon

On generalswitch do
if [switch1#State]=1
gpio,0,1
else
gpio,0,0
endif
endon

User avatar
grovkillen
Core team member
Posts: 3584
Joined: 19 Jan 2017, 12:56
Location: Hudiksvall, Sweden
Contact:

Re: Rules using 'OR"

#7 Post by grovkillen » 20 May 2020, 16:49

Try this (GPIO 14 just as an example):

Code: Select all

On switch1#State do
GPIO,14,[switch1#State#Z]
endon
Or inverted:

Code: Select all

On switch1#State do
GPIO,14,[switch1#State#!Z]
endon
ESP Easy Flasher [flash tool and wifi setup at flash time]
ESP Easy Webdumper [easy screendumping of your units]
ESP Easy Netscan [find units]
Official shop: https://firstbyte.shop/
Sponsor ESP Easy, we need you :idea: :idea: :idea:

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

Re: Rules using 'OR"

#8 Post by Dick60 » 20 May 2020, 17:28

this is working
On switch1#State do
GPIO,14,[switch1#State#Z]
endon

but how can I use the 'OR'' statement
if switch1=1 or switch2=1

the Generalswitch must be set to 1

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

Re: Rules using 'OR"

#9 Post by Ath » 20 May 2020, 17:33

You're almost there, something like this should work:

Code: Select all

On switch1#State do
  event,generalswitch
endon

On switch2#State do
  event,generalswitch
endon

On generalswitch do
  if [switch1#State]=1 or [switch2#State]=1
    gpio,0,1  // Turn on
  else
    gpio,0,0  // Turn off
  endif
endon

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

Re: Rules using 'OR"

#10 Post by Dick60 » 20 May 2020, 18:03

Thanks a lot for all the support. Now it makes sence to implement it in my project.
Have a great day.

Post Reply

Who is online

Users browsing this forum: No registered users and 19 guests