[SOLVED] DateTime functions cannot be invoked

  • Platform information:
    • Hardware: Raspberry B Rev 2
    • OS: OpenHABian
    • Java Runtime Environment: openjdk 1.8
    • openHAB version: 2.4

What I want to achieve in the end is to set a timer depending on the sunset time as well as how overcast it is (100% overcast is 30 min earlier timer).

Rules that use DateTime cannot use the joda functions:

import org.joda.datetime.DateTime
import org.openhab.model.script.actions.Timer

var Timer sunsetTimer = null

rule "Sunset test"
when
    Time cron "0,30 * * * * ?"
then
    var DateTime sunsetMoment = Sunset_Time.state
    var Number clouds = Clouds.state
    var Number timeAdvance = 0.3 * clouds

    logInfo("test.rules", "Setting timer " + timeAdvance.intValue+ " minutes earlier on " + sunsetMoment)

    var DateTime advancedMoment = sunsetMoment.minusMinutes(timeAdvance.intValue)
    logInfo("test.rules", "Setting it to " + advancedMoment)
end

result in the logs:

2019-01-03 21:36:00.280 [INFO ] [se.smarthome.model.script.test.rules] - Setting timer 22 minutes earlier on 2019-01-03T16:39:00.000+0100
2019-01-03 21:36:00.327 [ERROR] [ntime.internal.engine.ExecuteRuleJob] - Error during the execution of rule 'Sunset test': An error occurred during the script execution: Could not invoke method: org.joda.time.DateTime.minusMinutes(int) on instance: 2019-01-03T16:39:00.000+0100

How can you invoke the joda functions like minusMinutes() correctly?

openHAB DateTime Items are not joda
This is helpful

Reading your proposed article @rossko57 it should work as described. By default DateTime in rules is joda date time. The functions I try to use are the joda functions.

Or am I interpreting something complete wrong?

myDateTimeItem.state is not a joda datetime. So the article describes how to convert between them, e.g. for comparisons

Ok, now I think I understand.

It seems to work indeed!

Thanks a lot @rossko57