Lux vallue not read when using rule for Motion detection

Hi Guys,

I’m running the latest cloudbees 1.8 version and all is working well except that my rule has some kind of error in it.
i allready used quite a few examples but still i’m unable to reach my goal.
What i’m trying to do is that when is to dark and motion is detected the lights go on , when in a specific period motion is detected again a timer is increased and the lights stayon.
when timer is expired and no motion is detected it should turn off the lights.
as said all is working but the value of the lux item is not read for some reason , can someone assist ?
cause when i check my sitemap the value is around 42 and i’m setting it at lower as 30 to execute the lightswitch.

this is my rule:

import org.openhab.core.library.types.*
import org.openhab.core.persistence.*
import org.openhab.model.script.actions.*
import org.openhab.model.script.actions.Timer
import java.util.Date
import java.util.format

var Timer Bureau_timer = null
var Integer Bureau_timeout = 3

//Licht Bureau fibaro powerplug rules //

rule “BureauLightOn”
when
Item Z_Bureau_Motion changed to OPEN
logInfo (“BureauLightOn”,“Motion has been detected in the room bureau”)
then
if (Z_Bureau_Lux.state as DecimalType < 30)
logInfo (“BureauLightOn”," Measuring Lux state below 30 lux or not"){
if (Bureau_timer != null)
{
Bureau_timer.reschedule(now.plusMinutes(Bureau_timeout))
logInfo(“BureauLightOn”,“Bureau timer rescheduled for " + Bureau_timeout + " minutes”)
}
else
{
sendCommand(Z_Bureau, ON)
logInfo(“BureauLightOn”,“Turning lights on and Bureau timer created with " + Bureau_timeout + " minutes”)
Bureau_timer = createTimer(now.plusMinutes(Bureau_timeout))
[|
if (Z_Bureau_Motion.state == OPEN)
{
Bureau_timer.reschedule(now.plusMinutes(Bureau_timeout))
logInfo(“BureauLightOn”,“Motion has been detected and Bureau timer extended again for " + Bureau_timeout + " minutes”)
}
else
{
sendCommand(Z_Bureau,OFF)
logInfo (“BureauLightOn”," No motion has been detected in the room within " + Bureau_timeout + " minutes")
Bureau_timer = null
}
]
}
}
end

this is my item --> fibaro motion sensor

Contact Z_Bureau_Motion “Bureau_motion” (Bureau,MotionAlarms) { zwave=“2:command=SENSOR_BINARY,respond to basic=TRUE” }
Contact Z_Bureau_Tamper “Bureau_tamper” (Bureau,TamperAlarms) { zwave=“2:command=sensor_alarm,respond to basic=TRUE” }
Number Z_Bureau_Temp “Bureau_temp [%.2f °C]” (Bureau,Temperatures) { zwave=“2:command=sensor_multilevel,sensor_type=1” }
Number Z_Bureau_Lux “Bureau_lux [%.0f Lux]” (Bureau) { zwave=“2:command=sensor_multilevel,sensor_type=3” }
Number Z_bureau_Motion_Bat “Bureau_motion_bat [%d %%]” (Bureau,BatteryLevels) { zwave=“2:command=BATTERY” }

Hi!
The first if statement looks a bit odd to me:
if (Z_Bureau_Lux.state as DecimalType < 30) logInfo ("BureauLightOn"," Measuring Lux state below 30 lux or not") { ... }
Try moving the logInfo() call before the if statement… Additionally my editor does not like the logInfo() call in the when-clause, but I am using 1.7.1, so that might as well work in 1.8, but it’s worth a try moving this logInfo() call directly after the then keyword.

ok i moved it like this

