Hi,
after updating to OH 2.5 my currently used two rules do not work any more.
Setup
I have two Tradfri motion sensors in two different rooms. If they detect motion OH should switch the light (Tradfri E27 bulbs) in the room on.
I’m using zigbee2mqtt/mosquitto with a CC2351 to control the sensors and bulbs.
Rules
$ cat /etc/openhab2/rules/bathroom.sensor.rules
#----------------------------------------------
var Timer lightsOffTimer = null
rule "Motion in bathroom detected"
when
Item Sensor_Motion_GF_Bathroom_Occupancy received update ON
then
logInfo('occupancy_bathroom_on', 'Motion detected.')
Light_GF_Bathroom_CeilingLights_MainLight_Brightness.sendCommand('100')
logInfo('occupancy_bathroom_on', 'Turned Light_GF_Bathroom_CeilingLights_MainLight on.')
if (lightsOffTimer !== null) {
logInfo('occupancy_bathroom_on', 'Further motion detected. Canceled timer to turn off lights.')
lightsOffTimer.cancel()
}
end
rule "No more motion in bathroom detected"
when
Item Sensor_Motion_GF_Bathroom_Occupancy received update OFF
then
logInfo('occupancy_bathroom_off', 'No more motion detected. Room probably unoccupied.')
val currentBrightness = Light_GF_Bathroom_CeilingLights_MainLight_Brightness.state
if(currentBrightness == 0) {
logInfo('occupancy_bathroom_off', 'Lights already off. No need for a change.')
return;
}
logInfo('occupancy_bathroom_off', 'Flash lights to notify about imminent turn out of lights.')
if((currentBrightness as Number) > 50) {
Light_GF_Bathroom_CeilingLights_MainLight_Brightness.sendCommand('25')
Light_GF_Bathroom_CeilingLights_MainLight_Brightness.sendCommand('100')
Light_GF_Bathroom_CeilingLights_MainLight_Brightness.sendCommand('25')
Light_GF_Bathroom_CeilingLights_MainLight_Brightness.sendCommand(currentBrightness.toString)
}
else {
Light_GF_Bathroom_CeilingLights_MainLight_Brightness.sendCommand('15')
Light_GF_Bathroom_CeilingLights_MainLight_Brightness.sendCommand(currentBrightness.toString)
Light_GF_Bathroom_CeilingLights_MainLight_Brightness.sendCommand('15')
Light_GF_Bathroom_CeilingLights_MainLight_Brightness.sendCommand(currentBrightness.toString)
}
logInfo('occupancy_bathroom_off', 'Done flashing lights. Setting timer now.')
lightsOffTimer = createTimer(now.plusSeconds(30), [|
logInfo('occupancy_bathroom_off', 'Timer ended. Turning off lights now.')
Light_GF_Bathroom_CeilingLights_MainLight_Brightness.sendCommand('0')
logInfo('occupancy_bathroom_off', 'Turned off Light_GF_Bathroom_CeilingLights_MainLight.')
lightsOffTimer = null
])
end
The other room has a slightly other rule, but is basically the same that’s why I’m not posting it in order to keep it short here.
Output
OH logs the correct things and seems to switch the light on:
14:09:18.423 [INFO ] [smarthome.event.ItemStateChangedEvent] - Sensor_Motion_GF_Bathroom_Occupancy changed from OFF to ON
14:09:18.428 [INFO ] [me.model.script.occupancy_bathroom_on] - Motion detected.
14:09:18.432 [INFO ] [smarthome.event.ItemStateChangedEvent] - Sensor_Motion_GF_Bathroom_LinkQuality changed from 19.215686274509803155297049670480191707611083984375 to 20.3921568627450966459946357645094394683837890625
14:09:18.452 [INFO ] [smarthome.event.ItemStateChangedEvent] - Sensor_Motion_GF_Bathroom_LastSeen changed from 2019-12-25T13:54:13.000+0100 to 2019-12-25T14:09:18.000+0100
14:09:18.451 [INFO ] [me.model.script.occupancy_bathroom_on] - Turned Light_GF_Bathroom_CeilingLights_MainLight on.
14:09:18.461 [INFO ] [smarthome.event.ItemCommandEvent ] - Item 'Light_GF_Bathroom_CeilingLights_MainLight_Brightness' received command 100
14:09:18.497 [INFO ] [arthome.event.ItemStatePredictedEvent] - Light_GF_Bathroom_CeilingLights_MainLight_Brightness predicted to become 100
14:09:18.514 [INFO ] [smarthome.event.ItemStateChangedEvent] - Light_GF_Bathroom_CeilingLights_MainLight_Brightness changed from 0 to 100
But nothing happens in the real, dark world . The bulbs remain dark. At least for some time. After a couple of minutes (that differs between 2 minutes up to ten to fifteen minutes) the light switches on. So there’s a huge lag somewhere.
Before the update the light switched on immediately. Where does the lag come from? How can I fix it?
Kind regards
- Platform information:
- Hardware: RPi 3B+
- OS: Raspbian GNU/Linux 9
- Java Runtime Environment:
- openjdk version “1.8.0_152”
- OpenJDK Runtime Environment (Zulu Embedded 8.25.0.76-linux-aarch32hf) (build 1.8.0_152-b76)
- OpenJDK Client VM (Zulu Embedded 8.25.0.76-linux-aarch32hf) (build 25.152-b76, mixed mode, Evaluation)
- openHAB version: 2.5.0 (Release Build)