Could not invoke postUpdate on instance null

Hi,
I have an issue with a simple rule recording the last change of an item: My Iitems definition:

Contact Sensor_Fenster_EG_1 "Fenster EG-1 [%s]" 	<contact> 	(gFenster, gEG, gPersistence) { channel="homematic:HM-Sec-SCo:CCU2:NEQ0405734:1#STATE" }
DateTime Sensor_Fenster_EG_1_LetzteAenderung

My rule implementation starts as following:

rule "Fenster Wohnzimmer"
when 
    Item Sensor_Fenster_EG_1 changed
then
    var DateTime letzteAenderung = now as DateTime
    Sensor_Fenster_EG_1_LetzteAenderung.postUpdate(letzteAenderung)
end 

And the error message during execution is

Rule 'Fenster Wohnzimmer': An error occurred during the script execution: Could not invoke method: org.eclipse.smarthome.model.script.actions.BusEvent.postUpdate(org.eclipse.smarthome.core.items.Item,org.eclipse.smarthome.core.types.State) on instance: null

Does anyone have an idea why this rule fails?

Thanks an best regards,
Marc

Because a Joda DateTime is not acceptable as an update to a DateTimeItem. Luckily there is an easy fix:

Sensor_Fenster_EG_1_LetzteAenderung.postUpdate(letzteAenderung.toString)
2 Likes

It works with this really easy fix… Thanks a lot!
Best regards,
Marc

Oh dang. That’s why most of the time my switch flipped back right away. It worked sometimes though.

Solution: I had to add .toLocalDateTime

EndsAt.postUpdate(endtime.toLocalDateTime.toString)

Problem: I can’t get this to work in OH3, please help…

Item:

DateTime EndsAt

Rule:

var Number minutes = (Remaining.state as Number).floatValue * 60
val endtime = now.plusMinutes(minutes.intValue)
logInfo("Rule","##Ends at: " + endtime.toString) //OK til here
EndsAt.postUpdate(endtime.toString)

Gives error:

Cannot convert '2021-08-12T07:27:02.011824Z[Etc/UTC]' to a state type which item 'EndsAt' accepts: [DateTimeType, UnDefType].

Please don’t reopen a 3+ year old post. If you need help please open a new thread. OH 3 didn’t even exist when the last post to this thread was made and date times work differently in OH 3, for which there are lots of threads already.