Rule that executes only after a given time

I’d like to create a rule that executes only after 10 PM, I created a Time based one like:

when
     	Time cron "0 0 22 ? * MON,TUE,WED,THU,SUN *"

But I fear that this will exec only at 10 PM, correct?
How can I do this?

That’s right. What is it that you want to happen instead? Have a rule triggered by some event, that checks to see if ‘now’ is after 10PM (and, you will need to decide, is also before XXPM/AM)?

now.getHourofDay is likely to prove useful

To elaborate, Rules are triggered by events, not state. You are looking for state when you care about between 10 PM and morning(?).

So as @rossko57 suggests, you would add an if statement in your rule to see what time it is and then only execute if it between the times you care about.

If you have more than one place where you care about time based states, I recommend:

Let me explain the scenario:
I have a hue light in my daughter’s bedroom and already have it set via Hue that at 9:30 starts dimming the light until 9:45 when it’s completely off. Now I’d like to create a rule that if the kid turns on the light after 10 PM, it will shut it off after 15 minutes.
I hope that explains :slight_smile:

Assuming Time of day

var Timer timer = null

rule "Turn off hue?"
when
    Item HueLight changed
then
    if(TimeOfDay.state == "NIGHT" && timer == null){
        timer = createTimer(now.plusMinutes(15), [| 
            HueLight.sendCommand(OFF)
            timer = null
        ])
    }
end

Without Time of Day

rule "Turn off hue?"
when
    Item HueLight changed
then
    if((now.isAfter(now.withTimeAtStartOfDay.plusHours(22)) || 
        now.isBefore(now.withTimeAtStartOfDay.plusHours(6))) && timer == null){
        timer = createTimer(now.plusMinutes(15), [| 
            HueLight.sendCommand(OFF)
            timer = null
        ])
    }
end

The above assumes there is no need to ever extend or cancel the OFF timer. If there is a Timer and the Hue’s state changes the event is ignored. If there isn’t a Timer, a Timer is created to send OFF to the light after 15 minutes and reset timer to null.

HueLight changed is the event.

The if statement is the "checks to see if ‘now’ is after 10PM.

I just put it on, I will test it.

Thanks!