DSL Rule Error: The method or field ChronoUnit is undefined

OH 3.1 on Raspberry Pi4

I’m trying to make some item to sum the power consuption of the day. I use influxdb 1.7 as persistent storage. My power consumption is measured every 10 second using an modbus serial transcriver.
I could see correctly the graph in OH3 of that item " ModbusDataWatt_ValueasNumber"

This is my script:

triggers:
  - id: "2"
    configuration:
      cronExpression: 0 0/10 * * * ? *
    type: timer.GenericCronTrigger
conditions: []
actions:
  - inputs: {}
    id: "1"
    configuration:
      type: application/vnd.openhab.dsl.rule
      script: >
        var Number tempValue1

        tempValue1 = ModbusDataWatt_ValueasNumber.sumSince(now.truncatedTo(ChronoUnit.DAYS))

        logInfo("TEST", tempValue1.toString())

        Consumi_Totali_Watt_24h.postUpdate(tempValue1)
    type: script.ScriptAction

If i try to get executed it get:

2021-10-17 17:53:50.758 [ERROR] [internal.handler.ScriptActionHandler] - Script execution of rule with UID '8a3c1de5bf' failed: var Number tempValue1
tempValue1 = ModbusDataWatt_ValueasNumber.sumSince(now.truncatedTo(ChronoUnit.DAYS))
logInfo("TEST", tempValue1.toString())
//Consumi_Totali_Watt_24h.postUpdate(tempValue1)
   The method or field ChronoUnit is undefined; line 2, column 89, length 10

Any hint?? Looking online i had understood that (now.truncatedTo(ChronoUnit.DAYS)) should be used to get the old StartOfTheDay method. Or not?

You’d want to import it in a file-based rule where you saw the example, but that is not possible in a GUI entered rule.
That’s okay, just give the full name
java.time.temporal.ChronoUnit.whatevermethodyouwant()

Thank you! So the error was i was uing the web ui editor and i have to call the entire class by his path.
Or use a rule file,
thanks!

No, I think you’d have the same error in .rules files if there isn’t an import. CronoUnit is not included by default. It has to be imported or used with it’s fully qualified name as @rossko57 demonstrated. Sometimes in Rules DSL examples that are not written with the UI in mind, people will leave the imports out for brevity or because they just simply forgot.

However, in the UI using Rules DSL, you cannot import it so you have to use the fully qualified name.