Cron Rule

Hi Guys.
i have picked up a issue with my cron Rule .it seems not to trigger.

My Rule :

rule "Morning Lights Weekdays"
when
   Time cron "0 0 5 ? * MON,TUE,WED,THU,FRI * "
then
 if ( Season.state == "Autumn" && Kitchen_Light_Stoep == "OFF" ) {
  Kitchen_Light_Stoep.sendCommand(ON) }
 
 if ( Season.state == "Winter" && Kitchen_Light_Stoep == "OFF"  ) {
  Kitchen_Light_Stoep.sendCommand(ON) }
 
 if ( Season.state == "Spring" && Kitchen_Light_Stoep == "OFF"  ) {
  Kitchen_Light_Stoep.sendCommand(ON) }
 
end

if i upload i get this in the log.

==> /var/log/openhab2/openhab.log <==

2020-05-28 08:18:16.431 [INFO ] [el.core.internal.ModelRepositoryImpl] - Validation issues found in configuration model 'Outlight.rules', using it anyway:

The use of wildcard imports is deprecated.

2020-05-28 08:18:16.432 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'Outlight.rules'

is it my cron ?

Your cron trigger looks fine, but



 do you have any imports? That warning wouldn’t prevent the rule from triggering though.

import org.joda.time.*
i added it to test as my rule does not trigger

org.joda.time is available without import, so remove the import and add a log entry at the beginning of the rule to be sure that the rule is actually triggering. I bet your rule was triggering, but you were not checking the state of Kitchen_Light_Stoep, so the conditions were never met. You were also comparing it to “OFF”, which is a string and SwitchItems will never have a state that is a string. What you were looking for was just OFF. You’re rule can also be cleaned up a bit.

rule "Morning Lights Weekdays"
when
   Time cron "0 0 5 ? * MON,TUE,WED,THU,FRI *"
then
    logInfo("Test", "Kitchen_Light_Stoep: {}, Season: {}", Kitchen_Light_Stoep.state, Season.state)
    if (Kitchen_Light_Stoep.state == OFF && (Season.state == "AUTUMN" || Season.state == "WINTER" || Season.state == "SPRING")) {
        Kitchen_Light_Stoep.sendCommand(ON)
    }
end
1 Like

So after the changes. it seems the rule gets triggerd but no actions.
in the log i get the test.

2020-05-29 05:00:00.017 [INFO ] [.eclipse.smarthome.model.script.Test] - Kitchen_Light_Stoep: OFF, Season: AUTUMN

But if i go in to the events log. i don’t get the lights coming on.
it seems like the trigger works and the logging. but no action from the lights. the evening rule works just fine.

I spotted some issues in the rule I posted. I’m surprised it would have even passed the validation check. It is now updated and hopefully works better for you! If you also add the ‘System started’ trigger, you can test it now.

Thank you. going in to a meeting now. will test it later today.

learned some new things with this. like the logging. :face_with_monocle:

1 Like
1 Like

If there is no match, then no command will be issued by the rule.
That is not a match.

2 Likes

Good catch, Ross! I’ve updated my post with capitalized season names.

Thanks .
see it now.

Thank you @5iver it is fully functional now.
today i am setting sum logging up.

1 Like