Jsr233 - Jython - Write current Time to DateTimeItem

Hi,

how can i write the current time to a DateTime Item with jython? I tried a few things, but i can’t get i work.

Item:
DateTime FensterHauswirtschaftsraumZuletztOffen

Code:
be.postUpdate(“FensterHauswirtschaftsraumZuletztOffen”,new DateTimeItem())
be.postUpdate(“FensterHauswirtschaftsraumZuletztOffen”,DateTime.now())

Thanks and Greetings
Dennis

Here is a bit of code that works for me posting to a DateTime item:

var DateTime nighttime=now.withTimeAtStartOfDay.plusHours(23)
postUpdate(Night_Time, new DateTimeType(nighttime.toCalendar(null)))

Hi,

thanks, but this is not jython. I need a code snippet, how to do in jython.

Greetings
Dennis

I think the essence of my suggestion is the DateTimeType en …toCalendar bit, which creates the correct format date time output for postUpdate.

It is actually way easier since you can use all openhab datatypes:

BusEvent.postUpdate( "Timestamp", str(DateTimeType()) )

(Maybe even the str() is not required but I forgot to try it. :blush:)

Hi,

many thanks! Oh man, now i see my mistake. I used DateTimeItem instead of DateTimeType :frowning:

No it works! The str() is required.

Thanks and Greetings
Dennis