- Platform information:
- OS: Synology
- openHAB version: 2.5
Hardware related:
- Z-wave stick serial controller
- Z-wave Motion sensor
- Z-wave Dimmer
Goal
When I light up the light with the dimmer or the motion controller, stay on for 60 seconds unless I close the light manually or the motion detector still see me.
Tools
Timer, reschedule, if, loginfo, design pattern.
Problem
-
With the motion detector it works almost always but some motion detectors doesn’t want to be trigged on again after the 60 seconds.
-
When I put the light on manually, no timer is started and I don’t see any log saying the dimmer has changed state so I suspect this is why it doesn’t work. I only see the Z-wave stick had some movement.
-
My items name are long and I see people having short easy to read name, where do I do that? (“zwave_device_129fb235_node18_switch_dimmer” could just be “Shop_Dimmer”).
Rule code
var Timer StairTimer = null
rule "Stair light Motion"
when
Item zwave_device_129fb235_node20_alarm_motion changed from OFF to ON
then
if(StairTimer === null || StairTimer.hasTerminated()) {
logInfo('test', " Stair motion detected; switching Stair light to on")
zwave_device_129fb235_node18_switch_dimmer.sendCommand(100)
}
else {
StairTimer.reschedule(now.plusSeconds(60))
logInfo('test', " Stair timer restarted by motion detector")
}
end
rule "Stair light Timer"
when
Item zwave_device_129fb235_node18_switch_dimmer changed
then
if (zwave_device_129fb235_node18_switch_dimmer.state > (0) && StairTimer !== null) {
StairTimer.reschedule(now.plusSeconds(60))
logInfo('test', " Stair timer restarted by switch > 0")
}
if (zwave_device_129fb235_node18_switch_dimmer.state == (0)) {
StairTimer = null
logInfo('test', " Stair timer cancelled by switch = 0")
}
if (zwave_device_129fb235_node18_switch_dimmer.state > (0) && StairTimer === null) {
logInfo('test', " Stair timer started")
StairTimer = createTimer(now.plusSeconds(60), [|
zwave_device_129fb235_node18_switch_dimmer.sendCommand(0)
logInfo('test', " Stair timer to zero, closing light")
StairTimer = null
logInfo('test', " Stair timer cancelled by expiration")
])
}
end
Log
19:54:33.990 [INFO ] [smarthome.event.ItemStateChangedEvent] -
wave_serial_zstick_129fb235_serial_sof changed from 179258 to 179259
19:54:34.541 [INFO ] [smarthome.event.ItemStateChangedEvent] - zwave_serial_zstick_129fb235_serial_sof changed from 179259 to 179260
19:54:34.562 [INFO ] [g.eclipse.smarthome.model.script.test] - Stair motion detected; switching Stair light to on
19:54:34.565 [INFO ] [smarthome.event.ItemStateChangedEvent] - zwave_device_129fb235_node20_alarm_motion changed from OFF to ON
19:54:34.592 [INFO ] [smarthome.event.ItemCommandEvent ] - Item 'zwave_device_129fb235_node18_switch_dimmer' received command 100
19:54:34.630 [INFO ] [arthome.event.ItemStatePredictedEvent] - zwave_device_129fb235_node18_switch_dimmer predicted to become 100
19:54:34.650 [INFO ] [g.eclipse.smarthome.model.script.test] - Stair timer started
19:54:34.651 [INFO ] [smarthome.event.ItemStateChangedEvent] - zwave_device_129fb235_node18_switch_dimmer changed from 0 to 100
19:54:34.686 [INFO ] [smarthome.event.ItemStateChangedEvent] - zwave_serial_zstick_129fb235_serial_ack changed from 30677 to 30678
19:54:34.701 [INFO ] [smarthome.event.ItemStateChangedEvent] - zwave_serial_zstick_129fb235_serial_sof changed from 179260 to 179261
19:54:35.000 [INFO ] [smarthome.event.ItemStateChangedEvent] - zwave_serial_zstick_129fb235_serial_sof changed from 179261 to 179262
19:54:58.477 [INFO ] [smarthome.event.ItemStateChangedEvent] - zwave_serial_zstick_129fb235_serial_sof changed from 179262 to 179263
19:54:59.013 [INFO ] [smarthome.event.ItemStateChangedEvent] - zwave_serial_zstick_129fb235_serial_sof changed from 179263 to 179264
19:54:59.033 [INFO ] [smarthome.event.ItemStateChangedEvent] - zwave_device_129fb235_node20_alarm_motion changed from ON to OFF
19:55:07.941 [INFO ] [smarthome.event.ItemStateChangedEvent] - zwave_serial_zstick_129fb235_serial_sof changed from 179264 to 179265
19:55:07.961 [INFO ] [smarthome.event.ItemStateChangedEvent] -
19:55:08.498 [INFO ] [smarthome.event.ItemStateChangedEvent] - zwave_serial_zstick_129fb235_serial_sof changed from 179265 to 179266
19:55:09.509 [INFO ] [smarthome.event.ItemStateChangedEvent] - zwave_serial_zstick_129fb235_serial_sof changed from 179266 to 179267
19:55:09.802 [INFO ] [smarthome.event.ItemStateChangedEvent] - zwave_serial_zstick_129fb235_serial_sof changed from 179267 to 179268
19:55:09.818 [INFO ] [smarthome.event.ItemStateChangedEvent] - zwave_device_129fb235_node20_sensor_luminance changed from 0 to 2
19:55:10.433 [INFO ] [smarthome.event.ItemStateChangedEvent] - zwave_serial_zstick_129fb235_serial_sof changed from 179268 to 179269
Thanks!
Robin