- Platform information:
- Hardware: Intel CPU
- OS: Ubuntu 16.04
- Java Runtime Environment: Java™ SE Runtime Environment (build 1.8.0_151-b12
- openHAB version: 2.3.0
- Issue of the topic:
In a rule, I am checking the temperature of the bedroom in a loop at night to determine if a ceiling fan should be ON or OFF every minute using Thread::sleep(60000). Randomly (roughly 50% of the time), everything in the OH log appears to stop for the entire minute.
The rule is;
var Timer lightTimer = null
var Timer fanTimer = null
var Timer fanNightTimer = null
val int temperatureComfortThreshold = 72
val int timeoutMinutes = 5 // choose an appropriate value
val int fanTimeoutMinutes = 7
val int fanNightMinutes = 540 // 9 hours from 10 to 7
val LocalTime wakeupTime = new LocalTime(7, 0) // 7am every day
val LocalTime lightsOutTime = new LocalTime(22, 0) // 10pm every day
rule "MasterBedroomMotionLight received ON"
when
Item MasterBedroomMotion changed from OFF to ON
then
logInfo("openhab", "Wake up time is {}", wakeupTime.toString)
logInfo("openhab", "Luminance level is {}", (MasterBedroomLuminance.state as DecimalType))
if (lightTimer === null) {
if (now.toLocalTime().isAfter(wakeupTime) &&
now.toLocalTime().isBefore(lightsOutTime) &&
((MasterBedroomLuminance.state as DecimalType).intValue < 70) ) {
logInfo("openhab", "Turning Front Bedroom Light On")
MasterBedroomLightSwitch.sendCommand(ON)
MasterBedroomDimmer.sendCommand(99)
lightTimer = createTimer(now.plusMinutes(timeoutMinutes ), [|
logInfo("openhab", "Timer expired, turning Master Bedroom Light Off")
MasterBedroomLightSwitch.sendCommand(OFF)
MasterBedroomDimmer.sendCommand(0)
lightTimer = null
])
}
}
else {
logInfo("openhab", "Front Bedroom Motion Detected when Timer not yet completed")
lightTimer.reschedule(now.plusMinutes(timeoutMinutes ))
}
// For night time fan cooling
// Check to see if the motion occurs after LightsOutTime
if ((now.toLocalTime().isAfter(lightsOutTime)) && (fanNightTimer === null)) {
// reset the fan timer in case it was on, to preclude it from interfering in the fan night timer operation
fanTimer = null
logInfo("openhab", "Fan Night Timer started")
// set the all night timer, as motion will occur infrequently during sleep
fanNightTimer = createTimer(now.plusMinutes(fanNightMinutes ), [|
logInfo("openhab", "Night Timer expired, turning Master Bedroom fan Off")
MasterBedroomFanSwitch.sendCommand(OFF)
fanNightTimer = null
])
while (fanNightTimer !== null) {
//check every 60 seconds to see if the temperature requires the fan on
logInfo("openhab", "Checking the bedroom temperature to see if too warm")
if ((MasterBedroomTemperature.state as DecimalType).intValue > temperatureComfortThreshold ) {
// It is too warm, turn the fan ON if it is not already on
if (MasterBedroomFanSwitch.state == OFF) {
MasterBedroomFanSwitch.sendCommand(ON)
logInfo("openhab", "Too warm at night, turning on fan")
}
}
else {
//Since it is not too warm, if the fan is already on, turn it off
if (MasterBedroomFanSwitch.state == ON) {
MasterBedroomFanSwitch.sendCommand(OFF)
logInfo("openhab", "Cool enough at night, turning off fan")
}
}
Thread::sleep(60000)
}
}
// if not during sleeping hours, turn on for 15 minutes when motion occurs and the temperature is above the setpoint
else {
if ((now.toLocalTime().isAfter(wakeupTime)) && (fanTimer === null) && ((MasterBedroomTemperature.state as DecimalType).intValue > temperatureComfortThreshold )) {
logInfo("openhab", "Turning Fan On during daytime")
MasterBedroomFanSwitch.sendCommand(ON)
fanTimer = createTimer(now.plusMinutes(fanTimeoutMinutes ), [|
logInfo("openhab", "Daytime fan Timer expired, turning Master Bedroom fan Off")
MasterBedroomFanSwitch.sendCommand(OFF)
fanTimer = null
])
}
else {
logInfo("openhab", "Front Bedroom Motion Detected when daytime fan Timer not yet completed")
if ((now.toLocalTime().isAfter(wakeupTime)) && ((MasterBedroomTemperature.state as DecimalType).intValue > temperatureComfortThreshold )) {
logInfo("openhab", "... and temperature is above the setpoint")
fanTimer.reschedule(now.plusMinutes(fanTimeoutMinutes ))
}
}
}
end
I don’t think it is appropriate to put the entire night’s log in here, so I’ll put in snippets where it does and does not happen. Every time the rule thread wakes up, you’ll see the log entry “Checking the bedroom temperature to see if too warm”
2018-07-10 05:10:03.609 [DEBUG] [ssage.ApplicationCommandMessageClass] - NODE 2: Transaction not completed: node address inconsistent. lastSent=2, incoming=255
2018-07-10 05:11:01.433 [INFO ] [lipse.smarthome.model.script.openhab] - Checking the bedroom temperature to see if too warm
2018-07-10 05:12:01.434 [INFO ] [lipse.smarthome.model.script.openhab] - Checking the bedroom temperature to see if too warm
2018-07-10 05:12:03.614 [DEBUG] [WaveSerialHandler$ZWaveReceiveThread] - Receive Message = 01 0E 00 04 00 0B 08 32 02 21 74 00 00 27 31 85
2018-07-10 05:12:19.862 [DEBUG] [ocol.ZWaveController$ZWaveSendThread] - NODE 4: Response processed after 1803ms/1960ms.
2018-07-10 05:13:01.435 [INFO ] [lipse.smarthome.model.script.openhab] - Checking the bedroom temperature to see if too warm
2018-07-10 05:14:01.436 [INFO ] [lipse.smarthome.model.script.openhab] - Checking the bedroom temperature to see if too warm
2018-07-10 05:14:03.625 [DEBUG] [WaveSerialHandler$ZWaveReceiveThread] - Receive Message = 01 0E 00 04 00 0B 08 32 02 21 74 00 00 25 EE 58
2018-07-10 05:14:03.625 [DEBUG] [ve.internal.protocol.ZWaveController] - Receive queue TAKE: Length=0
2018-07-10 05:15:00.990 [DEBUG] [ocol.ZWaveController$ZWaveSendThread] - NODE 2: Response processed after 129ms/1960ms.
2018-07-10 05:15:01.437 [INFO ] [lipse.smarthome.model.script.openhab] - Checking the bedroom temperature to see if too warm
2018-07-10 05:16:01.439 [INFO ] [lipse.smarthome.model.script.openhab] - Checking the bedroom temperature to see if too warm
2018-07-10 05:16:03.642 [DEBUG] [WaveSerialHandler$ZWaveReceiveThread] - Receive Message = 01 14 00 04 00 0B 0E 32 02 21 64 00 00 01 1C 02 58 00 00 01 1A C3
And as you can see, it doesn’t always do this;
2018-07-10 05:18:03.649 [DEBUG] [ssage.ApplicationCommandMessageClass] - NODE 2: Transaction not completed: node address inconsistent. lastSent=2, incoming=255
2018-07-10 05:19:01.442 [INFO ] [lipse.smarthome.model.script.openhab] - Checking the bedroom temperature to see if too warm
2018-07-10 05:19:17.080 [DEBUG] [WaveSerialHandler$ZWaveReceiveThread] - Receive Message = 01 09 00 04 00 04 03 80 03 64 12
At 05:21, the CivilDawn event occurred (see event.log below), which should have shut off the BackPorchLight, but that never showed up on the OH2 log and I had to shut it off myself;
2018-07-08 05:21:00.001 [vent.ChannelTriggeredEvent] - astro:sun:local:civilDawn#event triggered START
2018-07-10 05:20:03.660 [DEBUG] [ssage.ApplicationCommandMessageClass] - NODE 2: Transaction not completed: node address inconsistent. lastSent=2, incoming=255
2018-07-10 05:21:01.444 [INFO ] [lipse.smarthome.model.script.openhab] - Checking the bedroom temperature to see if too warm
2018-07-10 05:22:01.445 [INFO ] [lipse.smarthome.model.script.openhab] - Checking the bedroom temperature to see if too warm
2018-07-10 05:22:03.672 [DEBUG] [WaveSerialHandler$ZWaveReceiveThread] - Receive Message = 01 0E 00 04 00 0B 08 32 02 21 74 00 00 27 14 A0
Did I specify the sleep incorrectly?