Rule for turning lights on not working - Help

Hi,
I have tried to create a rule that turns my living room lights on when movement is detected but only if the Lux is less the 7.

Another rule is supposed to turn them off again if no movement is detected or if the Lux increases but only if there is no smoke alarm.
Both are failing. Can anyone help.

The devices are;
Security_Motion_LR = Switch
Light_All_LR = Dimmer for all 4 MiLight zones
Environment_Lux_LR = Number
gSafetyAlarms = Switch

This is my poor attempt;

rule "lightsAutoLR_ON"
when
	Item Security_Motion_LR changed to ON
then
	if(Environment_Lux_LR.state <=6 && Light_All_LR.state = 0) {
		sendCommand(Light_All_LR, 100)
	}
end


rule "lightsAutoLR_OFF"
when
	Item Security_Motion_LR changed from ON to OFF or
	Item Environment_Lux_LR changed
then
	if (gSafetyAlarms == OFF && Light_All_LR > 0 && Environment_Lux_LR > 8) {
		sendCommand(Light_All_LR,0)
	}
end

Maybe to start with, it may help if you posted your item and group definitions too; your log file; and maybe even before all of that, add some log statements so that you can see if you rule gets even triggered; it would good to know whether the rule trigger failed or the send_Command; and while you are at it, you may want to log also your lux_state to make sure that you see what sensor values you are getting back.

If I’m not correct,

sendCommand(Light_All_LR, 100)

Is where your problem lies. I believe …there is an issue with this only accepting type numerical. I may be incorrect though.

First rule the if statement has only one equal sign, change to two. ==

Thanks Matt. Putting the double equal kicked the rule into life as it wasn’t being triggered.
I changed the first test to <==6 and the second to ==0 The first rule now errors with;

2018-08-03 19:14:20.348 [WARN ] [el.core.internal.ModelRepositoryImpl] - Configuration model 'auto_lights_LR.rules' has errors, therefore ignoring it: [5,30]: missing ')' at '<'

[5,31]: no viable alternative at input '=='

[5,63]: mismatched input ')' expecting 'end'

2018-08-03 19:14:21.578 [WARN ] [el.core.internal.ModelRepositoryImpl] - Configuration model 'auto_lights_LR.rules' has errors, therefore ignoring it: [5,30]: missing ')' at '<'

[5,31]: no viable alternative at input '=='

[5,63]: mismatched input ')' expecting 'end'
if(Environment_Lux_LR.state <=6 && Light_All_LR.state = 0) {
		sendCommand(Light_All_LR, 100)

Do you have the 0 in Light_All_LR.state == 0 mapped to OFF? If not try changing the o to OFF. Also good to change your send commands to this: Light_All_LR.sendCommand(ON)

I am not seeing anything in the log to say the motion sensor is triggering.

This is how I have them defined. I put [%s] on one and placed it on my sitemap and beside its name it just has a - sign;

// Motion Sensors
Switch  Security_Motion_LR      "Living Room PIR [%s]"  <motion>        { channel="zwave:device:657f1a0f:node2:sensor_binary" } // Living room motion sensor
Switch  Security_Motion_H       "Hallway PIR"           <motion>        { channel="zwave:device:657f1a0f:node6:sensor_binary" } // Hallway motion sensor
Switch  Security_Motion_L       "Landing PIR"           <motion>        { channel="zwave:device:657f1a0f:node8:sensor_binary" } // Landing motion sensor

Switches are ON, OFF or have to be transformed to whatever you need. Normally if I have an item that tells a value it is defined as a Number.

Please use Light_All_LR.sendCommand(100). Is the dimmer item defined as a number?

I sent that before seeing the Light_All_LR as a dimmer, sorry about that. In your code you listed two values for that item 0 and 100, so I assumed 0 to be OFF and 100 to be ON.
I’ve never used dimmers with openhab, how do you control them remotely?

You may want to start with Light_All_LR turning on/off with motion. Get that working then add in each deceive one at a time. That way you narrow down what’s breaking your rule.

To retrieve a state value try this construct:

dimmerStateScale = ((vOMR_readinglightBright.state as DecimalType).intValue * 2.55).intValue // scale to 0 -> 255

I have stripped the rule down to basic and proved that the Motion sensor is not activating.

That’s a dealbraker :slight_smile:
What kind of sensor is it?

https://www.openhab.org/addons/bindings/zwave1/
I looked over the zwave stuff and found lots of devices and they are all configured a bit different. Check your item configuration and look in your logs to see whats happing. Logs are your web ui with :9001 tacked on.

Its a Coolcam PIR. It has both Motion and Lux in the one device. Below is how they are listed in my items file.
The Lux works just fine. I stripped my rule back to if motion on the turn lights on. I added the sensor to my site map as a switch. It appeared with two buttons Activated and UnActivated. When I click the activated button the lights came on and the log showed its state had changed but it doesn’t do anything by itseld. Its LED lights on movement but Openhab sees nothing.

// Motion Sensors
Switch  Security_Motion_LR      "Living Room PIR [%s]"  <motion>        { channel="zwave:device:657f1a0f:node2:sensor_binary" } // Living room motion sensor
Switch  Security_Motion_H       "Hallway PIR"           <motion>        { channel="zwave:device:657f1a0f:node6:sensor_binary" } // Hallway motion sensor
Switch  Security_Motion_L       "Landing PIR"           <motion>        { channel="zwave:device:657f1a0f:node8:sensor_binary" } // Landing motion sensor

// LUX Sensors
Number  Environment_Lux_LR      "Living Room Lux [%s]"  <blinds>        { channel="zwave:device:657f1a0f:node2:sensor_luminance" }      // Living room LUX sensor
Number  Environment_Lux_H       "Hallway Lux [%s]"      <blinds>        { channel="zwave:device:657f1a0f:node6:sensor_luminance" }      // Hallway LUX sensor
Number  Environment_Lux_L       "Landing Lux [%s]"      <blinds>        { channel="zwave:device:657fla0f:node8:sensor_luminance" }      // Landing LUX sensor

Add :MAP(ONOFF.map) to the end of a switch and check that you have the map transformation installed via paperUi. It may complain about the channel being to long if so remove the sensor_binary and replace with MAP(ONOFF.map).

org.eclipse.smarthome.model.item.BindingConfigParseException: UID segment 'MAP(ONOFF.map)' contains invalid characters. The last segment of the channel UID must match the pattern [A-Za-z0-9_-#]*.

If this is somewhat similar to my Aeotec Multisensor 6, the motion trigger is timed in the device itself, and the timeout value is configurable through a z-wave parameter. (Both from PaperUI and Habmin).

In fact I only use this timer for all my motion rules. Minimum setting is 240s, so while it is in its triggered state, the LED will light up, but no new value is sent, but the device timer is of course restarted.

Yes its similar. It does have the timeout you talkabout. For the Living room I have it set to the maximum to avoid lights going off because I’m sitting to still. I have them set shorter in the hallway and landing.
These just don’t seem to be firing - they worked on my Domoticz setup so I know the hardware is fine.

I’ve posted a message about these sensors in the items section to see if anyone has used them.

Thanks all for your help

You could debug this a bit by making a rule that triggers on received update and log the .state.
Could be that it is something else than ON or OFF.

There is also: tail -F -n500 /var/log/openhab2/events.log
Could be something interesting there.