Rules with combining logic

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
Elektrofreak
Normal user
Posts: 22
Joined: 03 Mar 2016, 09:06

Rules with combining logic

#1 Post by Elektrofreak » 05 Apr 2017, 12:08

Hi all,

I am planning to use a SONOFF with a BH1750 luminosity sensor to control a secondary lamp in a bath room. The ESP will be used without an external controller but with the internal rules.

What I understand is the following example rule:

Code: Select all

On brightness#lux do
  if [brighness#lux]>1  // Master light switched on, so turn on relais
    gpio,12,1
    gpio,13,0    
  endif
endon
On brightness#lux do
  if [brighness#lux]<50  // Master light switched off but light connected to relais still on, so turn off relais
    gpio,12,0
    gpio,13,1    
  endif
endon
The problem is that the trigger level for turning off is higher than the trigger level for turning on. Thus, I need to take also the current state into consideration. The device monitoring the relais IO is called relais. So I would like to use something like this:

Code: Select all

On brightness#lux do
  if [brighness#lux]>1 and [relais#relais] == 0  // Master light switched on, so turn on relais
    gpio,12,1
    gpio,13,0    
  endif
endon
On brightness#lux do
  if [brighness#lux]<50 and [relais#relais] != 0 // Master light switched off but light connected to relais still on, so turn off relais
    gpio,12,0
    gpio,13,1    
  endif
endon
But I already crashed the config once and the brightness sensor connected to the SONOFF uses the (disabled) RX and TX lines so I need to re-flach each time I mess up the config :cry: .

Could you tell me if my idea with a combining "and" is possible? Would it be possible to interleave two if loops?


Please help :roll:

paxi
Normal user
Posts: 121
Joined: 02 Feb 2017, 00:48
Location: Germany

Re: Rules with combining logic

#2 Post by paxi » 06 Apr 2017, 22:41

The rules tutorial states that neither boolean logic nor nesting is supported. :?
You can work around this limitation by creating another rule:

Code: Select all

On event1 do
  If condition1 is met
   Event checkAND 
Endon

On checkAND do
   If condition2 is met
    Desired action
Endon

Elektrofreak
Normal user
Posts: 22
Joined: 03 Mar 2016, 09:06

Re: Rules with combining logic

#3 Post by Elektrofreak » 18 Apr 2017, 08:26

Thank you for your reply. I will test it and give feedback ;)

User avatar
toffel969
Normal user
Posts: 469
Joined: 03 Jan 2017, 10:58
Location: Germany

Re: Rules with combining logic

#4 Post by toffel969 » 18 Apr 2017, 20:24

paxi wrote:
06 Apr 2017, 22:41
The rules tutorial states that neither boolean logic nor nesting is supported. :?
You can work around this limitation by creating another rule:

Code: Select all

On event1 do
  If condition1 is met
   Event checkAND 
Endon

On checkAND do
   If condition2 is met
    Desired action
Endon
It definitely works. @paxi, I allowed myself to use above to update the rules tutorial in the wiki, trusting it's OK for you
Domoticz on Raspi 2 -- 14 ESP units (hacked Sonoff,NodeMCUs, Wemos, self-built units) running with RC140- Mega 2.0.0 dev8

Martinus

Re: Rules with combining logic

#5 Post by Martinus » 18 Apr 2017, 20:32

You should also be able to use a condition directly within the "on xxx" line like this sample that i'm using:

Code: Select all

on OutsideLDR#Lux<50 do
  if [Lights#Hal]=0
    SerialSend 10;NewKaku;123454;2;ON;
    SerialSend 10;NewKaku;123455;2;ON;
    TaskValueSet 3,1,1
  endif
endon

paxi
Normal user
Posts: 121
Joined: 02 Feb 2017, 00:48
Location: Germany

Re: Rules with combining logic

#6 Post by paxi » 24 Apr 2017, 09:21

I feel honored toffel969. ;)
Martinus' solution is way more elegant for cases where at least one condition depends on the variable triggering the event. Mine is 'universal'. :D

User avatar
toffel969
Normal user
Posts: 469
Joined: 03 Jan 2017, 10:58
Location: Germany

Re: Rules with combining logic

#7 Post by toffel969 » 24 Apr 2017, 09:28

paxi wrote:
24 Apr 2017, 09:21
I feel honored toffel969. ;)
Martinus' solution is way more elegant for cases where at least one condition depends on the variable triggering the event. Mine is 'universal'. :D
I know :-) I use both of them in combination for MONSTER-rules ;-)
Domoticz on Raspi 2 -- 14 ESP units (hacked Sonoff,NodeMCUs, Wemos, self-built units) running with RC140- Mega 2.0.0 dev8

Post Reply

Who is online

Users browsing this forum: No registered users and 15 guests