Rules "OR" Statement

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
getget
New user
Posts: 4
Joined: 02 Mar 2018, 20:53

Rules "OR" Statement

#1 Post by getget » 02 Mar 2018, 21:00

Hello, in a rule I need to do either a "OR" between two inputs or if it's not possible an imbricated if.
It does not seem to work, how can I do :(

I want to do this :

Code: Select all

on BP_Montee#Pressed=1 do 
	if [GPIO-12#Active]=1 OR [GPIO-5#Active]=1 
		Publish domoticz/in, {"idx":87, "command":"switchlight", "switchcmd":"Stop"}
		gpio,12,0
		gpio,5,0
		Delay 100
		timerset,1,0 
	else
		Publish domoticz/in, {"idx":87, "command":"switchlight", "switchcmd":"On"} 
		gpio,12,0 
		Delay 500 
		gpio,5,1 
		timerset,1,15 
	endif
endon

The other possibility is :

Code: Select all

on BP_Montee#Pressed=1 do 
	if [GPIO-12#Active]=1 
		Publish domoticz/in, {"idx":87, "command":"switchlight", "switchcmd":"Stop"}
		gpio,12,0
		gpio,5,0
		Delay 100
		timerset,1,0 
	else
		if [GPIO-5#Active]=1
			Publish domoticz/in, {"idx":87, "command":"switchlight", "switchcmd":"Stop"}
			gpio,12,0
			gpio,5,0
			Delay 100
			timerset,1,0 
		else 
			Publish domoticz/in, {"idx":87, "command":"switchlight", "switchcmd":"On"} 
			gpio,12,0 
			Delay 500 
			gpio,5,1 
			timerset,1,15 
		endif
	endif
endon

Both should do the same but doesn't work :(
Last edited by getget on 03 Mar 2018, 14:26, edited 2 times in total.

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

Re: Rules "OR" Statement

#2 Post by grovkillen » 02 Mar 2018, 21:11

Have you studied the wiki? Your code tells me no.

Just this last week a basic AND OR was introduced, not documented yet.
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:

getget
New user
Posts: 4
Joined: 02 Mar 2018, 20:53

Re: Rules "OR" Statement

#3 Post by getget » 02 Mar 2018, 21:24

I checked, double checked here before posting :
https://www.letscontrolit.com/wiki/inde ... rial_Rules

and here :
https://www.letscontrolit.com/wiki/inde ... _Reference

But didn't found :(

Will keep searching ... but searching for a non documented function seems not so easy.


getget
New user
Posts: 4
Joined: 02 Mar 2018, 20:53

Re: Rules "OR" Statement

#5 Post by getget » 03 Mar 2018, 14:29

With the last version of Mega it woks. I had an "old" 2.0 version.

Code: Select all

on BPM#Switch=1 do 
	if [GPIO-12#Switch]=1 OR [GPIO-5#Switch]=1 
		//Publish domoticz/in, {"idx":87, "command":"switchlight", "switchcmd":"Stop"}
		gpio,12,0
		gpio,5,0
		Delay 100
		timerset,1,0 
	else
		//Publish domoticz/in, {"idx":87, "command":"switchlight", "switchcmd":"On"} 
		gpio,12,0 
		Delay 500 
		gpio,5,1 
		timerset,1,15 
	endif
endon

on BPD#Switch=1 do 
	if [GPIO-12#Switch]=1 OR [GPIO-5#Switch]=1 
		//Publish domoticz/in, {"idx":87, "command":"switchlight", "switchcmd":"Stop"}
		gpio,12,0
		gpio,5,0
		Delay 100
		timerset,1,0 
	else
		//Publish domoticz/in, {"idx":87, "command":"switchlight", "switchcmd":"Off"} 
		gpio,5,0 
		Delay 500 
		gpio,12,1 
		timerset,1,15 
	endif
endon

on Rules#Timer=1 do
	timerset,1,0
	gpio,12,0
	gpio,5,0
	Delay 100
endon

kimot
Normal user
Posts: 190
Joined: 12 Oct 2017, 20:46

Re: Rules "OR" Statement

#6 Post by kimot » 05 Mar 2018, 14:16

@getget
You not reading very thoroughly
Nested "if" is not allowed:
https://www.letscontrolit.com/wiki/inde ... rial_Rules

" BUT, only simple if/else is possible - so nesting and Boolean logic are not supported. However there is a workaround for the limitation of not being able to nest. An "event" can be called from a "trigger".

on <trigger> do
if <test1>
event <EventName1>
endif
endon

on <EventName1> do
if <test2>
<action>
endif
endon"

In your original rules I can see:

Code: Select all

on BP_Montee#Pressed=1 do 
	if [GPIO-12#Active]=1 
		.
		.
		
	else
		if [GPIO-5#Active]=1
			.
			.
			

getget
New user
Posts: 4
Joined: 02 Mar 2018, 20:53

Re: Rules "OR" Statement

#7 Post by getget » 05 Mar 2018, 14:59

This was just to show what I wanted to do not actual code.

Post Reply

Who is online

Users browsing this forum: No registered users and 120 guests