Trigger Automations When a Specific Echo Device's Alarm Goes Off

Hey guys, my template for next alarm not triggering anymore:

value_template: "{{ (as_timestamp(states('sensor.stefi_s_echo_show_next_alarm'),1e+11) - 18*60) <= as_timestamp(states('sensor.date_time_iso'),0) }}"

But there is also no error in the logs.
Any hints what’s wrong with my template?

PS.: it should trigger 18 minutes before the next alarm

thx

Solved!
I accidently removed the “sensor.date_time_iso”. After readding to my configuration all is working again.

Hey guys

Not sure what I’m doing wrong, as the Automation does trigger and switch on my heating as it should, but the logs warn me about this:

Error evaluating ‘template’ trigger for ‘websocket_api’: ValueError: Template error: as_timestamp got invalid input ‘unavailable’ when rendering template ‘{% set alarm_time = as_timestamp(states(‘sensor.echo_mancave_next_alarm’)) %} {% set current_time = as_timestamp(states(‘sensor.date_time’).replace(’,’, ‘’)) %} {% set pre_time = 1800 %} {{ current_time >= alarm_time - pre_time }}’ but no default was specified

Error evaluating ‘template’ trigger for ‘websocket_api’: AttributeError: ‘NoneType’ object has no attribute ‘tzinfo’

Admittedly, I never really looked into the logs as stuff just works, but trying to get as many things clean as possible, such stuff now makes me wonder where I’m going wrong.

Any help is much appreciated :slight_smile:

Since Oct '21 the as_timestamp and other filters have required that defaults are explicitly declared.

When there isn’t a defined next alarm, you are going to get errors because there’s no value to apply your filters to.

These two sources of errors are eliminated in the template trigger example I gave above.

Thanks so much!

I read everything in this thread, but templating still isn’t something I feel good with and therefore didn’t quite get it.

I tried your solution again and it works perfectly. Will review my other templates now as well on my quest to reduce errors and avoid “delay for” etc.

Can anyone here help me please,

I’d like to use the next_time senor of my echo. I tried every trigger you wrote above, but it will just not trigger.

I used the template from didgeridrew and I added a time sensor in my configuration.yaml

{% set alarm_time = states(‘sensor.bad_next_alarm_next_alarm’) | as_datetime %}
{% set minutes_before = 1 %}
{% if alarm_time != None %}
{{ now() >= alarm_time - timedelta(minutes = minutes_before) }}
{% else %}
False
{% endif %}

@kristina , double check your template…

  1. It looks like you have an autofill error that doubled _next_alarm : sensor.bad_next_alarm_next_alarm
  2. You have “fancy quotes” around the sensor’s entity id, you need to use plain quotes. This happens sometimes when copying text from the forum that isn’t in a formatted code block.
{% set alarm_time = states('sensor.bad_next_alarm') | as_datetime %}
{% set minutes_before = 1 %}
{% if alarm_time != None %}
{{ now() >= alarm_time - timedelta(minutes = minutes_before) }}
{% else %}
False
{% endif %}

Oh my goodness. I really didn’t see my fault with the double thing. The quotes were alright. These were just fancy because of the font in my internet explorer.

Thank you so much for your help.

1 Like

I’m a complete beginner at Homeassistant and I’m trying to set up my automation to run 5 minutes before the alarm, but I don’t really understand the example above.
I have created a sensor and can see the Developer Tool / Template that it shows True/False depending on whether the alarm is set 5 minutes before or not.

What I don’t really understand is how to create an automation of it.
This is the Triggers Template

  trigger:
    platform: template
    value_template: >
	{% set alarm_time = states('sensor.bedroom_next_alarm') | as_datetime %}
	{% set minutes_before = 5 %}
	{% if alarm_time != None %}
	{{ now() >= alarm_time - timedelta(minutes = minutes_before) }}
	{% else %}
	False
	{% endif %}

This is from the Edit in YAML

alias: Alexa WakeUp Light
description: ""
trigger:
  - platform: template
    value_template: "  trigger:\n    platform: template\n    value_template: >\n\t{% set alarm_time = states('sensor.bedroom_next_alarm') | as_datetime %}\n\t{% set minutes_before = 1 %}\n\t{% if alarm_time != None %}\n\t{{ now() >= alarm_time - timedelta(minutes = minutes_before) }}\n\t{% else %}\n\tFalse\n\t{% endif %}"
    enabled: true
condition:
  - condition: device
    type: is_off
    device_id: f3ed9a8f0a526677ae0e685f0bb5e1ba
    entity_id: switch.first_floor_bedroom_lamp
    domain: switch
action:
  - type: turn_on
    device_id: f3ed9a8f0a526677ae0e685f0bb5e1ba
    entity_id: switch.first_floor_bedroom_lamp
    domain: switch
mode: single

The trigger is not executed and can someone please show me how this should be done correctly?

You have a copy/paste error in your trigger configuration that is causing it to fail.

If you already created the template sensor, you do not need to use the template again in your trigger. You have not included the entity ID of your sensor so you will need to correct it (and possibly the to: state as well) before using the following automation:

alias: Alexa WakeUp Light
description: ""
trigger:
  - platform: state
    entity_id: sensor.#YOUR_ALARM_SENSOR#
    to: 'True'
condition:
  - condition: device
    type: is_off
    device_id: f3ed9a8f0a526677ae0e685f0bb5e1ba
    entity_id: switch.first_floor_bedroom_lamp
    domain: switch
action:
  - type: turn_on
    device_id: f3ed9a8f0a526677ae0e685f0bb5e1ba
    entity_id: switch.first_floor_bedroom_lamp
    domain: switch
mode: single

Thanks a lot Didgeridoo for helping out :blush:

Got everything working flawlessly now :+1: :ok_hand: :laughing:

Hi all, I’ve been using the next.alarm to start my espresso machine 30 minutes before it goes off and it has been going great for a year thanks to a Shelly built inside it…. That s until this week.

Alexa is failing to send the next alarm to Home Assistant this week. It remains Unknown after the alarm is set and on my dashboard it is stuck on Dec 31, 1969 7:00pm (same time it always shows when an alarm isn’t set).

Anyone else having trouble with Alexa sending the alarm time?

This works perfectly for me – very concise and correct!!

Is there a way to template a timer instead of using .js modules in Lovelace to get this countdown timer effect?

I’d like to create template sensors for up to 3 Alexa timers that I can then use on my Sunton 7" OpenHASP display thats in my kitchen. So much easier to glance at it instead of asking Alexa every time, esp w/ multiple timers going on.

image

this is a very unique approach, but it doesnt do me any good if I cant set an entity to a countdown value.

I had the same issue with every “next alarm” showing unknown when an alarm was set! I just had to update to the newest release of alexa_media_player. I wanted to leave a comment incase anyone else is still running into this issue.

Additionally, for anyone troubleshooting and testing, make sure when you set an “alarm” you say the time. Otherwise if you say “set an alarm for one minute”, it actually sets a timer. You have to say “set an alarm for xx:xx”. :confused:

1 Like

Amazon can only dig up so many alarms from their time mines everyday… they can’t let us peons go around wasting that precious natural resource when a timer will be perfectly sufficient… :upside_down_face: