[SOLVED] Switch of fan timer rule

I am trying to create a timer that starts the fan when someone comes into the room (use the change of tradfri light to indicate that). Based on a script I found in the internet - it seems to work, but then copied for another room and there the power off after a while did not work. I double checked the code but found no differences - any idea?

kind of working:
var Timer WCHerrenLuefterTimer = null
val int WCHerrenLuefterTimeoutMinutes = 20

rule "WC Herren"
when
        Item DeckenkeuchteWCHerren_Helligkeit changed to 100
then
        sendCommand(WaschraumHerrenWC_Switch2, ON)
end

rule "WC Herren automatisch aus"
when
        Item WaschraumHerrenWC_Switch2 changed to ON
then
        if(WCHerrenLuefterTimer === null) {
                WCHerrenLuefterTimer = createTimer(now.plusMinutes(WCHerrenLuefterTimeoutMinutes ), [|
                        sendCommand(WaschraumHerrenWC_Switch2, OFF)
                        WCHerrenLuefterTimer = null
                ])
        }
        else {
                WCHerrenLuefterTimer.reschedule(now.plusMinutes(WCHerrenLuefterTimeoutMinutes ))
        }
end

here the fan starts but timer never switches of the fan

var Timer WCDamenLuefterTimer = null
val int WCDamenLuefterTimeoutMinutes = 20

rule "WC Damen"
when
        Item DeckenkeuchteWCDamen_Helligkeit changed to 100
then
        sendCommand(WaschraumWCDamen_Switch2, ON)
        sendTelegram("bot1", "item WaschraumWCDamen_Switch2 to %s", WaschraumWCDamen_Switch2.state.toString)
end

rule "WC Damen automatisch aus"
when
        Item WaschraumWCDamen_Switch2 changed to ON
then
        if(WCDamenLuefterTimer === null) {
                WCDamenLuefterTimer = createTimer(now.plusMinutes(WCDamenLuefterTimeoutMinutes ), [|
                        sendCommand(WaschraumDamenWC_Switch2, OFF)
                        WCDamenLuefterTimer = null
                ])
        }
        else {
                WCDamenLuefterTimer.reschedule(now.plusMinutes(WCDamenLuefterTimeoutMinutes ))
        }
end

or any other timer recommendations?

Seems you have a typo on the item name…

You send the command ON like this :

“sendCommand(WaschraumWCDamen_Switch2, ON)”

and the timer references another item name when sending the OFF command:

“sendCommand(WaschraumDamenWC_Switch2, OFF)”

1 Like

Problems in rules like Item name typos will show up in openhab.log as runtime error messages.

typo ?

1 Like