Alexa Alarm Automation with Pre-Alarm Sunrise Simulation

Hi all,
I was wondering if anyone had any ideas on how to make this better. Basically, it uses the alarm time set on a specific alexa device as a trigger to make a light slowly brighten in the 5 minutes before it goes off. The goal is to just set the alarm on the alexa device and have home assistant figure out the rest. Any ideas on how to more efficiently trigger the time?

- id: '1577441043621'
  alias: Alexa Alarm Lights
  trigger:
  - minutes: /5
    platform: time_pattern
  condition:
  - condition: template
    value_template: '{{ as_timestamp(states("sensor.alexa_bedroom_next_alarm")) -
      as_timestamp(now()) < 380 }}'
  action:
  - alias: ''
    data:
      brightness: 125
      power: false
    entity_id: light.bedside_lamp
    service: lifx.set_state
  - data:
      transition: 300
    entity_id: light.bedside_lamp
    service: light.turn_on

Thanks!

I did do this by using the TTS and media player capabilities of Alexa.
Essentially, I would set a date/time input in HA, and then it would trigger a script of things. One was to brighten lights slowly, then at a certain time play bird sounds from Spotify into Alexa as a media player.

The next step was to actually take input from a voice command to set the time, but I ended up being limited by Alexa’s inability to share data to HA and vice versa. My workaround here was to use the Alexa integration with Nodered to take a voice command to set the time. The limitation there is that you can only give a percentage amount… So I’ll likely set it up so that the voice command assumes 7:%% AM where %% is the given voice percentage. Any alarms set outside of 7-8AM will need to be overridden on the UI.

I do hope that we can get a good voice assistant device with a proper integration at some point. Until then, keep your duct tape out.

1 Like

This was my solution to making device specific Alexa alarms triggers for automations.

  1. Alexa Media Player customers component
    • you want this anyways, super cool -
  2. create sensor (‘sensor.date_time’)
  3. use as_timestamp()

Check out the link and let me know if it helped.

I’ve since updated this and it works very well. I’m using the alexa custom component which provides the current alarm time that’s set. Then I trigger a python script which starts slowly making the lights brighter 15 minutes before the alarm goes off. Trigger below:

{{ states('sensor.time') == (( as_timestamp(states('sensor.master_bedroom_next_alarm')) | int - 900 ) | timestamp_custom("%H:%M")) }}

The real trick is being able to stop it before the alarm starts. The python script takes an input boolean (“cancel switch”) that stops the script.

I then have another automation that turns on that “cancel switch” (and off 1 minute later) if the alarm time becomes “unavailable”. The result is that I can just tell Alexa to cancel the alarm at any point in the cycle and it stops.

In the end, this works without any interaction except for setting my alexa alarm.

2 Likes