Set Android alarm clock from Home Assistant

I was wondering if it’s possible to set the alarm time in SleepAsAndroid via Home Assistant Companion App intents?

I used to set this via Pushover message that Tasker would get and it would set the alarm. It worked perfect, but I would no longer like to use Tasker as that’s all I was using it for, and hated that it was running all of the time. I also want to simplify this as much as possible (take Pushover out of the mix).

I just recently discovered that the Home Assistant Companion App can use intents. I now have SleepAsAndroid start the sleep tracking, but can only see the ability to turn alarms with labels on and off. Is there a way to set the actual time?

I have my alarm time set off a number of different conditions, and it can change each day.

1 Like

you should be able to create alarms using this intent Common Intents  |  Android Developers

That’s what I thought. I’m pretty new to intents, and have pretty limited experience with this.

I found that page before, and tried just about every combination I could think of to no avail. Also, I don’t know where to find any logs to check to see if I’m even close.

I found a bunch of different references to com.google.android.deskclock, when referring to the Next Alarm sensor. Also when reading this I’m not sure if I should be sending AlarmClock.ACTION_SET_ALARM?

This is what I have that starts the SleepAsAndroid tracking.

service: notify.mobile_app_pixel_5
data:
  message: command_broadcast_intent
  title: com.urbandroid.sleep.alarmclock.START_SLEEP_TRACK
  data:
    channel: com.urbandroid.sleep

I know I would need to specify the hours and minutes. I believe that would be set using group option under channel, but I’m lost as to what to put under the title, and the channel to interact with the base android alarm clock.

The first time I did it through Tasker, I believe it asked me if I wanted to set the alarm using the google app, or the SleepAsAndroid app.

Thanks for the reply!

no you need to use the full string, so you click on the link and grab its constant value at the bottom which is
android.intent.action.SET_ALARM

Yes one for each extra so hours would be:
android.intent.extra.alarm.HOUR

make sure to refer to the extras guide in the companion docs above

you need to use the package name, navigate in a browser to the play store listing for the app and the package name is in the URL.

Thanks for the tip on how to find the app name!

I think I’m still doing something wrong. I am sending this, with nothing. The message is received by the phone (I can see it in the Notification History).

service: notify.mobile_app_pixel_5
data:
  title: "android.intent.action.SET_ALARM"
  message: command_broadcast_intent
  data:
    channel: "com.google.android.deskclock"
    group: "android.intent.extra.alarm.HOUR:8,android.intent.extra.alarm.MINUTES:30"

try switching to command_activity keep everything else the same

Nope. Just comes through as a regular notification.

oh my bad, you have to move title to be a tag, so rename the field to tag and same spacing as channel and group

service: notify.mobile_app_pixel_5
data:
  message: command_activity
  data:
    intent_package_name: "com.google.android.deskclock"
    intent_extras: "android.intent.extra.alarm.HOUR:8,android.intent.extra.alarm.MINUTES:30"
    intent_action: "android.intent.action.SET_ALARM"

6 Likes

Amazing! That worked.

Thanks so much. This opens up a number of possibilities!

1 Like

Could you help me remove the old alarms. I have a node red flow that sets my alarm from my google calendar work schedule. I would like to be able to remove the old alarm and set a new one if my schedule changes.

Thank you so much for your post dshokouhi you (and this link) have got me this far. Do you think you might be able to help me get the rest of the way?

I can set the alarm with…

service: notify.mobile_app_oneplus_8t
data:
  message: command_activity
  data:
    channel: "com.google.android.deskclock"
    tag: "android.intent.action.SET_ALARM"
    group: "android.intent.extra.alarm.HOUR:8,android.intent.extra.alarm.MINUTES:30,android.intent.extra.alarm.MESSAGE:Home Assistant Alarm,android.intent.extra.alarm.SKIP_UI:true,"

Now I would like to remove or delete the alarm. I managed to work out how to use the “Dismiss Alarm” intent

data:
  message: command_activity
  data:
    channel: com.google.android.deskclock
    tag: android.intent.action.DISMISS_ALARM
    group: "android.intent.extra.alarm.SEARCH_MODE:android.label,android.intent.extra.alarm.MESSAGE:Home Assistant Alarm"

But this just disables the alarm not remove it. So leaves a trail of disabled alarms

Do you know how you can delete the alarm? not just cancel it?

unless you see an intent to remove an alarm it won’t be possible using this command

I think I have read about how to delete alarms but perhaps that was just dismissing.

Can’t you set the alarm later? If you wait until just before you want the alarm to actually trigger and set it at that point?

i know with sleep as android you can enable and disable them, but no option to completely remove them.

Do you know we’re i can find this?
I would like to be able to enable/disable alarms in sleep as android from home assistant

Alarm state change is what you are after, just apply a label ot the alarm so its easy to toggle it

I was able to add a new alarm as per the code in you previous post. But I am not able to enable/disable an alarm in Sleep as Android.

I have tested this code (and some other alternatives) but it isnt working
I get message: Not able to send activityintent. Please check format of command. Or something like that, I get the message in swedish

service: notify.mobile_app_andreas_one_plus_8t
data: 
  message: command_activity
  data:
    channel: "com.urbandroid.sleep"
    group: "com.urbandroid.sleep.extra.alarm_label:test, com.urbandroid.extra.sleep.alarm_enabled:false"
    tag: "com.urbandroid.sleep.alarmclock.ALARM_STATE_CHANGE"

Make sure the labels match exactly what you see on the documentation, don’t add extra text before them.

alarm_label and alarm_enabled is copy/pasted, 100% sure it is correct. I have tried both with and without .extra.

remove this entire bit and only have alarm_label:label,alarm_enabled:true notice how there is no space after the comma as well?

You can also refer to the 3rd example: Notification Commands | Home Assistant Companion Docs

1 Like

Thank you for uber-quick help!

My code is now

service: notify.mobile_app_andreas_one_plus_8t
data: 
  message: "command_broadcast_intent"
  title: "com.urbandroid.sleep.alarmclock.ALARM_STATE_CHANGE"
  data:
    channel: "com.urbandroid.sleep"
    group: "alarm_label:test,alarm_enabled:false"
1 Like