#Next alarm trigger not working anymore

1 messages · Page 1 of 1 (latest)

thick sable
#

Hello, I have an automation to lift my blinds every morning when the alarm on my phone goes off but it is not working anymore around the same time I got the 2024 update (not sure it is related though)

I am using this trigger template :

{{now().strftime('%a %h %d %H:%M %Z %Y') == (((state_attr('sensor.phone_next_alarm', 'Time in Milliseconds') | int / 1000) ) | timestamp_custom('%a %h %d %H:%M %Z %Y'))}}

I have tried to debug using the template tool in the developer menu :

The first part is working great showing the right formated date time

{{now().strftime('%a %h %d %H:%M %Z %Y')}}

The second part is also working great and showing the right formated date time

{{(((state_attr('sensor.phone_next_alarm', 'Time in Milliseconds') | int / 1000) ) | timestamp_custom('%a %h %d %H:%M %Z %Y'))}}

Apart from when my alarm goes off where it is showing the following error :

ValueError: Template error: int got invalid input 'None' when rendering template '{{(((state_attr('sensor.phone_next_alarm', 'Time in Milliseconds') | int / 1000) ) | timestamp_custom('%a %h %d %H:%M %Z %Y'))}}' but no default was specified

Any idea why this is happening and how to fix it ?

ps : I have also tried using the time -> next alarm trigger instead of the custom template trigger without success

timid blade
#

When next alarm sensor is unavailable, it cannot convert that string to int. You can define a default like int(0)

thick sable
#

Thanks that seems to have fixed the error I had, but the next alarm trigger is still not working unfortunately

timid blade
#

Is an alarm set?

#

And is that sensor enabled in the companion app?

thick sable
#

Yes and I see it set at the right time in HA

#

It worked without any issue for about a month and now, I can see the event in trace only maybe 1 time every 10 tries, it's very inconsistent

timid blade
#

The template seems to work in my dev tools. What to the traces say when the automation fails?

thick sable
#

Nothing, it's like no trigger happened

timid blade
#

Does this work?

{{ now() | as_timestamp(0) | round(0) == states('sensor.phone_next_alarm') | as_timestamp(0) | round(0) }}
thick sable
#

So I have 3 triggers :
-One is using : sensor.phone_next_alarm
-The second : {{now().strftime('%a %h %d %H:%M %Z %Y') == (((state_attr('sensor.phone_next_alarm', 'Time in Milliseconds') | int(0) / 1000) ) | timestamp_custom('%a %h %d %H:%M %Z %Y'))}}
-And the third : {{ now() | as_timestamp(0) | round(0) == states('sensor.phone_next_alarm') | as_timestamp(0) | round(0) }}
But none seem to be working reliably, some are never triggered and other only sometime

#

Would it be possible that another automation interfere with this one ?

timid blade
#

It worked on my test automation.
Well... I would alter the defaults a bit. Just to prevent unwanted triggering.

{{ now() | as_timestamp(1) | round(0) == states('sensor.phone_next_alarm') | as_timestamp(0) | round(0) }}
thick sable
#

It seems to be working from time to time, but not every time, I don't get why sometimes it just doesn't trigger

timid blade
#

And using a time trigger with the sensor.phone_next_alarm isn't reliable too?

  - trigger:
      - platform: time
        at: sensor.phone_next_alarm
thick sable
#

About as much as the other triggers

thick sable
#

I have also posted on reddit and someone may have found the answer, my phone would be running slightly ahead of time in comparison to my HA server, so right before the next alarm trigger is executed on my HA setup it is replaced by the next one, making it never happen

#

That would explain why the triggers were working randomly

timid blade
#

A timedelta might help 🤔

thick sable
#

Using this trigger now : {{ as_timestamp(states('sensor.oneplus_7t_next_alarm')) - 60 < as_timestamp(now()) }}

#

With a minute a delay afterward

timid blade
#

👍

thick sable
#

Thanks a lot for your help !