Wake up to configurable actions at next alarm (android)

:construction: deprecated in favor of Adjustable Wake-up to Android alarm - Blueprints Exchange - Home Assistant Community (home-assistant.io) :construction:

This blueprint wakes you up to your custom actions at your phones next alarm with an offset.
This is the more advanced version of https://community.home-assistant.io/t/wake-up-to-lights-at-next-alarm-android/438277

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

: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 Wake up to lights at next 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 alarm goes off)
  • Select any action to run, e.g. turn on lights, play media, etc…
  • Only runs when a selected person is home (or any other location)
  • Option to run it only during night time (between sunset and sun rise)

:wrench: Requirements

  • Android phone with mobile app
  • Next alarm sensor activated
  • Date and time helper entity

:hammer_and_wrench: Changelog

  • 2023-03-11: Change text, people to person
  • 2023-03-04: Added option to run it only during night time (between sunset and sun rise)
  • 2023-03-01: Added Author
  • 2022-07-09: Added unit_of_measurement: “Seconds”

blueprint:
  name: Wake up to configurable actions at next alarm
  description:
    Wakes you up to configurable actions at your phones next alarm with
    an offset
  domain: automation
  author: op00
  source_url: https://community.home-assistant.io/t/wake-up-to-configurable-actions-at-next-alarm-android/438300

  input:
    offset:
      name: Offset
      description: Set a offset in seconds to the next alarm. When (before) the action should run
      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
      selector:
        entity:
          integration: mobile_app
          device_class: timestamp
          multiple: false
    alarm_helper:
      name: Alarm Helper
      description: Select the date time helper
      selector:
        entity:
          integration: input_datetime
          multiple: false
    location:
      name: Location
      description: Location where the person need to be for the action(s) to run
      selector:
        entity:
          integration: zone
          multiple: false
    sunset_sunrise_active:
      name: Sunset Sunrise
      description: Only run during night time (between sun set and sun rise)
      default: false
      selector:
        boolean:
    people:
      name: People
      description: Actions only when this person is in the location specified
      selector:
        entity:
          integration: person
          multiple: false
    actions:
      name: Actions
      description: Actions to run before alarm goes off
      default: []
      selector:
        action: {}
variables:
  offset: !input offset
  sunset_sunrise_active: !input sunset_sunrise_active
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: wake_up
          - condition: zone
            entity_id: !input people
            zone: !input location
          - condition: or
            conditions:
              - condition: template
                value_template: "{{ sunset_sunrise_active == false }}"
              - condition: sun
                before: sunrise
                after: sunset
        sequence: !input actions
    default: []
mode: single

:construction: ToDo

  • :white_check_mark: ToDo list
  • :white_check_mark: Create my link to import the blueprint
  • :black_square_button: Spellcheck

🧑🏼‍🤝‍🧑🏻 Contributions

  • Very welcomed and please do
5 Likes

I do not understand what should be: An auxiliary date and time object?
It’s empty there, and I can’t understand what I need to add? Time sensors from the home assistant cannot be selected there.

1 Like

What is the “date and time helper” … purpose? what it should be created / set too? etc?

Goto: Open your Home Assistant instance and show your helper entities. Settings/Devices & Services/Helpers to create a helper. This is required to store the date and time of the alarm with the offset. Think of it as a variable.
e.g. that’s mine

1 Like

For whatever reason this does not see my Pixel 5A’s next_alarm sensor. How do I get it to recognize that sensor?

UPDATE: Fixed. I had to turn on the settings on the app on my phone.

Would love for this to be able to read the weather forecast and traffic update at a low level as to not wake up my neighbors.

1 Like

Hey, I also have a pixel but can’t find the next_alarm option.
Can you tell me where to find it?

You need to enable it in the Home Assistant App. Settings → Companion App → Manage Sensors → Next Alarm → Enable Sensor

Thanks you very much for the blueprint, i really like it! Onlything is mis is a condition that it gets triggerd only after sunset and before sunrise. Is it possible to add this? And how?

Greeting and many thanks.

@Sarnog: I wish I could get up only when the sun has risen. You must live a luxurious life. :beach_umbrella:
Anyhow, I have updated the blueprint to include this feature. Please test it and let me know.

Hahaha, well it’s not that luxurious as it sounds. I work in shifts, so sometimes i need to sleep in daylight and there for also wake up in day light. Thanks for the change! i really appriciate it.

Hello op00,

I tested the automation this morning, but it’s not working unfortunatly.
I tried to multiple light entities and switched the sunset / sunrise option, but neighter of the sun options, triggers the light to go on.
It seems the automation is failing somewhere. Can you please review the automation?

Thanks in advance again!

Greetz,

Sarnog.

Sarnog, I think I’m having the same issue possibly.

Looking at the trace from when the automation was supposed to run I see the following error:
Error: In 'zone' condition: error matching person.ben with zone.home: entity person.ben has no 'latitude' attribute

This looks to be related to this issue:

I’ll probably just tweak the blueprint to remove those conditions and use my own in a subsequent automation.

It seems like that Sarnog had the same issue. I DM’d him/her and came to same solution. Maybe i should make the Zone thing optional in the blueprint. Don’t know how yet though.

Don’t make it a zone condition, but a state condition based on person.entity (home or not_home).

blueprint:
  name: Wake up to configurable actions at next alarm V2
  description:
    Wakes you up to configurable actions at your phones next alarm with
    an offset
  domain: automation
  author: op00
  input:
    offset:
      name: Offset
      description: Set a offset in seconds to the next alarm. When (before) the action should run
      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
      selector:
        entity:
          integration: mobile_app
          device_class: timestamp
          multiple: false
    alarm_helper:
      name: Alarm Helper
      description: Select the date time helper
      selector:
        entity:
          integration: input_datetime
          multiple: false
    active_hours:
      name: Active hours
      description: Only between set values below
      default: false
      selector:
        boolean:
    person:
      name: Person
      description: Select the person for the state condition
      selector:
        entity:
          integration: person
          multiple: false
    person_state:
      name: State of the person
      description: condition as to when the automation runs for the person selected
      selector:
        select:
          mode: dropdown
          options:
            - label: Home
              value: home
            - label: Away
              value: not_home
            - label: Unavailable
              value: unavailable
            - label: Unknown
              value: unknown
    actions:
      name: Actions
      description: Actions to run before alarm goes off
      default: []
      selector:
        action: {}
 variables:
  offset: !input offset
  hello: !input person
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: wake_up
          - condition: state
            entity_id: !input person
            state: !input person_state
          - condition: or
            conditions:
              - condition: template
                value_template: "{{ active_hours == false }}"
              - condition: sun
                before: sunrise
                after: sunset
        sequence: !input actions
    default: []
mode: single

try this, it’s checking state

Invalid blueprint: missing input definition person

my bad, it should be fixed now

Do i -redownload this blueprint via the link on top of this post, or is it a separate one? Because you named it v2, and it seems i get the same one as before using zone…

It’s a separate one and I want to keep it that way. As I guess the original works for most users and it supports zones. These import links, AFAIK only work with one blueprint per forum topic.

Create a yaml file in your /blueprints/automation/ folder and copy the text into it. (Studio Code Server addon will be your friend).

1 Like

Thanks a lot! It’s accepting the blueprint now. I’ll test it in the comming days… Many thanks again for the contribution and quick responces!

1 Like