I’m new to OpenHab and i struggeling to get fan running correctly.
When the rule is triggered, the fan gets started, but nt.ItemStatePredictedEvent predicts the fan to be OFF, and turns off the fan. Then again the rules fires the fan up just to be shut down again. Again and again and again.
Why is this happening? My fan is connected to an TDK socket. The item file looks like this:
Switch Bryter_Kjeller_Bad “Vifte kjeller” channel=“zwave:device:168f1450dab:node3:switch_binary”}
And my rule file looks like this:
// Imports
import org.openhab.core.library.types.*
import org.openhab.core.persistence.*
import org.openhab.model.script.actions.*
// Global Variables
var boolean fanRunning = false
var boolean manuellStart = false
var Number humidity = 0
var Number timestamp = 0
var Number startTimestamp = 1
var Number stopTimestamp = 1
var String timeText = “”
var DateTime dateTime
// Constants used to generate this rule
var Number HumidityLowLimit = 45
var Number HumidityHighLimit = 50
var Number runTime = 90 * 60000
var Number DefaultRuntime = 90
rule “Baderomsvifte”
when
Item Fuktighet_Bad_Kjeller_1 changed
or
Item Bryter_Kjeller_Bad changed
or
Time cron “0 0/1 * * * ?”
then
timestamp = now.getMillis
logInfo(“Rules started…”, “Rules - baderomsvifte:”)
if ((Fuktighet_Bad_Kjeller_1.state as DecimalType).intValue > 0) {
humidity = (Fuktighet_Bad_Kjeller_1.state as DecimalType).intValue
} else humidity = 0
if ( (Bryter_Kjeller_Bad.state == OFF) && (fanRunning == true) ) {
fanRunning = false
}
if ( (Bryter_Kjeller_Bad.state == ON) && (humidity > 0) && (humidity < HumidityHighLimit) && (manuellStart == false) && (fanRunning == false) ) {
logInfo(“Baderomsvifte”, “Startet manuelt. Vil være aktiv i " + DefaultRuntime + " minutter.”)
startTimestamp = timestamp
stopTimestamp = startTimestamp + runTime
manuellStart = true
fanRunning = true
}
if ( (Bryter_Kjeller_Bad.state == OFF) && (humidity >= HumidityHighLimit) && (fanRunning == false) ) {
logInfo(“Baderomsvifte”, "Startes automatisk. Vil være aktiv i " + DefaultRuntime + " minutter. Fuktighet = " + humidity.toString)
startTimestamp = timestamp
if (Bryter_Kjeller_Bad.state == OFF) {
sendCommand(Bryter_Kjeller_Bad, ON)
}
fanRunning = true
manuellStart = false
stopTimestamp = startTimestamp + runTime
}
if( (Bryter_Kjeller_Bad.state == ON) && ( (timestamp < stopTimestamp) || ( (manuellStart == false ) && ( (humidity > 0) && (humidity < HumidityLowLimit) )) )) {
logInfo(“Baderomsvifte”, “Baderomsvifte skrus av grunnet normal fuktighet eller maks påtid oppnådd, nullstiller timer”)
fanRunning = false
manuellStart = false
if (Bryter_Kjeller_Bad.state == ON) {
sendCommand(Bryter_Kjeller_Bad, OFF)
}
}
end