Wow , this is exactly what I’m looking for , I added it in my HA.
I removed the 30 minutes -1800 though , want the lights on @ alarmtime
I only have 2 issues , my wifes alarm time when she dismisses an alarm shows negative values , like - 2 hours , 25 minutes untill next alarm. while I have an alarm set at a later timepoint.
and I sometimes have an alarm set an hour apart from my wife and it doesnt switch to my alarm when wife dismisses hers ?
is the negative value an alarm app feature or a template thing ?
and is there a certain HA app update interval for it not to take my alarm time ?
really? It should be picking that up there. Might be worth opening a frontend issue because it should pick up any sensor with device_class: timestamp as its attribute
I haven’t tried but from previous experiments I can’t see this working properly because the next alarm includes calendar events. So if I have eg. A birthday calendar event before the set alarm it is getting the date time from there. I’m playing about with a template sensors to try define the two using
{% if 'calender' in (state_attr('sensor.s10_next_alarm', 'Package' )) %} {{ states('sensor. S10_next_alarm' }} {% endif %}
This is grabbing the alarm clock value only, now I just need to get it into a date time helper and hopefully I can simply use that as the trigger.
Here is a solution I found using one input datetime helper and one automation:
alias: Set Alarm Input Helper
description: ''
trigger:
- platform: state
entity_id: sensor.s10_next_alarm
condition: []
action:
- service: input_datetime.set_datetime
data_template:
entity_id: input_datetime.alarm_clock
datetime: >-
{% if 'clock' in (state_attr('sensor.s10_next_alarm', 'Package' )) %} {{
states('sensor.s10_next_alarm') |as_datetime |as_local }} {% endif %}
mode: single
Now I just need to create an automation that is triggered by time and the helper is available to me in the UI - so I tell lies I need 2 automations
Thanks for all the info, this thread helped me to see some different options
Happy 2022
Edit/ update: I encountered another problem here, if the snooze is set then the snooze time is added to the input helper even tho I push dismiss alarm on the phone. With the snooze turned off in the android alarm settings it works but I need to turn the flashing light off by another means. I could probably use a condition or boolean but I’m reasonably happy to turn my light automation off with a timer for now.
Hi all!
I’ve read several posts and topics without finding a solution for my issues.
I don’t have a regular wake-up time. Some days I wake up at 2:30am, others 4:30am, others 8am, so on…
I would like to set my alarm on mobile phone and based on “sensor.s8_bt_next_alarm” I would trigger automations BEFORE the alarm sounds ON.
For example:
I set my alarm for 2:30am.
At 2:00am (sensor.s8_bt_next_alarm MINUS 30min) turn on toilet heater.
At 2:20am (sensor.s8_bt_next_alarm MINUS 10min) turn on air conditioner on dressing room.
At 3:00am (sensor.s8_bt_next_alarm PLUS 30min) turn on air conditioner on kitchen.
At 3:10am (sensor.s8_bt_next_alarm PLUS 40min) turn off toilet heater.
At 3:15am (sensor.s8_bt_next_alarm PLUS 45min) turn off air conditioner on dressing room.
At 3:30am (sensor.s8_bt_next_alarm PLUS 60min) turn off air conditioner on kitchen.
Mainly I understand that I need to convert my “sensor.s8_bt_next_alarm” to “minutes to next alarm” and the trigger automations based on those “minutes to next alarm”.
For that I added this on configuration.yaml, check after line 107:
This is almost what I am looking for. It works as expected however one minor problem. When I disable alarm, helper entity value remains so even if alarm is disabled automation triggers. I removed if statement to set it to unavailable but it doesnt change the value. Do you have any idea how to do?
Edit: I added a NOT condition to my automation. if the next alarm state equals unavailable, light wont turn on.
My alarm trigger is quite often not working. My alarm was set to 7.30, as you can see in the screenshot, one second before the alarm should be triggered, it changes to unavailable.
Do others have experienced this as well? And is there a work around to get the trigger working reliable?
trigger:
- platform: time
at: sensor.phone_wietse_next_alarm
- platform: state
entity_id:
- group.persons
to: 'home'
condition:
- condition: and
conditions:
- condition: state
entity_id: group.persons
state: 'home'
- condition: not
conditions:
- condition: state # If media player is already on, don't execute
entity_id: media_player.lg_sl10yg
state: 'playing'
action:
- service: script.play_radio_sb
mode: single
This does not happen to me, but I think the reason is that your phone and HA are not exactly synced in time or the phone deletes the alarm just before it rings.
I would solve it with a template trigger to trigger 10-15 seconds before the alarm.
If it’s important that they start at the same time as the alarm then delay the automation in the actions first.
Sorry, I thought this thread was stale. I had to set a dummy alarm. eg. I set an android alarm for 2026 or something so that it falls back to that. It’s not elegant at all but I think I seen mention of something alarm clock related in a recent homeassistant update; I am about to get back to investigating a better solution and will keep you posted
The other issue was if an android timer was set it triggerd the automation.
The major issue with your template is that you aren’t comparing your alarm value to the current time. Without a comparison your template will never trigger the automation. From the docs:
The trigger will fire if the state change caused the template to render ‘true’ (a non-zero number or any of the strings true , yes , on , enable ) when it was previously ‘false’ (anything else).
The warning is due to either a typo in your template or the phone not having an alarm set. You can use an if: clause to get rid of the warning caused by not having an alarm set:
trigger:
- platform: template
value_template: >-
{% set x = states('sensor.phone_wietse_next_alarm') %}
{% if x not in ['unavailable', 'none', 'unknown'] %}
{{ now() >= x | as_datetime | as_local - timedelta(seconds=10) }}
{%else%} False {% endif %}
Thank you for the response. Your template is working, only needed to change the “timedelta” to 1 minute. I think it has to do with the “now()” updating only once a minute.
For others who want to use the working template, this one is working:
trigger:
- platform: template
value_template: >-
{% set x = states('sensor.phone_wietse_next_alarm') %}
{% if x not in ['unavailable', 'none', 'unknown'] %}
{{ now() >= x | as_datetime | as_local - timedelta(minutes=1) }}
{%else%} False {% endif %}