[SOLVED] Rule problem: IF and also ELSE gets executed

Hello,

i got a problem with the following rule: Not even the IF part of the rule gets executed, also the ELSE part gets executed. My plan was that the ELSE part just gets executed, if one of the item states is null for excample.

Can you tell me, what i am doing wrong?

Thanks, Alex

rule "Lueften-Wohnzimmer-Ende"

when
    Item Group_Wohnzimmer_Fenster changed to OFF
then
    sendNotification("xxx@me.com","Alle Fenster geschlossen, Timer WZ gestartet.")
    createTimer(now.plusSeconds(900)) [
        sendNotification("xxx@me.com","Timer WZ abgelaufen.")
        if ((Anwesenheitserkennung.state == ON) && (Group_Wohnzimmer_Fenster.state == OFF)) {
            HM_WZ_Heizung_ActProfile.sendCommand(1)
            sendNotification("xxx@me.com","Heizung WZ auf Anwesenheit stellen")
            }
        if ((Anwesenheitserkennung.state == OFF) && (Group_Wohnzimmer_Fenster.state == OFF)) {
            HM_WZ_Heizung_ActProfile.sendCommand(2)
            sendNotification("xxx@me.com","Heizung WZ auf Abwesenheit stellen")
            }
        else
            HM_WZ_Heizung_ActProfile.sendCommand(HM_WZ_Heizung_ActProfile.previousState.state)
            sendNotification("xxx@me.com","Heizung WZ auf vorheriges Profil stellen")
    ]
end

  • Use if to specify a block of code to be executed, if a specified condition is true
  • Use else to specify a block of code to be executed, if the same condition is false

The first If has no following Else, so the True will either be run or nothing.
The second if has a following, so either the True part will be run or the False (Else) part will be run.
In your example the first If was True and the second False!

Thanks for that! Now i am understanding the behaviour.
Can you even give me an advise, how to get the expected behaviour?

If condition A = true —> do something
If condition B = true —> do something
If all conditions are Not true —> do something

rule "Lueften-Wohnzimmer-Ende"

when
    Item Group_Wohnzimmer_Fenster changed to OFF
then
    sendNotification("xxx@me.com","Alle Fenster geschlossen, Timer WZ gestartet.")
    createTimer(now.plusSeconds(900), | [
        sendNotification("xxx@me.com","Timer WZ abgelaufen.")
        if ((Anwesenheitserkennung.state == ON) && (Group_Wohnzimmer_Fenster.state == OFF)) {
            HM_WZ_Heizung_ActProfile.sendCommand(1)
            sendNotification("xxx@me.com","Heizung WZ auf Anwesenheit stellen")
        } else if ((Anwesenheitserkennung.state == OFF) && (Group_Wohnzimmer_Fenster.state == OFF)) {
            HM_WZ_Heizung_ActProfile.sendCommand(2)
            sendNotification("xxx@me.com","Heizung WZ auf Abwesenheit stellen")
        } else {
            HM_WZ_Heizung_ActProfile.sendCommand(HM_WZ_Heizung_ActProfile.previousState.state)
            sendNotification("xxx@me.com","Heizung WZ auf vorheriges Profil stellen")
        }
    ])
end
1 Like

thank you, and if i got more than two conditions, i would do it like that?

if…
else if…
else if…
else if…
else…

Yep

thanks to all for your help, again! i really love this great community that never hasitates to help someone! its really fun to learn with your help how to deal with the funtions of openhab!