Calculate middle of two DateTimeTypes

Dear all,

I got a problem using millis and conversions to DateTimeTypes - could anyone please help me? I have tried many differnet ways and have absolutely no glue how to solve it. I tried to post the for me most meaningful approach below.

  • Platform information:
    • Hardware: Raspberry Pi 3 Model B Rev 1.2
    • OS: Raspbian GNU/Linux 8 (jessie)
    • Java Runtime Environment: openjdk version “1.8.0_152”
    • openHAB version: OH2.1.0-1
  • Issue of the topic:
    I tried to calculate the middle between start of civil dask/dawn and end of civil dask/dawn - the goal is to use this time as trigger for opening/closing the rollershutters.
    To calculate this time, I converted the DateTimeTypes to millis:
civil_dask_start.state as DateTimeType).calendar.timeInMillis + (civil_dask_end.state as DateTimeType).calendar.timeInMillis

This works fine when I log it as a message.
But posting this to an DateTimeItem dows not work - but I would like to display it and use it in a couple of rules to open and shut the rollershutters.

civil_dawn.postUpdate(DateTimeType.valueOf(((civil_dawn_start.state as DateTimeType).calendar.timeInMillis + (civil_dawn_end.state as DateTimeType).calendar.timeInMillis) / 2))
civil_dask.postUpdate(DateTimeType.valueOf(((civil_dask_start.state as DateTimeType).calendar.timeInMillis + (civil_dask_end.state as DateTimeType).calendar.timeInMillis) / 2))

My Items are defined as follows:

DateTime civil_dawn_start "Beginn Morgendämmerung [%1$tH:%1$tM]" <start_daylight> {channel="astro:sun:local:civilDawn#start" }
DateTime civil_dawn_end "Sonnenaufgang [%1$tH:%1$tM]" <start_daylight> {channel="astro:sun:local:civilDawn#end" }
DateTime civil_dask_start "Beginn Abenddämmerung [%1$tH:%1$tM]" <end_daylight> {channel="astro:sun:local:civilDusk#start" }
DateTime civil_dask_end "Sonnenuntergang [%1$tH:%1$tM]" <end_daylight> {channel="astro:sun:local:civilDusk#end" }
DateTime civil_dawn "Sonnenaufgang [%1$tH:%1$tM]" <end_daylight>
DateTime civil_dask "Sonnenuntergang [%1$tH:%1$tM]" <end_daylight>

The rule above shows up the following log message:

2018-02-13 18:51:12.040 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Error during the execution of startup rule 'SonnenaufgangSonnenuntergang': Could not invoke method: org.eclipse.smarthome.core.library.types.DateTimeType.valueOf(java.lang.String) on instance: null

Has anyone any idea how to calculate the middle between the both datetimes to store the outcome in the DateTime Item?

Many thanks and kind regards,