One small point: A DateTime
item in openHAB is not at all the same thing as a DateTime
object from org.joda.time
. They unfortunately share the same name, but they aren’t actually related.
A DateTime
item in openHAB usually has a state of class DateTimeType
. When you have a DateTimeType
, you can reference its java.util.Calendar
member using .calendar
in a rule. Then you can access this calendar’s properties, such as .timeInMillis
. Then you can use that returned long
to create or modify org.joda.time.base.AbstractInstant
instances. For example:
import org.joda.time.*
import org.openhab.core.library.types.DateTimeType
rule MyRule
when
Item BinMenArrive changed
then
val DateTime binMenArrive = new DateTime((BinMenArrive.state as DateTimeType).calendar.currentTimeMills)
if (now.isBefore(binMenArrive)) {
logInfo("MyRule", "put the bins out!")
} else {
logWarn("MyRule", "too late; have to wait a week.")
}
end