Android alarm and openHAB2

I’ve got a prob with the app updating the value in OH2 much to often.

2018-03-28 20:40:23.529 [vent.ItemStateChangedEvent] - wakeup changed from 1522296000 to 0
2018-03-28 20:40:27.134 [vent.ItemStateChangedEvent] - wakeup changed from 0 to 1522263031
2018-03-28 20:40:35.624 [vent.ItemStateChangedEvent] - wakeup changed from 1522263031 to 0
2018-03-28 20:40:40.572 [vent.ItemStateChangedEvent] - wakeup changed from 0 to 1522263045
2018-03-28 20:40:44.481 [vent.ItemStateChangedEvent] - wakeup changed from 1522263045 to 0
2018-03-28 20:41:15.810 [vent.ItemStateChangedEvent] - wakeup changed from 0 to 1522263080
2018-03-28 20:41:19.146 [vent.ItemStateChangedEvent] - wakeup changed from 1522263080 to 0
2018-03-28 20:41:22.574 [vent.ItemStateChangedEvent] - wakeup changed from 0 to 1522263086
2018-03-28 20:41:23.985 [vent.ItemStateChangedEvent] - wakeup changed from 1522263086 to 0

Everytime I am touching my phone, the app sends the “new” alarm value to OH. As you can see, the time differs but I didnt change my alarm at all. So the app doesn’t recognize, that the actuall alarm hasn’t changed and there’s no need to send a new value.

Strange … I guess there is another app using the alarm feature to schedule things it has to do … I’m already working on the next version and try to improve the behavior. Right now I would assume, that you don’t have any alarm scheduled … as 0 is only send if there is no alarm and if an app scheduled alarm time is reached or revoked, it should fall back to the android alarm clock alarm and not 0.
I can only read the next alarm value, as the android API is designed that way. If there is another app constantly scheduling things, the android alarm clock alarm might never be visible, until its over :confused: … We’ll see…

Do you have any app installed, doing some background work or something like that?

I’m looking into it

Thanks for your fast reply. Just found out what this issue causes. You were quite right with another app causing that behavior. The problem is tasker. Although I am not using the alarm clock in my tasker tasks, if I’m switching tasker off everything is fine.

Great news :smiley: … I can find out which app scheduled the next alarm. I think about showing which apps scheduled an alarm and allow the user to exclude certain apps while allowing different android alarm apps. Might take a moment to implement :wink:

1 Like

I implemented that feature. Unfortunately, I don’t get tasker to schedule any alarms for me. But I seems to work. The beta version is life in google play and released on github.com. I will publish it as soon as google approves my latest changes.

Hi Eberhard,

Your APP is awesome.
But it seems not to work with my AlarmClock APP (AlarmDroid).

I have there multiple alarms configured, each (or most of them) for more then one day.
But the current behavior is, that after the current alarm is triggered, the Item change to 0.

2018-12-05 06:00:03.869 [vent.ItemStateChangedEvent] - AndroidAlarm changed from 1543986000 to 0

Only if i open your APP, the item will get the next alarm, but after this one triggered i have the same problem again…

I have a Galaxy S7 running on Android 8.0.0

I would be great if you can help me.

Hi Eric,

since I also use AlarmDroid, I exclude that. I’m too running Android 8.0.0 (although on a Sony device). I know that the current alarm is not always sent to the server, but right now I’ve got no real clue why.
I guess that the app gets unloaded by the os and therefore receives no alarm anymore (Although this should actually not happen, because the app should be started on any alarm change) or is unloaded while trying to sent the next alarm to the server (which is more likely)

There are multiple things that are happening in the app. When the alarm is scheduled, the app is called and reads the next alarm from the AlarmManager. If the app, that scheduled the alarm, is allowed to do so, the rest call is made. Now things get tricky as this might fail due to numerous reasons. If that happens, the request ist scheduled to run again after 30s (but android can decide to delay that, as long as it wants :/). WLAN has to be on, assuming that openhab is running in a home network.
If the rest call is answered with anything but 200 HTTP OK by the openhab server, this alarm will be disregarded.

