The mobile alarm time would be a great to have in home assistant! This works in other apps so should be possible for this app also.
For example, on Samsung native alarm app, the broadcast intents are:
com.samsung.sec.android.clockpackage.alarm.ALARM_STOPPED_IN_ALERT
com.samsung.sec.android.clockpackage.alarm.ALARM_ALERT
I've been testing this in a small stand-alone app to do exactly this and it works great.
On many phones you could use the android.app.action.NEXT_ALARM_CLOCK_CHANGED intent. In onReceive of the BroadcastReceiver you can then get the nextAlarmClock from the AlarmManager.
On Home Assistant's side I have added a input_datetime:
android_alarm:
name: Android alarm
has_date: true
has_time: true
Request body of the POST to /api/services/input_datetime/set_datetime would be like:
{
"entity_id": "input_datetime.android_alarm",
"datetime": "2019-12-01 08:00:00"
}
Then you can use a trigger for automations like so, provided you have a time_date sensor:
value_template: "{{ states('sensor.date_time') == ( states.input_datetime.android_alarm.attributes.timestamp | int - 900 ) | timestamp_custom('%Y-%m-%d, %H:%M', True) }}" # Trigger 15 minutes before android alarm datetime
This works really well, the intent gets fired whenever the next alarm changes. This includes the moment an alarm goes off, but also when alarms get disabled. When all alarms get disabled I just update the android_alarm with the default 1970-01-01 00:00 datetime.
I could potentially create a PR for this at some point, but have no idea if this is functionality that is in scope for this app but also what the UI requirements are for settings in this app, seeing the settings activity is empty still.
Does this work with Google home alarms?
I'd love to run an automation when my Google home alarm is turned off
On Wed, Dec 4, 2019, 11:23 AM Martijn van der Woude <
[email protected]> wrote:
I've been testing this in a small stand-alone app to do exactly this and
it works great.On many phones you could use the
android.app.action.NEXT_ALARM_CLOCK_CHANGED intent. In onReceive of the
BroadcastReceiver you can then get the nextAlarmClock from the
AlarmManager.On Home Assistant's side I have added a input_datetime:
android_alarm:
name: Android alarm
has_date: true
has_time: trueRequest body of the POST to /api/services/input_datetime/set_datetime
would be like:{
"entity_id": "input_datetime.android_alarm",
"datetime": "2019-12-01 08:00:00"
}Then you can use a trigger for automations like:
value_template: "{{ states('sensor.date_time') == ( states.input_datetime.android_alarm.attributes.timestamp | int - 900 ) | timestamp_custom('%Y-%m-%d, %H:%M', True) }}" # Trigger 15 minutes before android alarm datetime
This works really well, the intent gets fired whenever the next alarm
changes. This includes the moment an alarm goes off, but also when alarms
get disabled.—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
https://github.com/home-assistant/home-assistant-android/issues/56?email_source=notifications&email_token=AAICE7EAUITXT6Q5ZXU4YVDQW7KQTA5CNFSM4JQMM3AKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEF5SYRQ#issuecomment-561720390,
or unsubscribe
https://github.com/notifications/unsubscribe-auth/AAICE7CF7YKP4L2HAEAWITLQW7KQTANCNFSM4JQMM3AA
.
@martijnvdwoude we wouldn't hack it together with set state. The alarms should be exposes as a sensor via mobile_app with the timestamp device class.
But yeah, a PR for this would be welcome. Here is info on how to expose sensors to Home Assistant. https://developers.home-assistant.io/docs/en/app_integration_sensors.html
We could keep track of a sensor named "Next Alarm"
@balloob Ah, yes much better. I just checked this repo out today, have just been digging through the code this afternoon. Might take a stab at it though!
As another reference @Johboh implemented a standalone app for this some while ago: https://github.com/Johboh/hassalarm
Most helpful comment
@balloob Ah, yes much better. I just checked this repo out today, have just been digging through the code this afternoon. Might take a stab at it though!