- 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?