Dennis650
(Dennis650)
1
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
pensionado
(Gerard Dirkse)
2
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)))
Dennis650
(Dennis650)
3
Hi,
thanks, but this is not jython. I need a code snippet, how to do in jython.
Greetings
Dennis
pensionado
(Gerard Dirkse)
4
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.
)
Dennis650
(Dennis650)
6
Hi,
many thanks! Oh man, now i see my mistake. I used DateTimeItem instead of DateTimeType 
No it works! The str() is required.
Thanks and Greetings
Dennis