How to use next alarm sensor

The docs are always a good place to start :wink:

Thank you :slight_smile: I try with UI and forgot to check the doc.

Everything works, but nxt alarm sensor is reporting GMT time, while here in Italy we are now GMT+1.
Time on my mobile is correct, but if I set next alarm at 7a.m., next alarm sensor shows it at 6a.m.
Is there a setting somewhere about this?

check that your alarm app has the correct time zone set…we dont do any data manipulation…whatever android sends to us we send back.

What is the state?
My phone report in zulu time as the start and local time in attribute.

Oh… And is it just me that get the very strange text in the app now.
I have it set to english but pretty much every othwr line is in swedish

change the language in App Configuration as well. By default it sticks to device language and it is separate from HA front end as its part of Android.

Also what app are you using that makes it report package: unknown?

here is mine

      friendly_name: "Minutes until Next Alarm Stephan"
      unit_of_measurement: "m"
      value_template: >-
        {% set dummy = states("sensor.time") %}
        {{((states('sensor.stephan_phone_next_alarm')|as_timestamp|int - now()|as_timestamp|int)/60)|int}}
      availability_template: "{{ not is_state('sensor.stephan_phone_next_alarm','unavailable') }}"
        time: "{{ state_attr('sensor.stephan_phone_next_alarm','Local Time') }}"

then i have this automation

- id: '85cf493e-b8eb-4a8b-8645-b384b752d0fd'
  alias: My Phone Alarm about to go off
  description: ''
  - platform: numeric_state
    entity_id: sensor.minutes_next_alarm_stephan
    below: '2'
  - condition: state
    state: 'off'
  - data:
      entity_id: switch.kettle_power
    service: switch.turn_on
  - delay: '00:00:50'  
  - data:
      entity_id: light.his_side
    service: light.turn_on
  - choose:
      - conditions:
          - condition: state
            entity_id: sensor.day_night
            state: 'Night'
          - service: light.turn_on
  mode: single

hope this helps

1 Like

I’m only talking about app language.

I use the stock alarm app on my phone. Don’t know much more than that :confused:

Timezone is correct, it’s the alarm that I use everyday.
I’ll do some more tests later.
Before going to bed alarm was showing 1 hour in advance, but this morning it was correct.

I guess we will still have to use a template if we want the next alarm time +/- ?
I tried offset: "-00:30:00" like the sun trigger but that didn’t work.

I think next_alarm sensor is not working well, at least on my Xiaomi MI9T Pro.

If I set alarm at 15:00, sensor shows 14:45
if I set 15:20, it shows 15:05
if I set 15:30, it shows 15:15
if I set 16:00, it shows 15:00
if I set 17:00, it shows 16:00

I can’t understand it

1 Like

now I set again 15:00, and it’s correctly showing 15:00
but also setting 16:00 shows 15:00

Search the forum, users who use xiaomi apps have the same issue. My recommendation stays the same, use another app that makes better use of the API.

Ah ok… you mean another alarm-clock app?

Mmm… ok, I saw that other have the exact same problem.
I installed google clock app, but I see that Companion app is still using com.xiaomi.calendar package.
I can put the google package in white list, but how can I tell it to not use the one from xiaomi?

by creating an allow list we only send states from the package you requested. As the API is only capable of providing the next scheduled alarm you will need to wait for that schedule to change in order to get the correct state.

I tried this, seems lika a good clean approach. There are some quirks that mess it up for testing, but in real life it might work OK.

But, i seem to run into that the alarm is moved from the app before HA gets around to triggering it. I ususally use flight mode so that should again work for real life, but still a bit fudged…

Hi @myle

Thanks for your template.

I am trying to add 5 mins to the next alarm in minutes but I am not getting the right value with the 5 minutes added. Here is my code:

{% set dummy = states("sensor.time") %}
        {{((states('sensor.sm_g986b_next_alarm')|as_timestamp|int - now()|as_timestamp|int)/60)|int + now()|as_timestamp|int +5|int}}
      availability_template: "{{ not is_state('sensor.sensor.sm_g986b_next_alarm','unavailable') }}"

Can you please help?


Off top of head not in fron of computer as does not know what 5 is so

Try now.timedelta(0,5)

1 Like

I’ve the sensor working. But I want it to turn on the thermostat. Automation doesn’t get triggered. I didn’t use a condition but that’s not really needed for now. It should work, but it doesn’t.


  - platform: fitbit
    clock_format: 24H
      - "body/weight"
      - "activities/steps"
      - "activities/heart"
      - "sleep/minutesAsleep"

  - platform: template
        friendly_name: "Minutes until Next Alarm Stefan"
        unit_of_measurement: "m"
        value_template: >-
          {% set dummy = states("sensor.time") %}
          {{((states('sensor.pixel5_next_alarm')|as_timestamp|int - now()|as_timestamp|int)/60)|int}}
        availability_template: "{{ not is_state('sensor.pixel5_next_alarm','unavailable') }}"
          time: "{{ state_attr('sensor.pixel5_next_alarm','Local Time') }}"
        device_class: timestamp

By the way, take a look at device_class I added there. Without it, no way the sensor would become available in Ha; One of the few things I hate about HA, nothing about that in the official documentation or on the forum, somebody on the Discord told it to me. After looking around for ages why it wouldn’t work. By the way, the official code also doesn’t work as it’s timestamp it requires UTC input and I’m on GMT +1. I’ve a very hard time understanding why that code exists officially and it simply doesn’t work. It should work and be as easy as that by the way, but it isn’t. Oh boy no, why do something in 5 minutes as 5 hours is better …

this code doesn’t work

  - trigger:
      platform: time
      at: sensor.phone_next_alarm
      service: light.turn_on
      entity_id: light.bedroom

on with the automation that won’t trigger, shall we?

- id: '1609284651176'
  alias: Turn on heat 1 hour before wake-up
  description: ''
  - platform: numeric_state
    entity_id: sensor.minutes_next_alarm_stefan
    below: '60'
  condition: []
  - device_id: 91d0ff446acba47608bbe4119dfe616e
    domain: climate
    entity_id: climate.thermostat
    type: set_preset_mode
    preset_mode: home
  mode: single

In the log file, I don’t see the automation being triggered.
It only says sensor.minutes_next_alarm_stefan became unavailable (which goes rather fast, I suspect HA doesn’t have the time to trigger the automation, or have I done something stupid?

Any help would be greatly appreciated. As someone who works at unregular hours, this automation is a life and euro saver and one of the few that are really the reason why I started with HA, otherwise I could just have stayed with Google Routines.

What official code?
If you’re talking about the template sensor you have there then that is a copy of another members code. That is not official (perhaps say thank you?).
If you need it in a different timezone then just add the time you need


No… because your phone is called pixel5, not phone. So sensor.pixel5_next_alarm I assume.

You said before that this entity does not work (sensor.minutes_next_alarm_stefan). Does it work now? Or are you trying to code an automation to a entity that does not work.