Going crazy with a rule, please help


(Runar) #1

i made this rule, and honestly I am ripping my hair off. It works in reporting statuses, but the last part of turning on and off items doesnt. What am I doing wrong?

rule "Bortemodus sjekk"

when
Item Bortemodus changed from OFF to ON

then

// sende pushmelding

// sendNotification("Bortemodus aktivert")    
// Sende introstemme til default audiosink
say ("Sjekker dører og vinduer")
Thread::sleep(3000)


 
// Sjekk om dørene er åpne og kringkaste via default audiosink


    if (Verandador_open.state == OPEN)
{
say ("Verandadør åpen")
Thread::sleep(2000)
}


    if (Utgangsdor_apen.state == OPEN)
{
say ("Utgangsdør åpen")
Thread::sleep(2000)
}

    if (Alle_dorer_vinduer.state == OPEN)
{
say ("Bortemodus avbrutt lukk dører og vinduer")
Bortemodus.postUpdate(OFF)
}

// Sjekk om dørene er stengt og kjøre tilsvarende kode


    if (Verandador_open.state == CLOSED)
    if (Utgangsdor_apen.state == CLOSED)

{
say ("Alle dører og vinduer stengt" )
Thread::sleep(2000)
say ("Utetemperaturen er" + Yahoo_temp_ute.state)
Thread::sleep(3000)
say ("GOD TUR, håper du finner veien tilbake, slår av lys og senker temperatur om 5 sekunder")

// Slå av alle lys

   
Thread::sleep(5000)
Alle_lys.sendCommand(OFF)

 
say ("Slår på bortemodus om 5 sekunder")

Thread::sleep(5000)
Bortedetect.postUpdate(ON)
Thread::sleep(1000)
Bortemodus.postUpdate(OFF)



}

end


(Mark) #2
Bortedetect.postUpdate(ON)
Thread::sleep(1000)
Bortemodus.postUpdate(OFF)

Why are you using postUpdate instead of sendCommand?


(Mark) #3

One other thing you should be aware of, since you’re using Thread::sleep pretty extensively.


(Miika Jukka) #4

Please fix code fences in your post so that it’s easier to read and the indentation shows properly. Might be some of those if statements are skipped because of missing curly brackets. Does your rule give any errors?


(Rossko57) #5

Something amiss there. Was that supposed to be an OR?
if ( Verandador_open.state == CLOSED || Utgangsdor_apen.state == CLOSED ) {


(Josar) #6

Missing } ?

And as @rossko57 said i think you want to have both criteria to be true., so you could use a AND.

if (Verandador_open.state == CLOSED && Utgangsdor_apen.state == CLOSED) 
{ 

(Udo Hartmann) #7

Code seems to be almost ok to me:

rule "Bortemodus sjekk"
when
    Item Bortemodus changed from OFF to ON
then
    // sende pushmelding
    // sendNotification("Bortemodus aktivert")    
    // Sende introstemme til default audiosink
    say ("Sjekker dører og vinduer")
    Thread::sleep(3000)
    // Sjekk om dørene er åpne og kringkaste via default audiosink
    if (Verandador_open.state == OPEN) {
        say ("Verandadør åpen")
        Thread::sleep(2000)
    }
    if (Utgangsdor_apen.state == OPEN) {
        say ("Utgangsdør åpen")
        Thread::sleep(2000)
    }
    if (Alle_dorer_vinduer.state == OPEN) {
        say ("Bortemodus avbrutt lukk dører og vinduer")
        Bortemodus.postUpdate(OFF)
    }
    // Sjekk om dørene er stengt og kjøre tilsvarende kode
    if (Verandador_open.state == CLOSED) 
        if(Utgangsdor_apen.state == CLOSED) {
            say ("Alle dører og vinduer stengt" )
            Thread::sleep(2000)
            say ("Utetemperaturen er" + Yahoo_temp_ute.state)
            Thread::sleep(3000)
            say ("GOD TUR, håper du finner veien tilbake, slår av lys og senker temperatur om 5 sekunder")
            // Slå av alle lys
            Thread::sleep(5000)
            Alle_lys.sendCommand(OFF)
            say ("Slår på bortemodus om 5 sekunder")
            Thread::sleep(5000)
            Bortedetect.postUpdate(ON)
            Thread::sleep(1000)
            Bortemodus.postUpdate(OFF)
        }
end

One thing is the line

say ("Utetemperaturen er" + Yahoo_temp_ute.state)

As a state is a state, please use

say ("Utetemperaturen er" + Yahoo_temp_ute.state.toString)

instead.

Many Thread::sleep() commands with long sleep time is a really bad idea.
Please be aware that openHAB works asynchronous, you need to prevent the rule to be executed more than once per 17 seconds (cumulated Thread::sleep() time plus 1)

Would be better to use another approach for the functionality. :wink:


(Runar) #8

Thank you all for your hjelp :grinning: I tried with a timer, tried rewriting the rule, but. Very unstable and noe other simple rules stopped working as Wellington :thinking:. Think its a problem with OH 2.4 M5. So I will wait for an update and see if IT helps. Thank you again. Will post the new rules when I get home :wink:


(Runar) #9

Pardon my autocorrect :joy::joy::joy: