Since you only gave use a partial error message then it’s hard to help you more. But most likely it’s what comes after as_timestamp
My automation:
alias: '[Bedroom] Morning'
description: ''
trigger:
- platform: template
value_template: >-
"{{states('sensor.date_time') ==
as_timestamp(states.sensor.motorola_razr_5g_next_alarm)|
timestamp_custom('%Y-%m-%d, %H:%M') }}"
condition: []
action:
- service: mqtt.publish
data:
topic: blinds/side/percentage
payload: '0'
mode: single
Error message:
- Template variable error: ‘sensor’ is undefined when rendering ‘{{ states(‘sensor.date_time’) == as_timestamp(sensor.motorola_razr_5g_next_alarm)| timestamp_custom(’%Y-%m-%d, %H:%M’) }}’
I got rid of the previous error, quotation marks were missing.
But the automation does not trigger. I see no errors in the log.
Could that be because of the mismatch of timestamps?
I have the following automation:
trigger:
- platform: template
value_template: >-
"{{states('sensor.date_time') ==
as_timestamp(states.sensor.pixel_3_next_alarm)|
timestamp_custom('%Y-%m-%d, %H:%M') }}"
condition:
- condition: and
conditions:
- condition: state
entity_id: group.persons
state: home
- condition: time
after: 06:00
before: '12:00'
action:
- service: script.play_radio_sb
mode: single
But when the alarm on the phone goes, it does not trigger this automation. What do I need to change to get the trigger working?
should be:
as_timestamp(states.sensor.pixel_3_next_alarm.state)
or
as_timestamp(states('sensor.pixel_3_next_alarm'))
You can always try your templates in the templates tool and see what they output before using them in automations.
You can use the sensor directly as you are trying to trigger the moment the alarm sounds off.
Thx, real easy that way
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 ?
After trying various solutions from this thread, a standard automation is actually already also working when you use the attribute “Local Time”:
alias: 'Alarm: Turn lights ON'
description: ''
trigger:
- platform: state
entity_id: sensor.samsung_s10_next_alarm
attribute: Local Time
condition: []
action:
- service: light.turn_on
target:
area_id: bedroom
mode: single
did you not try the example up above it can be even simpler
I tried my solution before reaching the end of this topic . Just wanted to mention it then as another possibility.
But in the GUI mode, HA give me no entities back, when I use the Time trigger in YAML mode it is fine.
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
Hmm the entity has that attribute. I will check this more closely tomorrow.
I have now created an issue No entities with "timestamp" attribute listed when using "Time" trigger in automations · Issue #10356 · home-assistant/frontend · GitHub
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
And this automation worked to flash my light when the alarm triggers then turn it off when I stop the alarm. Hopefully this holds up -
alias: S10 Alarm
description: ''
trigger:
- platform: time
at: input_datetime.alarm_clock
condition: []
action:
- service: light.turn_on
target:
entity_id: light.lounge_light_0
data:
effect: Slow Pulse
- wait_for_trigger:
- platform: state
entity_id: sensor.s10_next_alarm
- type: turn_off
device_id: 2d504a953e3e2f1b9f8c0922848f513e
entity_id: light.lounge_light_0
domain: light
mode: single
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.
I’m facing same problems with my Xiaomi Phone.
I finally solved all of them removing com.xiaomi.calendar with this guide: Xiaomi Bloatware List | Remove Bloatware on MIUI 12/11/10
Now my next_alarm sensor works as expected.
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:
But it returns “Configuration invalid”:
Maybe I’m not identing it well…
Any help would be appreciated.
Tks in advance
Hi,
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.