rule “BureauLightOn”
when
Item Z_Bureau_Motion changed to OPEN
logInfo (“BureauLightOn”,“Motion has been detected in the room bureau”)
then
logInfo (“BureauLightOn”," Measuring Lux state below 30 lux or not")
if (Z_Bureau_Lux.state as DecimalType < 30){
if (Bureau_timer != null)
{
Bureau_timer.reschedule(now.plusMinutes(Bureau_timeout))
logInfo(“BureauLightOn”,“Bureau timer rescheduled for " + Bureau_timeout + " minutes”)
}

and this indeed seems to be working :slight_smile: i’ll test a little more !
the rule now ends indeed on the loginfo for lux as should.
are you using the editor from openhab designer ?

thnx for the help
kindest regards

Wolf

Glad that I could help! :smile:

Yes, I’m using the designer for most things, except on-the-fly changes. It has saved my notebook from being thrown out of the window many times. :wink:

i think we screamed yes to soon .
now when its dark it stops at the line loginfo and does not continue ???
any sugestions ?

kindest regards

wolf

At which logInfo exactly does it stop?
What value do you get from Z_Bureau_Lux.state when it’s dark? I suggest you to add the value to the logInfo so you know exactly how the if statements will evaluate.

hi ,
i did make a login info stating the measurement of lux. --> current lux is Z_Bureau_lux.state
and then i see it valued 20 when lights are on and 0 when lights are off --> yeah its real dark in the room :smile:

but still for some reason its not taking the Lux value as primary value point to continue cause my cause is that when there is enough lux so all above 19 it should do nothing.

current rule is like this and checked in designer, i picked it up from the forum but as said the LUX value is not used for a weird reason as it is the beginning of the rule

import org.openhab.core.library.types.*
import org.openhab.model.script.actions.*
import org.openhab.model.script.actions.Timer
import org.openhab.core.persistence.*

var Timer Bureau_timer = null
var Integer Bureau_timeout = 3

rule “Bureau light motion”
when
Item Z_Bureau_Motion changed to OPEN
then
logInfo(“BureauLightOn”,“Motion detected and checking Lumiance in the room”)
if ((Z_Bureau_Lux.state as DecimalType) < 30){
logInfo(“BureauLightOn”," Current Luminance is" + Z_Bureau_Lux.state)
if (Bureau_timer != null)
{
Bureau_timer.reschedule(now.plusMinutes(Bureau_timeout))
logInfo(“BureauLightOn”,“Bureau timer rescheduled for " + Bureau_timeout + " minutes”)
}
else
{
sendCommand(Z_Bureau, ON)
logInfo(“BureauLightOn”,“Kitchen timer create with " + Bureau_timeout + " minutes”)
Bureau_timer = createTimer(now.plusMinutes(Bureau_timeout))
[|
if (Z_Bureau_Motion.state == OPEN)
{
Bureau_timer.reschedule(now.plusMinutes(Bureau_timeout))
logInfo(“BureauLightOn”,“Bureau timer triggered, but rescheduled again for " + Bureau_timeout + " minutes”)
}
else
{
sendCommand(Z_Bureau, OFF)
Bureau_timer = null
logInfo (“BureauLightOn”,“No Motion detected for 3 Minutes, Turning lights off”)
}
]
}
}
end

Hm, strange… It works in my environment. Can you try to put the line

logInfo("BureauLightOn"," Current Luminance is" + Z_Bureau_Lux.state)

before the if-clause? So you can check the value of Z_Bureau_Lux in the logs before the if-statement is evaluated. The only thing I can imagine is that the value “0” is not correctly assigned to the item by the z-wave binding.

as promised my rule that works !

import org.openhab.core.library.types.*
import org.openhab.core.persistence.*
import org.openhab.model.script.actions.*
import org.openhab.model.script.actions.Timer
import java.util.Date
import java.util.format

var Timer Bureau_timer = null
var Integer Bureau_timeout = 3

//Licht Bureau fibaro powerplug rules //

rule “BureauLightOn”

when
Item Z_Bureau_Motion changed to OPEN
then
if ((Z_Bureau_Lux.state as DecimalType) < 18){
logInfo(“BureauLightOn”,"Motion detected! Measuring Lux state below 19 lux or not,current Luminance is " + Z_Bureau_Lux.state)
if (Bureau_timer != null)
{
Bureau_timer.reschedule(now.plusMinutes(Bureau_timeout))
logInfo(“BureauLightOn”,“Bureau timer rescheduled for " + Bureau_timeout + " minutes”)
}
else
{
sendCommand(Z_Bureau, ON)
logInfo(“BureauLightOn”,“Turning lights On and Bureau timer set to " + Bureau_timeout + " minutes”)
Bureau_timer = createTimer(now.plusMinutes(Bureau_timeout))
[|
if (Z_Bureau_Motion.state == OPEN)
{
Bureau_timer.reschedule(now.plusMinutes(Bureau_timeout))
logInfo(“BureauLightOn”,“Motion has been detected and Bureau timer extended again for " + Bureau_timeout + " minutes”)
}
else
{
sendCommand(Z_Bureau,OFF)
logInfo (“BureauLightOn”,“No motion has been detected in the room within " + Bureau_timeout + " minutes”)
Bureau_timer = null
}
]
}
}
end