Trigger a specific hour of the day

hi guys,i need to write a rule for a night light .I want to light a lamp when my motion sensors triggered but only after 00:00 till 07:00.I cant find something so i can run this rule only between these hours…Any ideas?

There are other ways to do this, but this should work for you. Depending on your use case, you may not want the light to turn off at 7.

rule "Motion enabled between 0-7"
    Item MotionItem changed
    val Integer currentHour = now.getHourOfDay
    logDebug("Rules", "test: currentHour={}",currentHour)
    if ((0..7).contains(currentHour)) {
        logDebug("Rules", "test: time is valid")
        if (MotionItem.state == ON) {
            // turn on light
        else if (MotionItem.state == OFF) {
            // turn off light
    else {
        logDebug("Rules", "test: time is not valid")
        // if light is on, turn it off

Nice use of the set ( (0…7) ) operator. I always forget it there.