Date diff - js scripting

i am trying to store current date in an DateTime item and then check the date and do some calculations (plus/minus minutes).


console.log(items.getItem(“RadiatorAC1_WindowOpenedDate”).state)- NULL :frowning:


Not sure why it’s not working? what am i missing?

Sending a command or posting an update to an Item happens asynchronously. This means if you are trying to log the state of the Item immediately after commanding it, it almost certainly will not be the new state.

What do you see in events.log? Do you see any errors in openhab.log?

I’m not sure where you found that syntax. You should be seeing an error in the logs saying something like Item has no method getTime(number) or something like that.

items.getItem('name') returns an Item, not a Date, DateTime or anything like that. See that link for what an Item does have.

You also misstyped isBefore.

If you want to see if the state of an Item is at least 15 minutes in the past.


i want to save a current date into a DateTime item, and then read it and use it in a rule.

1/ Saving current datetime:


Creation of event failed, because one of the registered event factories has thrown an exception: Error getting class for simple name: ‘$ProxType’ using package name ‘org.openhab.core.library.types.’.
java.lang.IllegalArgumentException: Error getting class for simple name: ‘$ProxType’ using package name ‘org.openhab.core.library.types.’.
at ~[?:?]
at ~[?:?]
at ~[?:?]
at ~[?:?]
at ~[?:?]
at ~[?:?]
at ~[?:?]
at ~[?:?]
at$0( ~[?:?]
at [?:?]
Caused by: java.lang.ClassNotFoundException: org.openhab.core.library.types.$ProxType cannot be found by org.openhab.core_3.4.0.M4
at org.eclipse.osgi.internal.loader.BundleLoader.generateException( ~[org.eclipse.osgi-3.17.200.jar:?]
at org.eclipse.osgi.internal.loader.BundleLoader.findClass0( ~[org.eclipse.osgi-3.17.200.jar:?]
at org.eclipse.osgi.internal.loader.BundleLoader.findClass( ~[org.eclipse.osgi-3.17.200.jar:?]
at org.eclipse.osgi.internal.loader.ModuleClassLoader.loadClass( ~[org.eclipse.osgi-3.17.200.jar:?]
at java.lang.ClassLoader.loadClass( ~[?:?]
at java.lang.Class.forName0(Native Method) ~[?:?]
at java.lang.Class.forName( ~[?:?]
at ~[?:?]
… 9 more

it seems even the first part is not working ;(
in case of postUpdate:


Script execution of rule with UID '4eed5fcc93' failed: java.lang.UnsupportedOperationException: Unsupported operation identifier 'toFullString' and  object '[object Object]'(l

First, consider whether the timestamp profile would be a viable alternative here.

Secondly, you will notice in the docs that sendCommand and postUpdate on Item takes a String and only a String.

Next, there’s a “bug” with internationalization right now that makes parsing a Joda ZonedDateTime not work properly so using a LocalDateTime and calling toString on that is recommended.

The call to getItem() also requires a String, the name of the Item. You must put the String in quotes.

There is a shorthand built into the library that will convert just about anything to a ZonedDateTime: time.toZDT(). It’s much shorter to type and read than

Finally, it doesn’t make much sense to send a command to a DateTime Item. It’s not causing something to happen. It doesn’t need to cause a binding to cause a device to do something. postUpdate is more appropraite.


The TARDIS binding is not yet available to carry out time-travelling command instructions.