nt.ItemStatePredictedEvent

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

If you would post all logInfo lines while you see such hysteris we could be of more help.

Does using the method, opposed to the action, to turn the fan ON/OFF make a difference?
Example, rule parts like this:

sendCommand(Bryter_Kjeller_Bad, OFF)

changed to this:

Bryter_Kjeller_Bad.sendCommand(OFF)

As OH rules can be a bit odd, something else you might can try is changing

if (Bryter_Kjeller_Bad.state == ON) {
sendCommand(Bryter_Kjeller_Bad, OFF)
}

to

if (Bryter_Kjeller_Bad.state != OFF) {
Bryter_Kjeller_Bad.sendCommand(OFF)
}

???

To quote,

I don’t think this is your problem, but it can give odd effects.

May we see your Item definition please?

How would a state update actually turn your fan off?

Log excerpt.

Fuktighet #1 = humidity of sensor in %
Bryter = Switch which controls the fan

2019-03-18 20:36:00.007 [INFO ] [rthome.model.script.Rules started…] - Rules - baderomsvifte:

2019-03-18 20:36:00.017 [INFO ] [smarthome.model.script.Baderomsvifte] - Startes automatisk. Vil være aktiv i 90 minutter. Fuktighet = 53

==> /var/log/openhab2/events.log <==

2019-03-18 20:36:00.021 [ome.event.ItemCommandEvent] - Item ‘Bryter_Kjeller_Bad’ received command ON

2019-03-18 20:36:00.022 [nt.ItemStatePredictedEvent] - Bryter_Kjeller_Bad predicted to become OFF

==> /var/log/openhab2/openhab.log <==

2019-03-18 20:36:00.026 [INFO ] [rthome.model.script.Rules started…] - 4

2019-03-18 20:36:00.027 [INFO ] [smarthome.model.script.Baderomsvifte] - --------------------------------------------------------------------

2019-03-18 20:36:00.030 [INFO ] [smarthome.model.script.Baderomsvifte] - now = 20:36:00

2019-03-18 20:36:00.032 [INFO ] [smarthome.model.script.Baderomsvifte] - Fuktighet #1 = 53

2019-03-18 20:36:00.035 [INFO ] [smarthome.model.script.Baderomsvifte] - Fuktighet #2 = 20

2019-03-18 20:36:00.037 [INFO ] [smarthome.model.script.Baderomsvifte] - Bryter er __ = OFF

2019-03-18 20:36:00.040 [INFO ] [smarthome.model.script.Baderomsvifte] - fanRunning _ = true

2019-03-18 20:36:00.042 [INFO ] [smarthome.model.script.Baderomsvifte] - startTime ms = 1552941360006

2019-03-18 20:36:00.046 [INFO ] [smarthome.model.script.Baderomsvifte] - startTime = 20:36:00

2019-03-18 20:36:00.048 [INFO ] [smarthome.model.script.Baderomsvifte] - stopTime ms_ = 1552946760006

2019-03-18 20:36:00.051 [INFO ] [smarthome.model.script.Baderomsvifte] - stopTime _ = 22:06:00

2019-03-18 20:36:00.053 [INFO ] [smarthome.model.script.Baderomsvifte] - run time ms = 5400000

2019-03-18 20:36:00.056 [INFO ] [smarthome.model.script.Baderomsvifte] - run time = 01:30:00

2019-03-18 20:36:00.058 [INFO ] [smarthome.model.script.Baderomsvifte] - Min.aktiv = 90

==> /var/log/openhab2/events.log <==

2019-03-18 20:36:45.296 [vent.ItemStateChangedEvent] - Fuktighet_Bad_Kjeller_1 changed from 53 to 69

==> /var/log/openhab2/openhab.log <==

2019-03-18 20:36:45.319 [INFO ] [rthome.model.script.Rules started…] - Rules - baderomsvifte:

2019-03-18 20:36:45.366 [INFO ] [smarthome.model.script.Baderomsvifte] - Startes automatisk. Vil være aktiv i 90 minutter. Fuktighet = 69

==> /var/log/openhab2/events.log <==

2019-03-18 20:36:45.375 [ome.event.ItemCommandEvent] - Item ‘Bryter_Kjeller_Bad’ received command ON

2019-03-18 20:36:45.378 [nt.ItemStatePredictedEvent] - Bryter_Kjeller_Bad predicted to become OFF

==> /var/log/openhab2/openhab.log <==

2019-03-18 20:36:45.382 [INFO ] [rthome.model.script.Rules started…] - 4

2019-03-18 20:36:45.384 [INFO ] [smarthome.model.script.Baderomsvifte] - --------------------------------------------------------------------

2019-03-18 20:36:45.388 [INFO ] [smarthome.model.script.Baderomsvifte] - now = 20:36:45

2019-03-18 20:36:45.392 [INFO ] [smarthome.model.script.Baderomsvifte] - Fuktighet #1 = 69

2019-03-18 20:36:45.396 [INFO ] [smarthome.model.script.Baderomsvifte] - Fuktighet #2 = 20

Removed the imports, but i did not help!

Item that controls the socket where the fan is connected
Switch Bryter_Kjeller_Bad “Vifte kjeller” {channel=“zwave:device:168f1450dab:node3:switch_binary”} <—><------>// TKB_HOME_1

Most likely this is happening because of some bad code on my part, but I can’t find it…

Thanx for your suggestions

Tried your suggestions regarding logic, but did not change anything.

Does OH really read the two logic examples you gave differently? .stat==ON is treated different than .state != OFF? What other states can a .state have besides NULL (if it is off the network for some reason)?

I don’t see any evidence that your Switch item Bryter_Kjeller_Bad ever changes state at all.
We can see in your events.log that it gets sent command ON, I think you’ve said that the fan actually runs, is that correct?

The autoupdate prediction of OFF in response to the command suggests that the binding isn’t expecting a state change, i.e. the binding sees some problem.

The autoupdate prediction of OFF doesn’t actually do anything if the Item’s state is already OFF, and that does seem to be the case.

I think you need to look into your zwave setup, because it doesn’t look like your fan switch is giving any feedback about status to openHAB. Fix that first, then worry at the rule.

UNDEF is used by some bindings to indicate communication or similar problems.

Ok, I look into the z-wave bindings.

The fan starts and stops several times within seconds. The light indicator of the socket has a frequency of what to expect of an light strobe at a rave party.

Guess I need to roll back and look at the system with a new set of eyes…

Remove the rule for now, and just put a switch in your sitemap for the fan. can you control it? Do you get feedback from the device?`

Yepp. I can manually controll it…

Solved the problem. And it was of course a typo by me.

The part that should turn off the fan,

if( (Bryter_Kjeller_Bad.state == ON) && ( (timestamp < stopTimestamp) || ( (manuellStart == false ) && ( (humidity > 0) && (humidity < HumidityLowLimit) )) )) {
}

I should be checking wehter timestamp is GREATER THAN stopTimestamp, NOT LESS. So changing (timestamp < stopTimestamp) to (timestamp > stopTimestamp) solved my issue…

Tanks for all suggestions to my problem!