Is there any error message displayed in the app?
Is there any app disallowing “Home Automation Alarm Sender” to run?
Is WLAN on?

Hi Eberhard,

Thanks for the reply.
You are right, my OH is running in a home network, but WIFI was enabled all the time.
I see no App which is disallowing HAAS to run, also i don’t see any error in the APP (when i’m in the wifi).

I tested it yesterday also with an other APP, which should detect the alarm and send the info via MQTT to Openhab.
But this app also failed…

I only get the new AlarmDate when i open your APP (also tested with other Alarm Clocks).

I think the problem is that i have a Samsung phone.
I will test it again in the evening with my old LG, maybe i’m lucky…

another idea: there might be something about power management. Maybe allowing background activity for HAAS or excluding its background activity from power saving is helping.

I opened a PR to add this functionality to the official app: https://github.com/openhab/openhab-android/pull/1137.
If someone wants to give it a try, here’s the apk: https://github.com/openhab/openhab-android/pull/1137#issuecomment-446747581

Through holidays i tested the app again.

I noticed that also some other apps (wifi badger) where not working probably…
The problem was that i had enabled the “power saving” mode… :sweat_smile:

After i disabled it, all apps which should work in the background where working again.
But i think this is a Samsung Bug, cause i added them to be allowed to run in the background.

Thx for the help :grinning:

You’re welcome

Hallo and Thanks for the great Work.

My Question is, can you post a sample rule to convert the Number item to DateTime.

Cant handle it.

Thanks MATZ

I don’t actually convert the timestamp back, but try something like that:

Date alarm = new Date((long)timeStamp*1000);

https://stackoverflow.com/questions/3371326/java-date-from-unix-timestamp

The latest beta version of the official client now supports sending the alarm clock time.

@EKa Thanks for this idea. Do you want to add a note to your app that the official app can now do the same?

Great news, I’m looking forward to checking it out. I’ll change the app store entry soon. As I’m having exams these days, it might take a bit longer :wink:

Hello,
does anyone have the error that is sent in the time to Openhab is an offset of about 5min (299 seconds)?
Now and then comes the right value.
And if I set an alarm in the next 5 minutes, the time will be sent for the next week.

The log file contains the following:

2019-05-05 20:44:56.881 [vent.ItemStateChangedEvent] - AndroidAlarm changed from 1557082621 to 1557082681

This UNIX number converted: 1557082681 corresponds to: Sunday, 2019-05-05 18:58:01 UTC
exactly 4:59min to early.

And then exactly 5min before the alarm, the app changes to the right UNIX time.

Why? What am I doing wrong?

2019-05-05 20:58:00.556 [vent.ItemStateChangedEvent] - AndroidAlarm changed from 1557082681 to 1557082980

You likely do not do anything wrong. My guess is that your alarm clock app does weird stuff. The OH app uses this API whose return value is what was previously set by the alarm clock app via this API … so I’m pretty sure what’s reported equals what your alarm clock app is doing.

You are not doing anything wrong. I guess it is the alarm app: Wake up is “difficult” for an app, and there is no guarantee your app is woken up by the AlarmManager on time. So you schedule an alarm 5 min before you want to wakeup. The device awakes from deep sleep and sets an alarm in 5 minutes. As it takes some time for the device to go into sleep again, the next alarm will most certainly be on time.

Hello,

I’m relative new to openhab, so sry when this is some kinde of a noob question.
But the non beta version of the openhab app now has also the option to send the alarm time to OH, but I can’t get it to work.
I constantly get an error message that the Item couldn’t be updatet (http error 400).
To me this sounds like a connection problem but the rest of the app works just fine no matter if I am in my local network or vie the remote adress.
I hope someone can help me.