[SOLVED] Rules with multiple complexe IF conditions

Hi guys,

I tried to configure a rule to switch on a light during the night and in order of the presence of my mobile.
So I tried this way:

if ( (Tageszeit.state == "NIGHT" || Tageszeit.state == "CIVIL_DAWN") && 
            (Phone1_Online.state == OPEN || Phone2_Online.state == OPEN)){

        logInfo("Abenddämmerung", "Flurlicht angeschaltet!")
        Flur_SmartPlug.sendCommand(ON)
}

But its not working out and I don’t really know why. Are these conditions too complexe for OH?
If I put the “Phone”-Conditions into an seperate IF-statement, it’s fine:

if ( Tageszeit.state == "NIGHT" || Tageszeit.state == "CIVIL_DAWN") { 
     if (Phone1_Online.state == OPEN || Phone2_Online.state == OPEN){
           
           logInfo("Abenddämmerung", "Flurlicht angeschaltet!")
           Flur_SmartPlug.sendCommand(ON)
     }
}        

But I personally don’t like to have IF-statements in another IF-statements.

Does someone got a different way to realize that or can someone tell me where i got my mistake in the first part.

Thx for your help!

cheers
Hannes

I can’t see anything wrong with that.

Does it work if you only have one phone state to check?

if ( (Tageszeit.state == "NIGHT" || Tageszeit.state == "CIVIL_DAWN") &&  Phone1_Online.state == OPEN )

EDIT: I just found this rule that I had:

if (coffee_machine_powermode.state == "Schedule" && (heating_timeofday.state == "MORNING" || heating_timeofday.state == "DAY"))

I don’t have the extra OR on the power mode though.

I think you need another layer of parentheses around your IF statements, viz.

if ((Phone1_Online.state == OPEN) || (Phone2_Online.state == OPEN))

Something needs to evaluate to true or false on either side of your ||

As a state is a state and no string, you maybe have to use

if ( (Tageszeit.state.toString == "NIGHT" || Tageszeit.state.toString == "CIVIL_DAWN") && 
            (Phone1_Online.state == OPEN || Phone2_Online.state == OPEN)){

instead.

Hi @ all,
thanks for the fast responses.
I got a really strange behavior with my system. This morning i did a reboot of the system and went on trying different stuff. And now, some magic happened, and my first code is working great!

rule "Flur-Nachtlicht Automatik AN"
    when 
        Channel 'astro:sun:home:night#event' triggered START or
        Item Phone1_Online changed to OPEN or
        Item Phone2_Online changed to OPEN
    then 
        if ( (Tageszeit.state == "NIGHT" || Tageszeit.state == "CIVIL_DAWN") &&
            (Phone1_Online.state == OPEN || Phone2_Online.state == OPEN)){
            logInfo("Abenddämmerung", "Flurlicht angeschaltet!")
            Flur_SmartPlug.sendCommand(ON)
        }
    end

I don’t know what problem OH got, but will see if this will happen again in the future, maybe after the next reboot.

For completeness and as inspiration for other newbees, thats my rule to switch off the light when I’m leaving or night is over.

rule "Flur-Nachtlicht Automatik Aus"
    when 
        Channel 'astro:sun:home:civilDawn#event' triggered END or
        Item Phone1_Online changed to CLOSED or
        Item Phone2_Online received command CLOSED
    then
        if ( Tageszeit.state == "NIGHT" || Tageszeit.state == "CIVIL_DAWN"){ 
            if (Phone1_Online.state == CLOSED || Phone2_Online.state == CLOSED){
            logInfo("Abwesenheit", "Flurlicht ausgeschaltet!")
            Flur_SmartPlug.sendCommand(OFF)
            }
        }
        if( Tageszeit.state != "NIGHT" || Tageszeit.state != "CIVIL_DAWN"){
            Flur_SmartPlug.sendCommand(OFF)
            logInfo("Morgendämmerung", "Flurlicht ausgeschaltet!")
        }
    end
// => I'm using the fritzboxtr064 Binding for presence recognition

@Udo_Hartmann, yeah I thought the same but it worked as designed in the manual of the Astro binding.

Thanks again!

Cheers Hannes