It seems to be not a problem with MQTT, but with the syntax of the YAML you’re using, Can you post the exact configuration YAML within triple back ticks (```). Then it gets formatted as code…
automations.yaml
-.trigger:
…platform: mqtt
…topic: ‘android/broadcast/gsmruben’
…condition: state
…value_template: ‘{{ trigger.payload_json.action == “com.samsung.sec.android.clockpackage.alarm.ALARM_ALERT” }}’
…action:
…service: switch.turn_on
…entity_id: switch.lamp
. = space
Thx for the fast respon on my question
Gr Ruben.
I got around the stock Alarm disabilities by using the Do Not Disturb feature instead. I set DND to remain active until “Next Alarm” and when DND disables itself (when the Alarm triggers) as the action/trigger for Tasker.
When I set DND it runs a HA “Nighttime” script and when the Alarm goes off in the morning it runs a “Wake Up” script.
Corneyl !
I did it it works
Alarm phone = light in my room on
What did i change ?
my code (yaml) now:
- id: alarm_phone
trigger:
- platform: mqtt
topic: 'android/broadcast/gsmruben'
condition:
condition: and
conditions:
- condition: template
value_template: '{{ trigger.payload_json.action == "com.samsung.sec.android.clockpackage.alarm.ALARM_ALERT" }}'
action:
service: switch.turn_on
entity_id: switch.lamp
i add the - id: alarm_phone
Gr Ruben
@corneyl really nice app. Exactly what I was looking for.
Unfortunately it seems, that I don’t know the intent of the android native clock app.
At least if my alarm is activated the mqtt message is not send and also the counter is not increased.
If I press “Send Test Message” my automation is triggered.
Any idea which intent I can try?
This page lists a lot of intents: https://stackoverflow.com/questions/4115649/listing-of-manufacturers-clock-alarm-package-and-class-name-please-add
It also lists several intents for the default android clock app. Are you sure you’re using that one? Each brand normally delivers it’s own alarm clock app.
yes I installed the stock alarm clock app.
I was using “adb logcat” to find out the intent and caught the following output:
03-15 21:27:00.802 1164 1279 I ActivityManager: Displayed com.google.android.deskclock/com.android.deskclock.alarms.AlarmActivity: +461ms (total +33s388ms)
So I tried: “com.android.deskclock.alarms.AlarmActivity” as the intent value.
unfortunately no success.
I also looked up for permission, and no permissions are set for your app. Is this right?
did you also try com.android.alarmclock.ALARM_ALERT
and com.android.deskclock.ALARM_ALERT
?
Permissions are not needed for alarm clock intents as far as I know. Only for special intents, like when someone calls e.g.
ok got a bit closer. I have a huwai phone with EMUI. ANd I installed the stock clock app of android.
If I’m using the Emui alarm clock:
com.android.deskclock.ALARM_ALERT
Seems to work.
But still wondering why the stock app is not throwing the intent.
How to set up with Tasker + MQTT:
- install tasker
- give it app permissions for everything (maybe storage and telefon is enough, but it didnt work without doing it)
- install mqtt addon for tasker: mqqt publisher https://play.google.com/store/apps/details?id=net.nosybore.mqttpublishplugin
- open tasker
— in profile tab click the +Icon -> event -> date/time -> alarm clock
— add new task for this profile (this will probably open automatically, tasker GUI is quite messy…)
— give task a name -> task edit opens automatically -> click on the +Icon -> plugin -> mqtt publisher
— edit the “configuration”:
---- add IP of your mqtt broker, add Port (1883 for non SSL mqtt is default), add client id (something that is not used yet, for example “myalarmphone”, doesnt really matter), add username + passwort if your mqtt broker needs that, add a topic (call it what ever you want, like “light/wakeup” or simply “wakeup”), QoS 1, accept
— you can test this now, by listening to your mqqt broker. For example on a raspberry pi with mosquitto to listen to all incoming publishes:
mosquitto_sub -h HOSTIP -t "#" -v -u USER -P PASSWORD
— and in Tasker click on the Task you just created and press the play button. your topic should be shown (e.g. “light/wakeup”)
–open Home Asssistant automation.yaml and add this (screenshots because formatting got messed up by this forums markup):
replace “obi1” by “sonoffs” or “sonoff”. For service you may add the name you gave to your switch. I am not familiar with automation.conf yet. Got it to work by copy&paste and try&error.
you can use this instead if you use a tasmota sonoff switch:
This is my first post on the HA forums, so thank you to everyone.
I have been using this android app for a few weeks now and everything has been working great. The lights in my bathroom turn on to a dim setting when our alarms go off in the morning.
@corneyl I have a feature request if this is still being actively developed. It would be nice to have the daily alarm count instead of a running tally of the overall number of events since inception. The JSON payload on my current version includes a “count” variable which is the overall count since inception and an “android.intent.extra.ALARM_COUNT” variable which seems to stay at 1 regardless of how many times the alarm is triggered.
The use case for this would be triggering an action in the house to forcefully help to wake someone up after, perhaps, 3 alarms are triggered within a set amount of time.
Thank you again for the great app. It is simple to setup and very intuitive to use.
It’s not actively developed, but so now and then I spend some time on it.
For clarity: would you like to have a count of the past 24 hours, or one that resets at midnight?
A reset at midnight would work for my use case. Perhaps resetting the count after no alarm activity for a set period of time, say 1 hour, would also work. This would allow you to keep track of snooze events in a given alarm ‘session’ if there were multiple alarms used in one day.
Either way having a count of snoozes would be useful.
Thank you again. Cheers.
@corneyl, this is awesome.
The intent “android.intent.action.ACTION_PHONE_STATE_CHANGED” needs some privileges declared in the app manisfest file. I need this intent for automations related with phone calls.
Would you be available to add the ability for listening broadcasts about calls and telephony, please?
Thanks.
Cool option , but isn’t this all easier with the new routines function in the Google clock? Then you don’t need an extra app and mqtt? It’s a built-in feature now… ?
I was looking for a native android way to do this so i could use my voice to activate my alarm.
Unfortunately i discovered that my previous way was way more flexible and offered more features, you might find it interesting.
I use an app called ‘sleep as android’ that is hooked into ifttt by using webhooks. Besides all the default triggers, this has some smart triggers build in giving much more posiblities to automate things.
For example, it has a webhook tigger called ‘smart_period’ that fires 45m before my set alarm goes off. This allows for my thermostat to be set to a temperature and thus making sure it’s nice and cosy when the alarm rings without having to set a thermostat schedule. This also initiates a wake up light and turns on the coffee maker 30 minutes after the trigger went off.
It also fires an event at the moment you should go to bed to meet your sleep targets which you might find interesting.
The setup is quite simple and well documented for IFTTT and hooking IFTTT into hass.
Some examples:
- sleep_tracking_started
- sleep_tracking_stopped
- sleep_tracking_paused
- sleep_tracking_resumed
- alarm_snooze_clicked
- time_to_bed_alarm_alert
- fires when you get a bedtime notification
- alarm_alert_start
- alarm_alert_dismiss
- fires when you dismiss alarm (after you solve CAPTCHA, if it’s set)
- rem
- fires when we estimate the start of REM phase
- antisnoring
- fires when we detect snoring
- smart_period
- fires 45 minutes before the smart wakeup period starts
Just FYI.
Sorry, I don’t have time at the moment to work on this.
But I’ve put the code on github so if you want to add something yourself you’re welcome to create a PR .
Those who already have Tasker or an automation app compatible with Tasker (e.g. Automate) or would rather use something else than IFTTT might like to know that they can use a Tasker task (or, e.g., an Automate flow) to act on Sleep as Android events. I have a setup in which Tasker triggers HA scripts when I start sleep monitoring (to turn of my night stand lamp) and when I stop sleep monitoring (to turn on my coffee machine and turn on some lights if it is dark outside).
I understand, but for those who do not specifically look for a tasker way, IFTTT is an alternative that works great for me to do tasks like these.
If u do not mind using IFTTT, this works wonders. Unfortunately, you will be bound to the internet. Then again, on the very rare occasion that this would happen to me, I guess I would survive to not having a wake-up light and flipping the switch on the coffeemaker myself.
Edit: Excuse me, I now see that I misinterpreted your reply. The text above might still be valuable.
Anyone managed to use it with Google Clock? It works ok with Samsung clock but I can’t figure out which intent should be used for Google Clock.