Adjustable Wake-up to Android alarm

This blueprint wakes you up:

  • to your custom actions
  • if your custom conditions are met
  • before your phones next alarm with an custom offset.
    • It uses the next alarm sensor from the HA Android App.
    • It uses a date and time helper entity to store the (phone alarm time - offset)

:tipping_hand_man: Usage

  1. Create Date and/or time entity
    The Automation will use this to store the (phone alarm time - offset)
    No need to manually set a time there.
    Open your Home Assistant instance and show your helper entities.

  2. Enable next alarm sensor on the HA Android App
    HA App → Settings → Companion App → Manage Sensors → Next Alarm → enable

  3. Import the Blueprint
    Open your Home Assistant instance and show the blueprint import dialog with a specific blueprint pre-filled.

  4. Create an Automation based on the imported Blueprint Adjustable Wake-up to Android alarm
    Open your Home Assistant instance and show your blueprints.

  5. Set an alarm on your phone

:sparkles: Features

  • Offset (how many seconds before the phone alarm goes off)
  • Select any action to run, e.g. turn on lights, play media, etc…
  • Select any condition, e.g. only run if person is home, only run if sun has not risen yet, etc…

:bulb: Some Inspiratios: (at your own risk)

  • If the sun has not risen yet, turn on the bedroom lights 10 minutes before the phone alarm goes off
  • If person 1 is at home, switch on the TV and tune it to a news channel 30 minutes before the phone alarm rings
  • If person 2 is not at home, retrieve today’s calendar events and announce them on the bedroom speaker 2 minutes before the alarm is set to go off
  • If the temperature outside is below 0°C, start warming up the car 45 minutes before the alarm is set to go off
  • Wake up to an inspirational quote from a text-to-speech service, right before the alarm goes off

:wrench: Requirements

  • Android phone with mobile app
  • Next alarm sensor activated
  • Date and time helper entity
  • Home Assistant Version 2023.8.x or higher

:fist_left: Tips, Tricks and Gotchas

  • You can add the helper entity to your lovelace dashboard to see the time when the actions will run.
  • You cannot test the action in the automation editor (run). You have to wait for the next alarm to go off.

:hammer_and_wrench: Changelog

  • 2023-10-15: Fix when disabling the phones alarm the automation was still running @Propboot
  • 2023-08-06: Initial release
blueprint:
  name: Adjustable Wake-up to Android alarm
  description: >
    # Adjustable Wake-up to Android alarm v2

    When the specified __conditions__ are satisfied, it runs these specified __actions__ prior the phone's next alarm
     
    ## 🔧 Requirements:
      - [Android app](https://play.google.com/store/apps/details?id=io.homeassistant.companion.android) installed on your phone
      - Next alarm sensor activated in the app (HA App → Settings → Companion App → Manage Sensors → Next Alarm → enable)
      - Date and time helper entity
        [![Open your Home Assistant instance and show your helper entities.](https://my.home-assistant.io/badges/helpers.svg)](https://my.home-assistant.io/redirect/helpers/)    
      - Home Assistant version 2023.8.0 or higher

    ## 💡Some Inspiratios: **(at your own risk)**
     - If the sun has not risen yet, turn on the bedroom lights 10 minutes before the phone alarm goes off
     - If person 1 is at home, switch on the TV and tune it to a news channel 30 minutes before the phone alarm rings
     - If person 2 is not at home, retrieve today's calendar events and announce them on the bedroom speaker 2 minutes before the alarm is set to go off
     - If the temperature outside is below 0°C, start warming up the car 45 minutes before the alarm is set to go off
     - Wake up to an inspirational quote from a text-to-speech service, right before the alarm goes off

  domain: automation

  author: op00
  homeassistant:
    min_version: 2023.8.0
  source_url: https://tbd.tbd/

  input:
    offset:
      name: Offset
      description:
        "Enter an offset in seconds for the next alarm. Specify when the action should run __before__ the alarm\n\n
        _max: 3600s = 1 hour_"
      selector:
        number:
          min: 0.0
          max: 3600.0
          mode: box
          step: 1.0
          unit_of_measurement: Seconds
    alarm_source:
      name: Alarm Source
      description: "Select the alarm source\n\n
        _your Android phone's next alarm sensor_"
      selector:
        entity:
          filter:
            integration: mobile_app
            device_class: timestamp
          multiple: false
    alarm_helper:
      name: Alarm Helper
      description: "Select the date and time helper\n\n
        _manually created helper_"
      selector:
        entity:
          filter:
            domain: input_datetime
          multiple: false

    conditions:
      name: Conditions
      description:
        "Choose the circumstances under which the actions will or will not run\n\n
        _can be multiple or none_"
      default: []
      selector:
        condition: {}

    actions:
      name: Actions
      description: "Actions to run before alarm goes off\n\n
        _can be multiple_"
      default: []
      selector:
        action: {}
variables:
  offset: !input offset
trigger:
  - platform: time
    at: !input alarm_helper
    id: wake_up
  - platform: state
    entity_id:
      - !input alarm_source
    id: helper_update
action:
  - choose:
      - conditions:
          - condition: trigger
            id: helper_update
          - condition: template
            value_template:
              '{{ trigger.to_state.state not in ["unknown","unavailable"]
              }}'
        sequence:
          - service: input_datetime.set_datetime
            data:
              timestamp: "{{ (as_timestamp(trigger.to_state.state) |int ) - (offset)}}"
            target:
              entity_id: !input alarm_helper
      - conditions:
          - condition: trigger
            id: helper_update
          - condition: template
            value_template:
              '{{ trigger.to_state.state in ["unknown","unavailable"]
              }}'
        sequence:
          - service: input_datetime.set_datetime
            data:
              datetime: "1970-01-01 00:00:00"
            target:
              entity_id: !input alarm_helper
      - conditions:
          - condition: trigger
            id: wake_up
          - condition: and
            conditions: !input conditions
        sequence: !input actions
    default: []
