[SOLVED] Multiple 'when' statements, (AND/OR)

With the trigger “System started” this rule will only run when openHAB is starting and when the .rule file’s timestamp is updated (e.g. file edited or touched). This why your statement the it occurs frequently and NOT just at startup is confusing. Are you editing the files at these times or are you or something else touching the files so the timestamp gets updated?

I do notice that you are getting the DateTime of Sunrise_Time but Twilight_Event. Shouldn’t that be Twilight_Time? Twilight_Event is a Switch, not a DateTime type. I don’t think Twilight_Time was part of my original example above so you may need to add it.

I quickly looked back and I didn’t see that I’ve made this suggestion yet. If I missed it, sorry for the duplicate.

Have you set up persistence and are you using restoreOnStartup for your Sunrise and Twilight times? That should populate them with the last known values at startup and avoid the UnDef error.

Maybe add a Thread::sleep(msec) where msec is long enough for the Astro binding to load and recalculate the Sunrise and Twilight times.