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

Tags: #<Tag:0x00007fc41682d1d8> #<Tag:0x00007fc41682ce68>

I struggled with how to make device specific alarm automations, for when we have company and my father gets up two hours before me (he is a 5 am sort of guy). I know others have mentioned having children, and wanting their lights to come on when just their echo went off.

Step 1)
Make sure you have the Alexa Media Player custom component:


Step 2)

Add time sensors to your configuration.yaml file

sensor:
  - platform: time_date
    display_options:
      - 'time'
      - 'date'
      - 'date_time'
      - 'date_time_utc'
      - 'date_time_iso'
      - 'time_date'
      - 'time_utc'
      - 'beat'

Step 3)

Make an automation! Check your list of sensors and you will notice you have some new ones with the _next_alarm ending. For this example I will use sensor.master_bedroom_echo_show_next_alarm. Please swap it out for the device you want triggered. The rest should be copy and paste.

  trigger:
    platform: template
    value_template: >
      {% set alarm_time = as_timestamp(states('sensor.master_bedroom_echo_show_next_alarm')) %}
      {% set current_time = as_timestamp(states('sensor.date_time').replace(',', '')) %}
      {% set pre_time = 2 %}
      {{ current_time >= alarm_time - pre_time }}

This trigger will set off your automation 2 seconds before your echo specific alarm. It has to be before because once the alarm goes off it there will no longer be a _next_alarm time. If you need them to sync up add the following to your action.

action:
  - delay: 00:00:02
  - 

Enjoy!!!

I’m really interested in getting this to work but when I try to assemble the automation i get this error msg: Message malformed: invalid template (TemplateSyntaxError: unexpected ‘}’, expected ‘)’) for dictionary value @ data[‘value_template’]

platform: template
value_template: >
{% set alarm_time = as_timestamp(states(‘sensor.guest_room_echo_spot_next_alarm’)) %}
{% set current_time = as_timestamp(states(‘sensor.date_time’).replace(’,’, ‘’)) %}
{% set pre_time = 2 %}
{{ current_time >= ( alarm_time - pre_time }}

So first let’s make sure it’s formatted correctly.

trigger:
    platform: template
    value_template: >
        {% set alarm_time = as_timestamp(states('sensor.guest_room_echo_spot_next_alarm')) %}
        {% set current_time = as_timestamp(states('sensor.date_time').replace(',', '')) %}
        {% set pre_time = 2 %}
        {{ current_time >= alarm_time - pre_time }}

Try to copy and paste this code, let me know if that helps.

PS. In future when you paste code in here, highlight it and click the </> button, which will make sure it’s formatted correctly for posting.

Thank you I will try it out and my bad about the code.