Crontime not work

Hello to all.
I created a rule for my blinds to work depending on the light intensity and it works great, except for the time - it works all the time, although in crontime I prescribed it to work from 8 to 22, but at the same time it is executed every 15 minutes. I have tried various crontime options, but in the end the time interval is not respected.

rule "Jalyzi_Lux"
when  
	 Time cron "* 0/15 8-22 ? * *"
then
    {
     if (ESP_Easy_Lux.state >= 800) 
	 gShutter.sendCommand(100)
	}
    {
     if (ESP_Easy_Lux.state <= 800)
     if (ESP_Easy_Lux.state >= 500)	 
	 gShutter.sendCommand(75)
	}
    {
     if (ESP_Easy_Lux.state <= 499)
     if (ESP_Easy_Lux.state >= 200)	 
	 gShutter.sendCommand(50)
	}
    {
     if (ESP_Easy_Lux.state <= 199)
     if (ESP_Easy_Lux.state >= 0)	 
	 gShutter.sendCommand(0)
	}
end

It’s not clear what you are asking. Is the problem that the rule triggers every 15 minutes 24 hours a day, or the fact that it’s triggering every 15 minutes at all?

The given cron expression should execute every 15 minutes between the hours of 08:00 and 22:00.

Some other things I notice is that the code itself almost certainly doesn’t do what you expect. While it’s syntactically correct it is very odd in the way it’s written. The { should go after the if statement, not before.

if (ESP_Easy_Lux.state >= 800){
    gShutter.sendCommand(100)
}
if (ESP_Easy_Lux.state <= 800){
    if (ESP_Easy_Lux.state >= 500){
        gShutter.sendCommand(75)
    } 
}
if (ESP_Easy_Lux.state <= 499){
    if (ESP_Easy_Lux.state >= 200){
        gShutter.sendCommand(75)
    } 
}
if (ESP_Easy_Lux.state <= 199){
    if (ESP_Easy_Lux.state >= 0){
        gShutter.sendCommand(75)
    } 
}

And this code could be made much more concise:

var shutterState = 0
if (ESP_Easy_Lux.state >= 800) {
    shutterState = 100
}
else if(ESP_Easy_Lux.state >= 500) {
    shutterState = 75
}
else if(ESP_Easy_Lux.state >= 200){
    shutterState = 50
}
// the default value of shutterState handles the case of 0-199

gShutter.sendCommand(shutterState)
1 Like

Thank you for your help.
The problem is that it works 24 hours a day. I tried various options, read many topics and even saw the exact same code somewhere and it worked there.
For the primitiveness of the code, I apologize) this is my first rule and I did it for two days. But it does work as it should, even with the errors you listed.

I just noticed another interesting point - the command is issued a full minute once a second, that is, once every 15 minutes, not one command is issued to execute the rule, but as many as 60 (!) сommands.

Using an online Quartz cron generator (recommended in the docs), I get the following for your use case:

0 0/15 8-22 ? * * *

Does that work?

Thanks for your reply.
This was my very first krone, but unfortunately it also works 24 hours. I am using https://www.freeformatter.com/cron-expression-generator-quartz.html#

And you’re sure you’re not running the routine in another rule somewhere?

If it was me, I’d take out the hyphen, and try the following:

0 0/15 8,9,10,11,12,13,14,15,16,17,18,19,20,21,22 ? * * *

Oh yeah, I do have one more rule:

 rule "Zakritiye jalyzi vecherom"
when  
     Time cron "0 1 22 * * ?"
then
     gShutter.sendCommand(DOWN)
end

     rule "Otkritiye jalyzi utrom"
when  
     Time cron "0 1 8 * * ?"
then
     gShutter.sendCommand(UP)
end

But I think it cannot affect this rule in any way, since it is performed only twice a day.

Looks interesting, I’ll test it tomorrow and let you know the results. Thank.

I think your problem is that you need 8-21 if you want its last execution at 21:45.

If I let me show the next execution events for 8-22 it says:

Fri Sep 25 22:45:00 UTC 2020
Sat Sep 26 08:00:00 UTC 2020

Btw. it executes every second because of the * at first position, you need a 0 there for once every 15 minutes :wink:

If you don’t want to wait until tomorrow evening, just test it against the next full hour.

That’s what I thought, so I suggested

and the OP responded that they’d tried it and it also ran every minute


:man_shrugging:

Nah he stated that it ran 24 hours (probably he only checked 1-2 executions after 10pm which is caused by 8-22 instead of 8-21)

The fact it runs every 15 minutes 60 times is another thing which he should fix :wink:

Hello. I apologize for not answering for so long.
Indeed, for the code to work as I want, it was necessary to set the time one hour less)

when
Time cron “0 0/15 8-19 ? * * *”
then

Everything turned out to be very simple, maybe it will help someone. Thank you all for your help.