I suppose this is less OH related, but being a novice programmer at best I’m failing to wrap my mind around how I could make this into one rule, instead of triggered 3 separate ones. Or maybe it’s not needed at all, in any case, I’d welcome any pointers to streamline the rules.
rule "Gang Lys"
when
Item FrontDoorContact changed from CLOSED to OPEN
then
if(LocalSun_Position_Elevation.state < 0|°) { //Chekcs if the sun has gone down.
GangLys.sendCommand(ON)
}
end
rule "Døren åbnes - ingen hjemme"
when
Item FrontDoorContact changed from CLOSED to OPEN
then
Thread::sleep(45000)
if(KlingeTLF_Online.state == OFF && LottesTLF_Online.state == OFF) { //checks if anyones phone is currently online
sendNotification("my@mail.com", "Hovedøren er blevet åbnet!") //sends notificatioon that the door has been opend and noone is home
}
end
rule " Døren holdes åben - Sluk varmen"
when
Item FrontDoorContact changed from CLOSED to OPEN
then
Thread::sleep(60000) //waits for 1 minute
val Number pHeat = GangTermostat_SetpointHeat.state //Stores the current temperature in a variable.
if( FrontDoorContact.state == OPEN)
GangTermostat_SetpointHeat.sendCommand(8) //Sets temperature to 8 degrees
while(FrontDoorContact.state == OPEN){ //Continues to check if the door has been closed.
Thread::sleep(1000) // sleep for 1 second
}
GangTermostat_SetpointHeat.sendCommand(pHeat) //Resets the temperature to what it was before the door opend.
end
From top to bottom the 3 rules does this:
When the front door opens, check if the sun has gone down, if yes, then turn on the lights in the hallway.
When the front door opens, wait for 45 seconds, then check if anyone’s phone is on the network, if they aren’t notify us both.
When the front door opens, wait for 1 minute. then save the current temperature setting of the radiator to a value. Then check if the door is still open, if yes, set the temperature to 8 degrees. continue to check if the door has been closed every second, if it is, reset the old temperature.