- Platform information:
- Hardware: RPI4
- OS: latest openhabian
- Java Runtime Environment: default
- openHAB version: latest openhabian
Hello,
I’m trying to display the date and alarm of my android phone on openhab. I managed to get the epoch time to an item in openhab via the android app. I allso managed to display the date and time in the logs using loginfo. My problem starts when i want to move the datetime to a DateTime item using the rule. I searched the forum but cant find any example.
.items
Number AlarmClockJimmy {expire="2s, state=OFF"} //epoch
DateTime AlarmClockJimmyDateTime
.rule
var Timer timerAlarm = null
rule "Alarm Clock"
when
Item AlarmClockJimmy changed
then
logInfo("Android alarm", "rule started")
if (AlarmClockJimmy.state as Number == 0) {
if (timerAlarm !== null) {
timerAlarm.cancel
timerAlarm = null
}
logInfo("Android alarm", "All alarms are cancelled")
} else {
var epoch = new DateTime((AlarmClockJimmy.state as Number).longValue)
val DateTime datetime = new DateTime(epoch)
val String time = datetime.toLocalTime().toString("HH:mm")
val String date = datetime.toLocalDate().toString("dd-MM-yyyy")
logInfo("Android alarm", "Jimmy's alarm instellen voor " + time.toString + " op " + date.toString)
AlarmClockJimmyDateTime.sendCommand(datetime , new DateTimeType() )
if (timerAlarm !== null) {
logInfo("Android alarm", "Reschedule alarm")
timerAlarm.reschedule(epoch)
} else {
logInfo("Android alarm", "New Alarm")
timerAlarm = createTimer(epoch,
[ k |
// Turn on stuff, e.g. radio or light
//Light.sendCommand(ON)
logInfo("Android alarm", "alarm is expired")
]
)
}
}
end
.sitemap
Text item=AlarmClockJimmyDateTime label="Alarmijd [%1$tl:%1$tM %tp]"
Text item=AlarmClockJimmyDateTime label="Alarmdatum [%tA %1$te %1$tB %1$tY]"
Any advice is welcome