mode: single

:construction: ToDo

  • :black_square_button: Spellcheck
  • :black_square_button: Handle snooze, setting a new alarm when the alarm is still running.
  • :black_square_button: Ability to only listen to a specific alarm from android (not sure if that’s possible)
  • :black_square_button: Fix manual trigger for testing

🧑🏼‍🤝‍🧑🏻 Contributions

Very welcomed and please do, so far:

  • Thanks @Propboot for providing a fix, when the alarm gets disabled
13 Likes

@op00 I now see what you realized, that everything people have been requesting of your previous blueprint can all be implemented using conditions. Brilliant in it’s simplicity!

Hi @op00
Thank you for this great blueprint. I noted that deactivating the alarm does not deactivate the scheduled alarm sequence. So I added the following condition:

  - conditions:
    - condition: trigger
      id: helper_update
    - condition: template
      value_template: '{{ trigger.to_state.state in ["unknown","unavailable"]
        }}'
    sequence:
    - service: input_datetime.set_datetime
      data:
        datetime: "1970-01-01 00:00:00"
      target:
        entity_id: !input alarm_helper

I am new to HA, so this will not be the most elegant solution but perhaps it is a helpful inspiration.

1 Like

Thank you, that’s great and I have updated the blueprint. Wish there was better versioning with blueprints.

I want to make a “wake up light” where a light slowly increases in brightness from the “offset” time until the alarm goes off. I see this older blueprint has functionality for this: Wake up to lights at next alarm (android), but since that one is deprecated I’m guessing it should also be possible with this one. Could anyone point me in a direction on how to implement that?

@kwint That’s what I use it for. If your light supports transition. You can add a service call ligth.turn_on with transition time to the actions.
Add Action → Call Service → Light: turn on → Select your Target → Select Transition (set a time) → select Brightness (target brightness)

or yaml

service: light.turn_on
data:
  transition: 30
  brightness_step_pct: 100
target:
  entity_id: light.somelight

if your light doesn’t support transition, i made this blueprint script here: Increase or decrease light brightness over time - Blueprints Exchange - Home Assistant Community (home-assistant.io)

I have a problem with this blueprint.

When I make a new automation the alarm which is already sets works. But when I change the alarm the steps in the automation change.
If I look at the trace timeline it says: “Triggered by the state of sensor.tel_ruben_next_alarm at December 22, 2023 at 15:42:42” and suddenly only chooses option 1 therefore not executing the sequence.

sorry, not sure if I understand your question/problem. Sorry. But the blueprint/automation has two triggers. One, when the alarm is being set/changed (changes the helper) and the time condition (actual alarm, with the configures actions)

When I change my alarm this happens.

The wrong option is chosen, it should be option 3.

EDIT: nvm, all of a sudden it’s working again

