Hi, can you please help me fixing the following rule?
I finally upgraded from 2.x to 4.0 and am nearly done updating my rules. My alarm clock rule I can’t get to work again. The goal is to send to alarm clock time from my Android phone and trigger a rule at the given time.
I’m trying the following two options:
1) Updating my old rule:
The following rule I used for years now without a flaw.
Item:
Number AlarmClock_user1
Rule:
var Timer timerAlarm = null
rule "Alarm Clock"
when
Item AlarmClock_user1 changed
then
if (AlarmClock_user1.state == UNDEF || AlarmClock_user1.state == NULL) {
if (timerAlarm !== null) {
timerAlarm.cancel
timerAlarm = null
}
logInfo("alarm", "All alarms are cancelled")
} else {
alarm_clock_time = new DateTime((AlarmClock_user1.state as Number).longValue)
logInfo("alarm", "Scheduling alarm clock for " + alarm_clock_time.toString)
if (timerAlarm !== null) {
logInfo("alarm", "Rescheduling alarm clock.")
timerAlarm.reschedule(alarm_clock_time)
} else {
logInfo("alarm", "New alarm clock is set.")
timerAlarm = createTimer(alarm_clock_time,
[ alarm_clock_timer_id |
logInfo("alarm", "Trigger timerAlarm!")
// do something
]
)
}
}
end
Unfortunately sending the the update to the item AlarmClock_user1 in the app leads to:
2023-07-27 13:35:31.907 [INFO ] [openhab.event.ItemCommandEvent ] - Item 'AlarmClock_user1' received command 1690520100000
2023-07-27 13:35:31.907 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'AlarmClock_user1' changed from UNDEF to 1690520100000
2023-07-27 13:35:31.908 [ERROR] [internal.handler.ScriptActionHandler] - Script execution of rule with UID 'alarm_clock-1' failed: An error occurred during the script execution: Cannot invoke "org.eclipse.xtext.common.types.JvmType.eIsProxy()" because "type" is null in alarm_clock
What is the “new” syntax for creating a timer or needed time format?
2) Using the example from the docs:
Items:
DateTime AlarmClock_Default "Alarm Clock [%s]" <time>
Rule:
rule "Alarm Clock Default"
when
Time is AlarmClock_Default
then
logInfo("alarm", "Triggered default alarm clock rule.")
end
The problem is that the rule does not trigger to the correct time - I think due a timezone problem. Updating the items shows:
2023-07-27 13:44:23.421 [INFO ] [openhab.event.ItemCommandEvent ] - Item 'AlarmClock_Default' received command 2023-07-28T05:00:00.000+0000
2023-07-27 13:44:23.421 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'AlarmClock_Default' changed from UNDEF to 2023-07-28T05:00:00.000+0000
The alarm should trigger at local time 07:00, not 05:00. I think therefore, at 07:00 nothing happens.
The OH instance runs in a docker container with environment variable:
EXTRA_JAVA_OPTS: "-Duser.timezone=Europe/Berlin"
The timestamp the log shows are correct. The GUI settings do show Europe/Berlin as set timezone.
How do I achieve that the alarm triggers at the correct local time?
Thanks for the help!