How to update am Item of DateTime type?

Using the latest stable OH3, perhaps a simple question:
I have created a DateTime item called MasterBedroom_Door_LastUpdate_Virtual
How do I set or update this from a rule or script?

Initially I would like to display on a mainUI page so I can know the door is still sending updates.
Later I would like to trigger/update an item if last update is > 1 day

I have spent hours on this, any help would be appreciated.

I created a DSL language script:

MasterBedroom_Door_LastUpdate_Virtual.postUpdate(now)

but get the error:
ReferenceError: “now” is not defined in at line number 1

In addition to also tried ECMAScript and Blocky script. Not clear how to get the current date time into a DateTime Item.

I looked at this page: DateTime Conversion (openHAB 3.x)
But I am not clear how this helps me.

I also looked at this, but it is not clear how this could help me: OH3 Setting current DateTime to a custom item in a rule - #2 by muelli1967

I would have thought it would be simple to record when something happened and display it. Am I missing something really obvious?

That’s simple enough that it should work.
Suggests there’s something amiss about the way you are entering this rule. Are you using GUI editing, or putting it in a text file? Copying old file-based rules into GUI system can go wrong, different triggering structure.

1 Like

I have been sticking to the GUI.
I recently updated to the latest stable, I wonder if there is an issue with my install.

Found a workable solution, you can also peak behind to see the code.

Decided to start over from basics and follow this:
https://www.openhab.org/docs/tutorial/rules_advanced.html

Was going to Administration → Settings → Add-Ons-> Automation to install this:
https://www.openhab.org/addons/automation/jsscripting/

However discovered a DateTime Block library

Which allowed me to do this:
image

1 Like