Home Assistant Community

Automations based on next scheduled alarm (on Android device)

#1

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
2 Likes

#2

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

0 Likes

#3

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.

0 Likes

#4

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.

0 Likes

#5

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

0 Likes

#6

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

0 Likes

#7

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

0 Likes

#8

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:

0 Likes

#9

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.

1 Like

#10

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

0 Likes

#11

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.

0 Likes

#12

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.

0 Likes

#13

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.

0 Likes

#14

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

0 Likes

#15

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

0 Likes

#16

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

0 Likes

#17

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

0 Likes

#18

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

0 Likes