Automations based on next scheduled alarm (on Android device)

This has probably been done many times, but here is another one.

I wanted to play music and turn on lights right before my alarm went off, and I wanted to use an alarm clock on my device (Android).

So I created an app (https://github.com/Johboh/hassalarm) that will listen for the broadcast intent ACTION_NEXT_ALARM_CLOCK_CHANGED, which is sent once the next scheduled alarm is changed. This is sent by the system when any (decent) alarm clock schedule its next alarm. Once the app receives the intent, it will eventually call the API and post an updated value for a sensor called next_alarm. This can later be used in automations, for example:

  trigger:
  - minutes: /1
    platform: time
    seconds: 0
  condition:
  - condition: template
    value_template: '{{ (((as_timestamp(now()) | int) + 3*60) | timestamp_custom("%Y-%m-%d %H:%M:00")) == states.sensor.next_alarm.state }}'
  action:
  - data:
      entity_id: scene.wakeup
    service: scene.turn_on
5 Likes

Now available on Google play: https://play.google.com/store/apps/details?id=com.fjun.hassalarm

Thank you, I like the idea (though I believe it should also be doable with tasker?).

I installed your app (using an access token) on my Note 9. But it doesn’t seem to work? I can not see the sensor. But after clicking “save” it shows the correct Next Alarm in the App.

A “test connection” button with an error message would be a good idea.

Yeah, the app is quite naive when it comes to error handling and assumptions. I will add a “test connection” functionality and expose errors a bit better.

Thanks. Any idea on why it is not working? Where can I look?

No not really, it could be anything. But I will add that test connection feature today so you can diagnose.

I pushed the test connection feature now, both to github and also Google Play Store. Should be available shortly.

I am getting:

“Unexpected char 0x0a at 14 in Authorization value: Bearer Daniel:
[real token]”

So I made an error making a copy of my auth token (over Telegram). Maybe don’t display it with “*” symbols when entering? (and don’t show it at all later…)

It works now :slight_smile:

This project is just plain awesome! This is exactly what I was looking for! Thank you for such a great app!

Ever considered of sharing the knowledge?)) There is an open-source android client for HA in development (also on github) which could really benefit from such functionality.

2 Likes

Sounds like a good Idea :blush:. I will look into it.

1 Like

I like this project, thanks.

For people running into problems, set the correct timezone in your Home Assistant configuration so the value_template in the condition evaluates correctly.

Hello,

I know its a old thread, but now Ariela (Ariela - Home Assistant Android Client) supports sending next alarm info to Home Assistant. You can create automation based on that.

Hey, can you tell me where i can find the sensor?
I checked the docs but i dont see this sensor on my device, just bluetooth, battery, light and so on.

Please check if you have the latest version of Ariela(1.3.0.2)

Thanks, it was an outdated version.
But is it possible to send an event if the alarm is triggered?
I’m not a big fan of automations that need to run every minute. I think its a bit needless and stressfull for the server. Maybe not with one automation but sometimes there are more of these kind of automations

For the moment is not possible to send that event from Ariela, but i will investigate maybe i can add something like this

I’m not sure if the automation example is going to work as the docs say

Rendering templates with time ( now() ) is dangerous as updates only trigger templates in sensors based on entity state changes.

Which i understand now() will only be rendered once the alarm is set, and therefore the automation should never trigger

I suppose you make a automation that can parse the state of the next alarm sensor to be triggered at that exact time?

Has anyone managed to get this working with Ariela / MQTT? I am struggling with the automation setting, I already got MQTT sensor working and its state attribute is in the format “yyyy-mm-dd hh:mm:ss”. How do I integrate this information into an automation to turn on a light at this specific time?

Thanks in advance!

Hello,

You can find an example here: http://ariela.surodev.com/2019/03/03/mqtt-next-device-alarm/
Please let me know if you made it work.