How to implement 2-step motion sensor controlled lighting

I’ve installed motion sensors im my rooms to automatically turn on lights to 100%. After 90s of no-motion I’d like to switch the lights to 50%. Another 30s later I want to switch off the lights. This way easy to achieve.

Now the harder part: when I re-enable the lights via Alexa or just use the switch item for the resp. light, it switches on to 50%, not 100%. I’ve (more or less) solved this by settings lights to 100% immediately before turning them off, followed by 500ms delay, then turning them really off. But this is no good solution for me since the lights flash shortly.

Can you help me finding a better solution for this problem?

Best regards,
cd_

How did you achieve this? Perhaps a different way makes more sense. My first thouight was using timers and rules.

Yes, I did it via timers and rules. I’ve a rule which turns on lights to 100% if motion is detected. It also activates an expire binding item (90s). If this expire item triggers, another rule switches to 50%. This activates another expire item which switches off the lights.

Only if you share details of your system and configuration. The volunteers here do not play mystery guessing games.

How to ask a good question / Help Us Help You - Tutorials & Examples - openHAB Community

Here’s a destilled config:

Dimmer Ilight "Light" <light> (GlightsAvg) {channel="hue:wxyz:0123456789ab:1:color"}
Group:Dimmer:AVG GlightsAvg "Lights [%d]" <light>
Switch   MotionTimer1 {expire="90s,command=OFF"}
Switch   MotionTimer2 {expire="30s,command=OFF"}


val Functions$Function6<SwitchItem, SwitchItem, GenericItem, SwitchItem, Integer, SwitchItem, Boolean> motionDetectedSwitch= [ 
    
    motionSensorSwitchItem, featureEnabledSwitch, lightToControl, fullBrightnessTimer, fullBrightness, reducedBrightnessTimer |

    if (featureEnabledSwitch.state == ON) {
        lightToControl.sendCommand(fullBrightness)
        fullBrightnessTimer.sendCommand(ON)
        reducedBrightnessTimer.postUpdate(OFF)
    }

    true
]

val Functions$Function4<SwitchItem, GenericItem, SwitchItem, Integer, Boolean> motionDetectedNoMoreReduce= [ 
    
    motionSensorSwitchItem, lightToControl, reducedBrightnessTimer, reducedBrightness |

    lightToControl.sendCommand(reducedBrightness)
    reducedBrightnessTimer.sendCommand(ON)

    true
]

val Functions$Function2<SwitchItem, GenericItem, Boolean> motionDetectedNoMoreOff= [ 
    
    motionSensorSwitchItem, lightToControl |

    lightToControl.sendCommand(100)
    Thread.sleep(500)
    lightToControl.sendCommand(0)

    true
]

rule "Switch light on if motion is detected"
when
    Item IsensorsMotion_Motion received update ON
then
    motionDetectedSwitch.apply(triggeringItem as SwitchItem, true, GlightsAvg, MotionTimer1, 100, MotionTimer2)
end

rule "Lower light if no more motion was detected"
when
    Item MotionTimer1 received command OFF
then
    motionDetectedNoMoreReduce.apply(IsensorsMotion_Motion, GlightsAvg, MotionTimer2, 50)
end

rule "Switch off light if no more motion was detected after additional time in low light"
when
    Item MotionTimer2 received command OFF
then
    motionDetectedNoMoreOff.apply(IsensorsMotion_Motion, GlightsSfLrTableAvg)
end

I see no linked Switch Items.

I added the linked light.

Is there a particular reason you use Functions for this? I would recommend using Design Pattern: Associated Items to simplify your rules. Besides, when looking at your first function and when you call it, the arguments doesn’t match? (argument no. 2 is a boolean but should be a SwitchItem)

As for the problem itself it has been discussed before, but I don’t know if anyone have solved it in a good way. Different dimmable lights (and different bindings) handle ON/OFF commands differently. Some restore the light to the last value when turned on while some interprets ON as 100 and OFF as 0. Search the forum for a solution you could be satisfied with.

I use functions for this since I’ve serveral lights to control in this way – this allows me to re-use the logic. Anyway, I’ll have a look at the Design Pattern you mentioned, thanks!

Regarding the Boolean value: my mistake performing the destillation of the code, in my real scenario this is a switch controlling the enabling of the logic.