Rule needs to run twice to show correct result

Hi,
I have a rule, that runs at 00:05 everyday which updates some counters (days to left in the year, days until christmas, days until the next holiday is up etc).
Weirdly this shows the correct answer (in the LOG) when I run the rule (manually) a second time.
My Rule:

strNextBankHolidayID.sendCommand(Ephemeris.getNextBankHoliday())
var String HOLIDAY_LIST = "/etc/openhab/services/Holidays_de.xml"
/* NEXT HOLIDAY */
if (Ephemeris.isBankHoliday() == true)
{
	strUpcomingBankHoliday.sendCommand("Today is "+Ephemeris.getHolidayDescription(getNextBankHoliday,HOLIDAY_LIST).toString)
	logInfo("holidays.rules",strUpcomingBankHoliday.state.toString.toUpperCase)	
}
else
{
	strUpcomingBankHoliday.sendCommand(Ephemeris.getDaysUntil(getNextBankHoliday,HOLIDAY_LIST).toString+" Day(s) until "+Ephemeris.getHolidayDescription(getNextBankHoliday,HOLIDAY_LIST).toString)
	logInfo("holidays.rules",strUpcomingBankHoliday.state.toString.toUpperCase)
}

/* CHRISTMAS */
if (Ephemeris.getDaysUntil("FIRST_CHRISTMAS_DAY") != 0)
{
	//postUpdate
	strDaysUntilChristmas.sendCommand(Ephemeris.getDaysUntil("FIRST_CHRISTMAS_DAY").toString +" Day(s) until Christmas")
	logInfo("holidays.rules",strDaysUntilChristmas.state.toString.toUpperCase)
}
else
{
	//postUpdate
	strDaysUntilChristmas.sendCommand("Today is "+Ephemeris.getHolidayDescription("FIRST_CHRISTMAS_DAY").toString)
	logInfo("holidays.rules",strDaysUntilChristmas.state.toString.toUpperCase)
}

/* NEW YEAR */
if (Ephemeris.getDaysUntil("NEW_YEAR") != 0 && Ephemeris.getDaysUntil("NEW_YEARS_EVE") == 0)
{
	//postUpdate(
	strDaysOfYearLeft.sendCommand((Ephemeris.getDaysUntil("NEW_YEARS_EVE",HOLIDAY_LIST)).toString +" Day(s) left in "+ now.getYear().toString)
	logInfo("holiday.rules",strDaysOfYearLeft.state.toString.toUpperCase)
}
else
{
	//postUpdate(strDaysOfYearLeft,("First Day Of "+ now.getYear().toString))
	//postUpdate
	strDaysOfYearLeft.sendCommand((Ephemeris.getDaysUntil("NEW_YEARS_EVE",HOLIDAY_LIST)).toString +" Day(s) left in "+ now.getYear().toString)
	logInfo("holidays.rules",strDaysOfYearLeft.state.toString.toUpperCase)
}

When triggered at 00:05, it results in:

2024-05-09 00:05:00.947 [INFO ] [hab.core.model.script.holidays.rules] - 1 DAY(S) UNTIL ASCENSION DAY
2024-05-09 00:05:00.949 [INFO ] [hab.core.model.script.holidays.rules] - 231 DAY(S) UNTIL CHRISTMAS
2024-05-09 00:05:00.950 [INFO ] [hab.core.model.script.holidays.rules] - 237 DAY(S) LEFT IN 2024

When I run the rule manually it shows the correct results:

2024-05-09 08:07:18.656 [INFO ] [hab.core.model.script.holidays.rules] - TODAY IS ASCENSION DAY
2024-05-09 08:07:18.658 [INFO ] [hab.core.model.script.holidays.rules] - 230 DAY(S) UNTIL CHRISTMAS
2024-05-09 08:07:18.659 [INFO ] [hab.core.model.script.holidays.rules] - 236 DAY(S) LEFT IN 2024

Any idea why this is ?
Thanks

Maybe an issue with daylight saving?

  1. You should update Items, not command them if they represent a state and are not causing something to happen. You are not commanding Christmas to be 230 days from today, you are recording that fact. So you should use postUpdate.

  2. Both commands and update happen in the background and in parallel. If Item Foo is ON and you command it to OFF and then immediately pull Foo’s state, it is highly unlikely that Foo has actually changes to OFF yet. It’s still processing the command or update.

  3. A command involves more processing so 2 is going to be even more true for commands than it will be for updates. And in fact, there is no guarantee that an Item will actually change state at all in response to a command (see autoupdate).

Given all three of these, you cannot use the state of strUpcomingBankHolidy et al in the log statement immediately after commanding them. You know what you commanded them to, so just use that in your logs. Save it to a variable.

If you want to see confirmation that the Item changed state, see events.log.

Thanks for the help,
I updated my rule from

sendCommand

to

postUpdate

and it hat no effect, but it really is weird.
While the entries in the log-file are still incorrect, the items are updated correctly.
While this is the entry in the log-file:

2024-05-11 02:00:00.386 [INFO ] [hab.core.model.script.holidays.rules] - 10 DAY(S) UNTIL WHIT MONDAY
2024-05-11 02:00:00.387 [INFO ] [hab.core.model.script.holidays.rules] - 229 DAY(S) UNTIL CHRISTMAS
2024-05-11 02:00:00.389 [INFO ] [hab.core.model.script.holidays.rules] - 235 DAY(S) LEFT IN 2024

This what the GUI shows


So the rule works correctly it is just the log-entry that is really triggering my OCD.
Any thoughts ?

It’s what @rlkoshak says: when you read the state of the Item right after you do the postUpdate I hasn’t had time to actually receive the new state yet, it takes some tens of milliseconds for that to happen, but the rule runs faster.