Auto Lights not Triggering

I have replaced my Coolcam PIRs with Fibaro as the Coocam motion sensor would disappear requiring constant re-initialization.

I have a problem with my living room script. With my Domoticz system the rule started with ‘if motion = ON then’ And the coolcam pir was set to keep the alarm for ten minutes with further motion resetting that time.

I’ve tried the same with the fibaro and notice that the state is always ‘alarm’ which is what I want as obviously I don’t want the lights turning on and off whilst watching tv.

The script is failing to turn the lights on with the sensor set to ten minute alarm as I think the state is always on and so not triggering the script.

Any ideas?

rule "lightsAutoLR_ON"
when
	Item Security_Motion_LR received update
then
	if(Security_Motion_LR.state != ON) return;
	if(Environment_Lux_LR.state > 9) return;	// Do nothing if Lux higher than 5
	if(Light_All_LR.state != 0) return;		// Do nothing if lights are already on

	Light_All_LR.sendCommand(100)
	Light_Hue_Iris_LR.sendCommand(100)
end


rule "lightsAutoLR_OFF"
when
	Item Security_Motion_LR changed to OFF
then
//	if (gSafetyAlarms.state == ON) return; // Do nothing if alarm active
	if (Light_All_LR.state == 0) return; // Do nothing if lights are off

	Light_All_LR.sendCommand(0)
	Light_Hue_Iris_LR.sendCommand(0)
end


rule	"lightsAutoLR_LuxOFF"
when 
	Item Environment_Lux_LR received update
then
//	if (gSafetyAlarms.state == ON) return;		// Do nothing if safety alarm active
	if(Light_All_LR.state == 0) return;		// Do nothing if lights already off
	if(Environment_Lux_LR.state < 12) return;	// Do nothing if Lux lower than 13

	Light_All_LR.sendCommand(0)
	Light_Hue_Iris_LR.sendCommand(0)
end
Item Security_Motion_LR changed to OFF

Have you tried:

Item Security_Motion_LR changed from ON to OFF

Fibaro FGMS will sent motion events as alarms, so you need to link the item to the proper alarm channel first.
See if that event appears in events.log before you start looking at your rules.
For when to turn the alarm back off (which obviously is a prerequisite to turning it on again), check out the Fibaro’s parameter #6, also check #2 #3 #4 to tweak conditions under which it’s to turn on the alarm.

Hi Thanks for the reply

The script turns the lights off just fine. If I set the Fibaro config to alarm for 30s which is the default the lights will come on and of. The problem is that in a normal living room situation there is not enough movement to keep the lights on with a 30 second timeout

Here is what I use with a motion sensor rule.

var Timer occupancyTimer = null
val int timeoutMinutes = 45 // choose an appropriate value

rule "Pi_Hole_Sensor received ON"
when
    Item Pi_Hole_Sensor received update ON
then
    Smart_Plug.sendCommand(ON)
        if(occupancyTimer === null) {
            occupancyTimer = createTimer(now.plusMinutes(timeoutMinutes ), [|
                Pi_Hole_Sensor.sendCommand(OFF)
                occupancyTimer = null
            ])
        }
    else {
        occupancyTimer.reschedule(now.plusMinutes(timeoutMinutes ))
    }
end

rule "Turn Smart Plug Off"
when
    Item Pi_Hole_Sensor received update OFF 
then
    Smart_Plug.sendCommand(OFF)
end

With this I can set the timer to switch off the light after 45 minuets with no movement. Maybe you can try something similar and set the timer to suit your needs.

So it’s doing what you told it to, and if you were to set the Fibaro’s #6 to 600 (10 minutes), it would wait that long before turning off the lights. So where’s your problem ? Maybe better explain that again…

I think but I’m not sure the problem is the rule uses two conditions to turn the lights on - Lux and Movement.

With the extended 10 minute on time it is always seeing movement within that time frame and so the alarm is always active. It when it sees the first movement the Lux is high enough that the lights don’t come on. Then as the LUx drops because the movement is constantly being detected when the Lux is low enough to need the lights the rule doesn’t see the movement trigger because it is constantly active.

The rule is only executed whenever the motion sensor state gets an update (I’m assuming that Security_Motion_LR you trigger upon is the motion alarm item), so that should not be affected by lux updates.
You can use “changed” or “changed to ON” instead of “received update”.
Check events.log for what’s happening when. Insert logDebug() to show when the rule is executed and use it to output what the item states were at that time. Or in short: debug your rule.

received update
changed
received command
3 different things. check the events.log as stated to see how it is logged, then base your rule off of that

Ok I’ve played with the rule and the lights now trigger however I can’t get them to stay on.
As this is in the living room motion can be infrequent. I tried introducing a timer as suggested above but this is not working for me.

Here is the log file;

2018-08-20 23:58:19.495 [vent.ItemStateChangedEvent] - Security_Motion_MLR changed from OFF to ON

2018-08-20 23:58:19.530 [ome.event.ItemCommandEvent] - Item 'Light_All_LR' received command 100

2018-08-20 23:58:19.571 [vent.ItemStateChangedEvent] - Light_All_LR changed from 0 to 100

2018-08-20 23:58:19.580 [ome.event.ItemCommandEvent] - Item 'Light_Hue_Iris_LR' received command 100

2018-08-20 23:58:19.585 [vent.ItemStateChangedEvent] - Light_Hue_Iris_LR changed from 1,100,0 to 1,100,100

2018-08-20 23:58:49.879 [vent.ItemStateChangedEvent] - Security_Motion_MLR changed from ON to OFF

2018-08-20 23:58:49.906 [ome.event.ItemCommandEvent] - Item 'Light_All_LR' received command 0

