Wake-up light based on Android alarm clock

Before using HA I used a self-made system with limited functionality. But one of it’s functions which I used daily, was not available in HA: turn on a light when my Android alarm clock rings, as wake-up light.

So to be able to use this, I created a little Android app: https://play.google.com/store/apps/details?id=pixento.nl.broadcasttomqtt
It forwards android broadcast intents to a MQTT broker, and I use it to triggers a HA scene. The app is still in beta, so please report any misbehavior.

Automation example:

- trigger:
    - platform: mqtt
      topic: 'android/broadcast/device-id'
  condition:
    condition: and
    conditions:
    - condition: template
      value_template: '{{ trigger.payload_json.action == "com.samsung.sec.android.clockpackage.alarm.ALARM_ALERT" }}'
    - condition: state
      entity_id: group.all_devices
      state: home
  action:
    - entity_id: scene.awaken
      service: scene.turn_on
22 Likes

I do something similar with tasker and mqtt

@forsquirel Can you please show us how you set it up?

Thanks.

Do you know if a broadcast is emitted when the alarm is set, or when the “alarm will ring soon” notification appears, or anything else which would allow us to start something before the alarm actually starts ringing? (I would love having lights gradually turn on before my wake-up time… but this changes often, and I don’t want to set it in two different places…

Thanks for the application anyway, having a way to receive any broadcast via MQTT is really cool :slight_smile:

There probably is an intent sent when you set an alarm. You’d have to be listening on the MQTT server and try to set an alarm and see.

It really depends on the alarm clock application you’re using. There might be one that sends an intent as soon as you set it.

It seems that the intent android.app.action.NEXT_ALARM_CLOCK_CHANGE is broadcasted when I set an alarm in my Samsung alarm clock app, but due to a bug the Broadcast to MQTT app crashes. I will release an update in a few hours, and test it again.

1 Like

Any chance you can get it working on something below Android 5.0? :slight_smile:

As far as i know, the intent for Alarms is not common in Android. Some device manufacturers support it, some dont. Samsung does support it as far as i could try.

I have a similar implementation running for a year, however completely without HA involvement. It simply takes the time stamp and puts it into the hue hub directly. Im using an “automate” automation for it on Android.

However, im looking into changing the whole system to HA or at least combine it with HA.

I am looking to integrate my android phone eg. If I get a phone call, HA turns a light on.

The app is really good but it’s limited to alarm. It would be good if we could use it for more android functions. I know it’s possible with Tasker but I am not familiar with it.

First of all: update is published!

@kernald android.app.action.NEXT_ALARM_CLOCK_CHANGE is indeed broadcasted when setting an alarm. But the time is not put in the extra fields of the intent, but maybe you can find another broadcast intent that works for you and has this information.

@AbraKabastard I’ll see how much work that is, but probably it’s easy… Which version are you running?

@bachoo786 It’s not limited to alarms, but to broadcast intents. You could e.g. add the intent for an incoming call: android.intent.action.PHONE_STATE. The only problem is that the app needs special permissions for this particular action, and I have not implemented this.

1 Like

4.4.2! Using an old Samsung S3.

At the moment I do something similair (I set the alarmtime upon change on my Android) using the

android.app.action.NEXT_ALARM_CLOCK_CHANGED
Creating a alarm clock

But it fails to update my sensors from time to time somehow.
Will try this.

Where do I add the intent for an incoming call?

I am doing something similar and use an android alarm to automatically raise my blinds 10 minutes before the alarm goes off.
that basically works like this: there is a task in tasker that is triggered every day at 4:00 am. this task uses the AutoAlarm plugin to check how many minutes are left until the next alarm goes off. It then subtracts 10 from that number of minutes and delays for exactly that time. The delay finishes 10 minutes before the alarm is set to go off, the next task calls home-assistant rest api to raise the blinds :slight_smile:

1 Like

That’s a cool approach!

I wanted to achieve the same and went with the alarm app Sleep As Android. There I enabled a smart period of 5 minutes (which means the app wakes me up up to 5m early of the wished time).
Sleep as Android then sends an event 45m before the smart period starts which I catch with tasker, turn on WiFi and send it to HA where an automation will start fading in the lights some minutes later.

This works, but I have the feeling I like your solution more, maybe I will refactor it, thanks for sharing :slight_smile:

Edit:

the next task calls home-assistant rest api to raise the blinds

I prefer doing logic in HA, so I created switches like “alarm_ringing” or “alarm_starts_in_50m” etc which are turned on by tasker via the rest api. This way my tasker setup has as less logic as possible and most of the stuff is done by HA. This makes switching phones or adding functionality easier in my opinion.

@corneyl, the app is pretty cool. One issue I see is that if you are a “regular” Android user you don’t know the data for the “Broadcast Action”.

Also, an option to change the full topic would be nice.

@fabaff I know, but it’s also more targeted at experienced users. Maybe I will implement a way to add presets in the future, so it’s more usable for less experienced users, or just less typework. Btw, for me I’t just a hobby project which I published on the play store.

Would you like to be able to change the full topic for each broadcast item, or for all at once in the settings?

@AbraKabastard I tried to support also Android 4.4, but it seems that the library I’m using for MQTT doesn’t support that. At least it didn’t work on a virtual device.

It would be awesome to be able to change the full topic if needed. For Home Assistant android/broadcast/device-id works fine but it would make it easier to use it with other tools or beside other tools.

No obligations, asking is for free :slight_smile:

Thanks for trying mate

Nice! Been looking for something like this