Startup rule and cron, astro triggers

Still using OH4.1. I have a number of rules that trigger using cron and the astro plugin (for example, wake, bedtime, nighttime rule and dawn, daylight, dusk rules). On boot, the system doesn’t trigger, for example, the daylight rule isn’t triggered on boot because that event hasn’t been triggered by the astro plugin. Same with the cron rules. I’m creating a rule for startup using “when System reached start level 100 “. It looks like the only way to set the system to the current astro/cron timing events at startup is to add all of the variables in the startup script which seems kind of redundant. Here are some examples:

rule "Weekday Bedtime"
    when    
        Time cron "0 0 21 ? * MON,TUE,WED,THU,FRI *"
    then
        Bedtime_Switch.sendCommand(ON)
        LROutlet_Switch.sendCommand(OFF)
end

rule "Weekday Wakeup"
    when    
        Time cron "0 30 5 ? * MON,TUE,WED,THU,FRI *"
    then
        Bedtime_Switch.sendCommand(OFF)
        LROutlet_Switch.sendCommand(ON)
end

rule "Sunset Actions"
    
    when
        Channel 'astro:sun:local:civilDusk#event' triggered START
    then
        logWarn("rules", "Sunset Actions")
        Daylight_Switch.sendCommand(OFF)
        FrontDoorLight_Switch.sendCommand(ON)
end




Any suggestions on how to approach this, that is, on startup the system is set based rules that trigger on astro and cron events?

Rules are triggered by events. All of these rules are only triggered once a day. If OH isn’t running when the event occurs then the rule isn’t going to be triggered.

So when the system starts, you must calculate what state the Items should be in based on what day of the week and time it is (in this case) and making the actions as necessary. There is no going back. OH doesn’t know what events occurred while it was down and there is no way to go back.

So yes, you need your system started rule.

Though there are other approaches.

All of this is handled by Time Based State Machine [4.0.0.0;5.9.9.9] which can be used to command a string to an Item at certain times of day. Then instead of a hard coded cron trigger and astro trigger, you can trigger your rules using that String Item. The Time Based State Machine rule will handle restarts and missed events so that the string Item always reflects the current time of day state and on system start is will always send the current time of day to that string Item. So you’ll never miss an event.

Alternatively you can run the rule once a minute or every five minutes or what ever makes sense and based on the current time and day of the week send the commands to the Items. If you miss an event it won’t matter because the first time the rule runs it will figure out what needs to be done.