How to use next alarm sensor

Thanks.
I actually got that fixed. It’s a Oneplus. What I did was to edit the android companion app, edit the next alarm sensor where we can define which app is able to ‘update’ the next alarm value and i’ve set it to oneplus clock app only. So i guess there was some other apk which was pushing some ‘alarm’ stuff to the sensor poluting it.

What i’m not sure is, for automations, how reliable is it to compare now() against alarm. I ask this becasue as soon as the alarm is reached, then the sensor will update the value to the next occurence in that same isntant. So potentially alarm will never be equial to now()? I haven’t tried it yet, but that’s what I suspect might happen? Or is it working fine for you?

Thanks!

It’s working for me.
But I have seen people who has had issues with it.

You could just trigger the automation 10 seconds earlier than the time and it should work.

1 Like

honestly you don’t need to do that at all if you want it to fire when the alarm fires just use the time trigger like below

https://www.home-assistant.io/docs/automation/trigger/#sensors-of-datetime-device-class

2 Likes

Spot on, thanks!
And the example from the docs in particular shows precisely the ‘next_alarm’ scenario so it that’s how is meant to be used.

I had the same problem.
I wanted the heating in the bathroom to be set to 25 degrees 30 minutes before my (Android) alarm clock rang.
That way, the bathroom is always nice and warm in the morning when I get up.
I found the solution in another thread and find it extremely simple.
As trigger use:

{{ as_timestamp(states(''sensor.pixel_5_next_alarm'')) - 1800 < as_timestamp(now()) }}
3 Likes

Added a WTH topic, maybe if more people are interested there can be an easier solution.
WTH - Phone Alarm as Automation Trigger

What about the solution 3 posts above yours?

2 Likes

Yaml vs. Gui more or less I guess

Hello,
Until now, I used an input time to activate my alarm clock.
My alarm clock is divided into several parts.
The first at wake-up time which triggers an automation. That’s done and working. :white_check_mark:

The second at a time before the alarm clock which activates my phone charger.:x:

So far I used this code to control loader automation.

template:
  - sensor:
      - name: "Wake Time 1 Pre"
        unique_id: sensor.wake_time_1_pre
        device_class: timestamp 
        state: >
          {% set alarm = today_at(states('input_datetime.wake_time_1')) %}
          {% set offset = 23 if now() >= alarm else -1 %}
          {{ alarm + timedelta(hours=offset) }}

Today I wanted to replaceinput_datetime.wake_time_1 through sensor.oneplus_6t_justin_next_alarm

Which give :

template:
- sensor:
      - name: "Wake Time 1 Pre"
        unique_id: sensor.wake_time_1_pre
        device_class: timestamp 
        state: >
          {% set alarm = today_at(states('sensor.oneplus_6t_justin_next_alarm')) %}
          {% set offset = 23 if now() >= alarm else -1 %}
          {{ alarm + timedelta(hours=offset) }}

Except that this is not working, mysensor.wake_time_1_pre is marked as unavailable.

I don’t quite know what to do right now.

I would also like to add an input to control the time to be removed fromsensor.oneplus_6t_justin_next_alarm, which should allow me in the future to do something adaptive depending on the battery level.

So if you have any ideas to help me.

Thanks

I wish the next alarm sensor had a companion sensor that would tell me when I’ve snoozed an alarm. Right now I have to add heuristics like “is the next alarm in roughly 10 minutes?” to distinguish between snooze and actual next alarm, and this is killing me.

Sleep as Android let’s you distinguish that

That’s nice! Would you mind sharing the steps to use that app / get its data with the Companion app? Thanks in advance.

you dont need to use the companion app, you can just install the sleep as android app and use the webhooks feature or mqtt feature with your server. It can be independent of the app in that case.

Thanks, but I was hoping for something mediated by the Companion app. I don’t have MQTT and I would prefer something that goes over the Home Assistant bus rather than maintain yet another webhook on an ongoing basis. If Sleep as Android supported sending intents to the Companion app, that would be okay.

Thanks either way!

it does support sending intents, check out their docs: Intent API - Sleep as Android

Cool. Thanks.

I did get my alarm to trigger automations, but i like to set multible alarms with about 5 to 15 minutes in between.
I want the lights to turn on when the last alarm goes off.
So is there a way to ad a condition that if there is second alarm in the next 15 minutes it stops?

No the app is unaware of any additional alarms set. It only knows about the next alarm. One at a time.

The app may be unaware of it, but Home Assistant can be made to be…

If you throw a short delay in at the beginning of the actions, you can then poll the entity again to see if there is another alarm within 15 minutes…

alias: Mobile Last Alarm sequence
description: ""
trigger:
  - platform: time
    at: sensor.YOUR_PHONE_next_alarm
condition: []
action:
  - delay: 5
  - variables:
      no_next: "{{ (today_at() + timedelta(days=1)) | string }}"
      alarm: >
        {% set ent = 'sensor.YOUR_PHONE_next_alarm'%}
        {{ no_next if (states(ent) == 'unavailable') else states(ent) }}
  - choose:
      conditions:
        - alias: Check if this is the last alarm for this morning
          condition: template
          value_template: |
            {{ alarm | as_datetime > now() + timedelta(minutes=15) }}
      sequence:
        - service: light.turn_on
          data: {}
          target:
            entity_id: light.bedroom
    default:
      - service: YOUR NORMAL MORNING SERVICES
mode: single

If you need data from the originating alarm you can use one or more or the trigger variable types.

This does not account for an alarm being snoozed though, it only helps you see what the next state of the sensor is.