1 Like

Thank you for this blueprint, it is exactly what I was looking for.

But I still have a question of understanding:
If I create several automations with the blueprint, do I need a separate helper for each automation or can the automations share one helper?

Thank you for this blueprint!

It was working for a while, but since a few days ago I have an issue: the first alarm fails to trigger anything, and only the subsequent snoozes work.
But even weirder: it works fine when I use an alarm in the middle of the day; only the morning one fails :face_with_raised_eyebrow:

I can’t see anything in the traces (https://file.io/q5WxK6JVYxHO) nor the logs :

2024-01-18 07:44:40.836 WARNING (Thread-5) [pychromecast.socket_client] [Salon CCwGTV 4k(192.168.1.25):8009] Heartbeat timeout, resetting connection
2024-01-18 08:06:26.461 WARNING (Thread-5) [pychromecast.socket_client] [Salon CCwGTV 4k(192.168.1.25):8009] Heartbeat timeout, resetting connection
2024-01-18 08:25:10.571 WARNING (Thread-5) [pychromecast.socket_client] [Salon CCwGTV 4k(192.168.1.25):8009] Heartbeat timeout, resetting connection
2024-01-18 08:26:31.666 WARNING (Thread-5) [pychromecast.socket_client] [Salon CCwGTV 4k(192.168.1.25):8009] Heartbeat timeout, resetting connection
2024-01-18 08:55:00.348 WARNING (MainThread) [homeassistant.components.automation.android_reveil_wake_up_alarm] Android : réveil wake up alarm: Already running
2024-01-18 08:55:06.611 WARNING (MainThread) [homeassistant.components.automation.android_reveil_wake_up_alarm] Android : réveil wake up alarm: Already running
2024-01-18 09:04:51.136 WARNING (MainThread) [homeassistant.components.automation.android_reveil_wake_up_alarm] Android : réveil wake up alarm: Already running
2024-01-18 09:04:55.291 WARNING (MainThread) [homeassistant.components.automation.android_reveil_wake_up_alarm] Android : réveil wake up alarm: Already running
2024-01-18 09:15:00.395 WARNING (MainThread) [homeassistant.components.automation.android_reveil_wake_up_alarm] Android : réveil wake up alarm: Already running
2024-01-18 09:15:05.504 WARNING (MainThread) [homeassistant.components.automation.android_reveil_wake_up_alarm] Android : réveil wake up alarm: Already running
2024-01-18 09:15:11.484 WARNING (MainThread) [homeassistant.components.automation.android_reveil_wake_up_alarm] Android : réveil wake up alarm: Already running
2024-01-18 09:15:24.940 WARNING (MainThread) [homeassistant.components.system_log.external] Dots 2 - Single press action
2024-01-18 09:24:28.164 ERROR (MainThread) [homeassistant.components.hassio.handler] /ingress/validate_session return code 401
2024-01-18 09:24:28.164 ERROR (MainThread) [homeassistant.components.hassio] Failed to to call /ingress/validate_session - 
2024-01-18 10:53:30.243 ERROR (MainThread) [aiohttp.server] Error handling request
Traceback (most recent call last):
  File "/usr/local/lib/python3.11/site-packages/aiohttp/web_protocol.py", line 350, in data_received
    messages, upgraded, tail = self._request_parser.feed_data(data)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "aiohttp/_http_parser.pyx", line 557, in aiohttp._http_parser.HttpParser.feed_data
aiohttp.http_exceptions.BadHttpMessage: 400, message:
  Data after `Connection: close`:

    b'HELP'
       ^
2024-01-18 10:59:54.820 WARNING (Thread-5) [pychromecast.socket_client] [Salon CCwGTV 4k(192.168.1.25):8009] Heartbeat timeout, resetting connection
2024-01-18 11:16:46.190 WARNING (Thread-5) [pychromecast.socket_client] [Salon CCwGTV 4k(192.168.1.25):8009] Heartbeat timeout, resetting connection
2024-01-18 11:41:35.310 WARNING (Thread-5) [pychromecast.socket_client] [Salon CCwGTV 4k(192.168.1.25):8009] Heartbeat timeout, resetting connection
2024-01-18 11:49:57.056 WARNING (Thread-5) [pychromecast.socket_client] [Salon CCwGTV 4k(192.168.1.25):8009] Heartbeat timeout, resetting connection
2024-01-18 12:51:19.289 WARNING (Thread-5) [pychromecast.socket_client] [Salon CCwGTV 4k(192.168.1.25):8009] Heartbeat timeout, resetting connection
2024-01-18 13:20:33.725 WARNING (Thread-5) [pychromecast.socket_client] [Salon CCwGTV 4k(192.168.1.25):8009] Heartbeat timeout, resetting connection
2024-01-18 13:37:02.080 WARNING (Thread-5) [pychromecast.socket_client] [Salon CCwGTV 4k(192.168.1.25):8009] Heartbeat timeout, resetting connection
2024-01-18 14:24:13.331 WARNING (Thread-5) [pychromecast.socket_client] [Salon CCwGTV 4k(192.168.1.25):8009] Heartbeat timeout, resetting connection
2024-01-18 15:01:29.214 WARNING (Thread-5) [pychromecast.socket_client] [Salon CCwGTV 4k(192.168.1.25):8009] Heartbeat timeout, resetting connection
2024-01-18 15:48:00.810 WARNING (MainThread) [homeassistant.components.automation.android_reveil_wake_up_alarm] Android : réveil wake up alarm: Already running
2024-01-18 15:48:04.396 WARNING (MainThread) [homeassistant.components.automation.android_reveil_wake_up_alarm] Android : réveil wake up alarm: Already running
2024-01-18 15:55:24.855 WARNING (Thread-5) [pychromecast.socket_client] [Salon CCwGTV 4k(192.168.1.25):8009] Heartbeat timeout, resetting connection
2024-01-18 16:01:08.733 WARNING (MainThread) [homeassistant.components.system_log.external] Dots 2 - Single press action
2024-01-18 16:11:44.649 WARNING (Thread-5) [pychromecast.socket_client] [Salon CCwGTV 4k(192.168.1.25):8009] Heartbeat timeout, resetting connection

There should be something happening at 8:42(alarm at 8:45 with 180s offset) but there is nothing.
It is simply not triggering :face_with_raised_eyebrow:

NOTE: the logs contain a test around 15:48 to confirm it indeed works sometimes/in the middle of the day.

Also I originally thought there could be an issue with the fact that I use a “long running” script as action (Sunrise Simulator Manual) but that does not seem to be an issue (and it worked for a while anyway).

Separate helpers. Per automation a helper. The automation sets the helper to the alarm set on the phone minus offset.

Your logs are full of warning that the automation cannot run because it is already running.

The automation has two modes. 1. Setting the Helper to the alarm - offset 2. triggering the actions when the time equals to the helper.

Try to create a new alarm on your phone and check if the entity (next_alarm) and the helper is set in the dev tools :

Open your Home Assistant instance and show your state developer tools.

Snoozing does set a new next_alarm value => Mode 1, and that’s also why you’d see “already running”

Hello @op00

I have in fact the same problem. In my oppion there is a design failure at the blueprint.

My alarm is set automatically to the next event on the next day at the same time.

Actions are starting with an offset of -60 and if I turn off the alarm the automation is already running. Trigger for a new alarm is starting but cannot run while the automation is already running.

I’v set the automation in mode parallel. In this way it is working but it isn’t the best solution.

Would be awesome to have also an offset (+) for the new next_alarm trigger. Or something else.

regards

Sorry, I don’t really understand the problem.
If you could maybe list a timeline (Setting the alarm, Snoozing, state of the helper, state of the automation). It may be that your alarm app is different and therefore behaves different than mine.

Do I understand correctly if I want this for several phones I just have to create several automations?

Yes, and separate helper. Although I have not tested that yet. Let me know if it worked or not.

I usually have 3 alarm clocks set. 5 seconds before the alarm clock triggers actions - turning on the light or raising the blinds (depending on the sun level) and starting the alarm clock on the nest speaker with a one minute delay.

This one-minute delay means that when the phone alarm clock starts after 5 seconds and the automation wants to set the time of the next alarm clock it does not happen because the automation is already running.

I know that getting rid of the delay will solve the problem but I’m looking for a way to trigger some of the action also after the alarm clock, not just before. To be honest, raising the blinds/ turning on the light would also suit me better after the alarm clock than 5 seconds before.

3 Likes

Is there an easy way to just run this automation when it’s an workday. So it should not run if there is a holiday, weekend (and maybe vacation days

  • this needs manual entries I guess?)