Help with Living room lights

Can someone please help me with the automation of my living room lights.

I have a Fibaro motion sensor that I with to use to turn my lights on depending on movement and Lux.

I originally had the alarm duration set low and used ‘expire’ on the definition of my lights. This sort of worked but there were times when the lights would go out and would not come back on for a few minutes.

I have now tried setting the motion alarm duration to 30 minutes and this seemed to work if the lux level is low before the first movement. However it seems that when the lux level is high it sees movement but because the Lux is high it doesn’t turn the lights on but because of movement the alarm stays on and so never triggers (because it is already on) when the Lux gets low.

Could someone please look over my script and suggest a better way to do it?

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

	
end


rule "lightsAutoLR_OFF"
when
	Item Security_Motion_MLR changed to OFF 
then
	if (gLights_LR.state == OFF ) return;	// Do nothing if Lights are off

	gLights_LR.sendCommand(OFF)
end

I added a rule to check the lux value and turn the lights on. You may need to adjust the lux value to suit your needs.

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

	
end

rule "lights on when alarm is on and lux falls below 25"
when
	Item Environment_Lux_MLR changed
then
	if(Security_Motion_MLR.state == ON && Environment_Lux_MLR.state < 25){  // Set lux value as needed
		gLights_LR.sendCommand(ON)
	}
end

rule "lightsAutoLR_OFF"
when
	Item Security_Motion_MLR changed to OFF 
then
	if (gLights_LR.state == OFF ) return;	// Do nothing if Lights are off

	gLights_LR.sendCommand(OFF)
end

Many thanks for taking the time to help.

I’ve added your rule and will see tonight how it gets on.

You could also combine the events and conditions into less rules. This makes it less event-driven and more controller-like:

rule "lightsAutoLR"
when
	Item Security_Motion_MLR changed
    or Item Environment_Lux_MLR changed
then
  if(Security_Motion_MLR.state == ON && Environment_Lux_MLR.state <= 25){
	  gLights_LR.sendCommand(ON)
  }
  else
  {
	  gLights_LR.sendCommand(OFF)
  }
end

This will set your lights group on evey change of these states. If you feel like this generates too much traffic in your network, you can use conditions to check if it is really necessary to switch the lights:

    if (gLights_LR.state != ON) gLights_LR.sendCommand(ON)

My script with H102’s Lux rule addition fixed the problem of my Lights not comming on when it got dark enough but I was still getting the weird delay in them turning back on if they went off due to lack of movement.

So I tried SiLex’s more concise script and it seems to work better with the lights remaining on. However during the day it is constantly sending OFF commands.

I’ve made a slight adustment which has stopped the off commands but I’ll need to wait till tonight to see if the Logic still works. I know from my time with Domoticz that elseif’s weren’t true elseif’s;

rule "lightsAutoLR"
when
	Item Security_Motion_MLR changed
    or Item Environment_Lux_MLR changed
then
  if(Security_Motion_MLR.state == ON && Environment_Lux_MLR.state <= 21){
	  gLights_LR.sendCommand(ON)
  }
  else if (gLights_LR.state != OFF) {
  
	  gLights_LR.sendCommand(OFF)
  }
end

This may be caused if the lux value changes quickly when near the set point. How long was the delay and did it occur only when the lux was near the set point?

In the when part of the rule you have both, motion and lux when changed, that causes the rule to fire. Having one rule is good but sometimes using two works better for a particular situation. Either way, rules are flexible and testing to see what works best always a good idea.

No it wasn’t when the Lux was near the setpoint. I think it was to do with the trigger being motion changed to on only. If one of the other rules turned the light off it was having to wait for the alarm to go to off and then on again.