Hi everybody, I would like to share my most recent project:
Problem
I like to use my phone as an alarm clock for various things such as cooking and waking up in the morning. However, I have not found a convenient possibility to reliably and dynamically integrate my phones alarms into Home Assistant without actually having to actively interact with Home Assistant.
Ideally I want to be able to distinguish between following states of an alarm:
- when an alarm is active
- multiple user definable stages before and after ab alarm
- when an alarm is disabled
- when snooze-mode is enabled
All stages should be silent and parseable programatically.
Solution
I have forked the awesome open source alarm clock called simple clock from simple mobile tools and have extended it to do exactly what I have described above.
Each created alarm has the possibility to create multiple “silent alarms”. A silent alarm is a broadcast which can be processed by other apps such as Tasker, Easer or Broadcast to mqtt. The occurring event can then be sent to Home Assistant in order to trigger an automation.
The image below shows a screenshot of the applications alarm setup with two silent alarms scheduled:
- Audible alarm at 7:00 am
- Triggers broadcast
com.simplemobiletools.ALARM_IS_ACTIVE
- Triggers broadcast
- Silent alarm at 6:30 am
- Triggers broadcast
com.simplemobiletools.ALARM_GOING_TO_RING
- Triggers broadcast
- Silent alarm at 7:15
- Triggers broadcast
com.simplemobiletools.ALARM_GOING_TO_RING
- Triggers broadcast
Example usage Scenarios
-
Trigger my wakeup-light before my alarm activates without having to interact with home assistant
- A automation simply waits for the broadcast message
ALARM_IS_GOING_TO_RING
and then triggers the wakeup light routines
- A automation simply waits for the broadcast message
-
After I disable my alarm, I want certain devices to be turned on, such as my coffee machine, some lights, start playback of the local news, etc.
-
When I hit the snooze function too often, my home blasts me with unpleasant lights and plays loud music
Documentation
Following broadcasts are emitted:
com.simplemobiletools.ALARM_SET : when a new Alarm is created.
com.simplemobiletools.ALARM_GOING_TO_RING : when a silent alarm is triggered - only if the main alarm is enabled.
com.simplemobiletools.ALARM_IS_ACTIVE when an audible alarm is active.
com.simplemobiletools.ALARM_SNOOZED when an audible alarm has been snoozed.
com.simplemobiletools.ALARM_DISABLED when an audible alarm has been disabled.
All broadcasts contain the same payload with the attributes, which can be processed by other automations:
label
hours
minutes
days
id
All silent alarms have the same label as the main alarm, thus helping you distinguish individual alarms in your automations.
Example Automations
Wakeup light
This automation triggers my sunrise script once the MQTT message containing the action “ALARM_GOING_TO_RING” with the alarm label “get_up_work” is received.
- alias: 'Wake up light'
trigger:
- platform: mqtt
topic: 'android/broadcast/redmi-note-3'
condition:
condition: and
conditions:
- condition: template
value_template: '{{ "ALARM_GOING_TO_RING" in trigger.payload_json.action }}'
- condition: template
value_template: '{{ "get_up_work" in trigger.payload_json.label }}'
action:
- service: script.sunrise
Power on morning devices
This automation is triggered as soon as I disable the Alarm displayed when it is ringing on the phone. Again the conditions are a MQTT message containing the action “ALARM_DISABLED” with the alarm label “get_up_work”.
- alias: 'Alarm power on morning devices'
trigger:
- platform: mqtt
topic: 'android/broadcast/redmi-note-3'
condition:
condition: and
conditions:
- condition: template
value_template: '{{ "ALARM_DISABLED" in trigger.payload_json.action }}'
- condition: template
value_template: '{{ "get_up_work" in trigger.payload_json.label }}'
action:
- service: input_select.select_option
data:
entity_id: input_select.select_activity
option: "Nicht gesetzt"
- service: input_select.select_option
data:
entity_id: input_select.select_activity
option: "Aufstehen"
- service: scene.turn_on
entity_id: scene.comfortable
Download
Releases
20.02.20 broadcasts_v1.0.1-(5.1.0)
Changelog:
Update About section
New Feature: Enable/Disable, Update and Create alarms using intents
Change versioning scheme
Update Readme
16.02.20 [Release_v0.0.2]
Download: broadcast_v0.0.2.apk
Changelog:
Fixed issues with Android 10
Synced upstream
Convenience function to automatically adjust all silent alarms relative to a new alarm, when changed (prompt appears after changing alarm time)
All silent alarms of an alarm now have the same label of the triggered alarm
19.10.2019 Release_v0.0.1
Initial release
Source
Feedback
Please let me know if this is useful to you. I am open to ideas on how this can be improved. Furthermore, I am not responsible for missed alarms etc. usage at your own risk, this is the first release and may contain bugs, however it is working fine for me .
Feel free to create issues and feature requests in the git repository.