One Motion Detector two Lamps. Rules?

Hello,

I am a beginner with openHAB2 and am trying to switch two lamps with a motion detector
the lamps should be switched on at different times

lampe_1 from 8:00 a.m. to 10:00 a.m.
lampe_2 from 7:00 p.m. to 11:00 p.m.

Can you help me create the rule for it, my rules don’t work

My Rules:

rule “md_activate_lamp”

when
Item md changed to ON

then
if(Time cron “* * 8-10 ? * * *” ){

          sendCommand(lamp_1, ON)
           logInfo("aktivate.rules", "activate -> lampe_1")    
    }

    if(Time cron "* * 19-23 ? * * *" ){
      
          sendCommand(lamp_2, ON)
           logInfo("aktivate.rules", "activate -> lampe_2")    
    }

end

Thank you,

Don’t use a cron in this case, they are used as a trigger, and not for a if statement

Use something like this
When item changed to On

Then
if(hour <=20 && hour >=22)
Turn light on

And make a variable for Hour in the rule.
var Number hour = now.getHourOfDay

3 Likes

That worked very well, thank you! :slight_smile: