OH3 Setting current DateTime to a custom item in a rule

I would like to set the current time as an item state, when a specific rule is executed, therefore I created following rule, by paying attention to example #3 of DateTime Conversion (openHAB 3.x) for the datetime conversion:

  - id: "1"
      itemName: Haupteingang_OpenClose
      state: ""
    type: core.ItemStateChangeTrigger
conditions: []
  - inputs: {}
    id: "2"
      itemName: CarportExpectedMovement
      state: =new DateTimeType(new LocalDateTime())
    type: core.ItemStateUpdateAction

So when Haupteingang_OpenClose has any change I want to have the current time in the custom created DateTime item CarportExpectedMovement.
Unfortunately, this just leads to following error message:

2021-04-29 18:08:00.865 [WARN ] [handler.ItemStateUpdateActionHandler] - State '=new DateTimeType(new LocalDateTime())' is not valid for item 'CarportExpectedMovement'.

i have not tested it but reading example #3 could this be the reference to be used?

That’s not valid for a UI only rule. You need to create a Script Action and then you can use the line of code from the DateTime Conversion thread in the Script.

Expressions like that (values that start with =) are only a thing for MainUI Widgets. They don’t work in Rules.

Assuming Rules DSL as the language chosen for the Script Action a better solution would be:


An even better solution, assuming Haupteingang_OpenClose is linked to a Channel, is to link that same channel to CarportExpectedMovement and use the timestamp profile. Any change on the Channel will update CarportExpectedMovement with the current date and time. No rule required.

Thank you.