2018-08-20 23:58:49.921 [ome.event.ItemCommandEvent] - Item 'Light_Hue_Iris_LR' received command 0

2018-08-20 23:58:49.930 [vent.ItemStateChangedEvent] - Light_All_LR changed from 100 to 0

2018-08-20 23:58:49.942 [vent.ItemStateChangedEvent] - Light_Hue_Iris_LR changed from 1,100,100 to 1,100,0

And here is my rule;

var Timer occupancyTimer = null
val int timeoutMinutes = 10 // On time after movement

rule "lightsAutoLR_ON"
when
	Item Security_Motion_MLR changed to ON
then
//	if(Security_Motion_MLR.state != OFF) return;
	if(Environment_Lux_MLR.state > 12) return;	// Do nothing if Lux higher than 5
	if(Light_All_LR.state != 0) return;		// Do nothing if lights are already on

	Light_All_LR.sendCommand(100)
	Light_Hue_Iris_LR.sendCommand(100)
		if(occupancyTimer === null) {
			occupancyTimer = createTimer(now.plusMinutes(timeoutMinutes ), [|
				Security_Motion_MLR.sendCommand(OFF)
				occupancyTimer = null
		])
	}
	else {
		occupancyTimer.reschedule(now.plusMinutes(timeoutMinutes ))
	}
end


rule "lightsAutoLR_OFF"
when
	Item Security_Motion_MLR changed from ON to OFF 
then
//	if (gSafetyAlarms.state == ON) return; // Do nothing if alarm active
	if (Light_All_LR.state == 0) return; // Do nothing if lights are off


	Light_All_LR.sendCommand(0)
	Light_Hue_Iris_LR.sendCommand(0)
end


rule	"lightsAutoLR_LuxOFF"
when 
	Item Environment_Lux_MLR received update
then
//	if (gSafetyAlarms.state == ON) return;		// Do nothing if safety alarm active
	if(Light_All_LR.state == 0) return;		// Do nothing if lights already off
	if(Environment_Lux_MLR.state < 15) return;	// Do nothing if Lux lower than 13

	Light_All_LR.sendCommand(0)
	Light_Hue_Iris_LR.sendCommand(0)
end

Have a look at the expire binding (search the forum). Add it to the light item config. It’ll send OFF to that item after timer expiry, but every action such as light.sendCommand(ON) will restart the timer.

I had a look at expire but I must be doing something wrong.
For the item I have

Dimmer  Light_All_LR    "All Lights"    { channel="milight:rgbLed:ACCF233F8E3A:0:ledbrightness", expire="10m 30s,state=0" }

Then the rule;

rule "lightsAutoLR_ON"
when
	Item Security_Motion_MLR changed to ON
then
//	if(Security_Motion_MLR.state != OFF) return;
//	if(Environment_Lux_MLR.state > 12) return;	// Do nothing if Lux higher than 5
//	if(Light_All_LR.state != 0) return;		// Do nothing if lights are already on

	Light_All_LR.sendCommand(100)
	Light_Hue_Iris_LR.sendCommand(100)
	
end

rule	"lightsAutoLR_LuxOFF"
when 
	Item Environment_Lux_MLR received update
then
	if(Light_All_LR.state == 0) return;		// Do nothing if lights already off
	if(Environment_Lux_MLR.state < 22 ) return;	// Do nothing if Lux lower than 13

	Light_All_LR.sendCommand(0)
	Light_Hue_Iris_LR.sendCommand(0)
end

The log shows that the lights kept on receiving their 100 command until there was not motion for more than 10 mins and then the lights received the 0 command however although the log says Lights_All_LR changed from 100 to 0 they in fact stayed on and didn’t turn off.

events.log:2018-08-21 17:19:52.454 [ome.event.ItemCommandEvent] - Item 'Light_All_LR' received command 100
events.log:2018-08-21 17:21:01.219 [ome.event.ItemCommandEvent] - Item 'Light_All_LR' received command 100
events.log:2018-08-21 17:22:35.944 [ome.event.ItemCommandEvent] - Item 'Light_All_LR' received command 100
events.log:2018-08-21 17:23:35.675 [ome.event.ItemCommandEvent] - Item 'Light_All_LR' received command 100
events.log:2018-08-21 17:29:06.740 [ome.event.ItemCommandEvent] - Item 'Light_All_LR' received command 100
events.log:2018-08-21 17:39:37.411 [vent.ItemStateChangedEvent] - Light_All_LR changed from 100 to 0
events.log:2018-08-21 20:48:55.087 [ome.event.ItemCommandEvent] - Item 'Light_All_LR' received command 100
events.log:2018-08-21 20:48:55.116 [vent.ItemStateChangedEvent] - Light_All_LR changed from 0 to 100
events.log:2018-08-21 20:51:46.224 [ome.event.ItemCommandEvent] - Item 'Light_All_LR' received command 100
events.log:2018-08-21 20:55:33.472 [ome.event.ItemCommandEvent] - Item 'Light_All_LR' received command 100
events.log:2018-08-21 20:59:33.505 [ome.event.ItemCommandEvent] - Item 'Light_All_LR' received command 100
events.log:2018-08-21 21:00:58.355 [ome.event.ItemCommandEvent] - Item 'Light_All_LR' received command 100
events.log:2018-08-21 21:01:31.072 [ome.event.ItemCommandEvent] - Item 'Light_All_LR' received command 100
Dimmer  Light_All_LR    "All Lights"    { channel="milight:rgbLed:ACCF233F8E3A:0:ledbrightness", expire="10m30s,command=0" }

You used state=0 which will update the state but not action the binding and therefore not turn off the lights.
You need to use command=0 to send the value to the binding.

Many thanks that seems to have sorted it.