Automation time trigger doesn't work with a timestamp sensor

Hello,
I am trying to make a pretty basic automation that turns on a bedroom light when my phone’s alarm goes off.

I have the home assistant app so this alarm information is automatically given to home assistant via the sensor.jonathan_next_alarm sensor

I then have an automation that refers to this.

In my automation, I have this as my trigger:

- alias: Jonathan Nightstand Alarm Light
  initial_state: 'on'
  trigger:
    - platform: time
      at: sensor.jonathan_next_alarm

However, the automation is never triggered. There are no automation errors, but it never triggers the automation and in the logbook it also shows nothing.

I saw some posts that suggested your timestamp must have the time zone, which mine does.

Any idea why this doesn’t work?

1 Like

Had to do it different way

I created a sensor that look and the Mins to next alarm

    - unique_id: c6e3e245-8c1a-4859-a5a0-4379c2d5d1c8
      name: "Next Alarm Stephan: Minutes"
      unit_of_measurement: "m"
      state: >-
        {% set dummy = states("sensor.time") %}
        {{((states('sensor.sm_g986b_next_alarm')|as_timestamp|int - now()|as_timestamp|int)/60)|int}}
      availability: "{{ not is_state('sensor.sm_g986b_next_alarm','unavailable') }}"
        

then have this as a trigger

- id: "85cf493e-b8eb-4a8b-8645-b384b752d0fd"
  alias: My Phone Alarm about to go off
  description: ""
  trigger:
    - platform: numeric_state
      entity_id: sensor.next_alarm_stephan_minutes
      below: "2"

which turn on my kettle

  action:
    - data:
        entity_id: switch.kettle_power
      service: switch.turn_on

plus has some delays on it

   - delay: "00:15:00"
    - service: tts.google_say
      data:
        entity_id: media_player.livingdisplay
        message: "Hay.. Take some vitamin C Please"
2 Likes

Wow, I’m shocked this isn’t a trivial task.

Thanks for the reply. While you were writing it, I spent 30 minutes messing around in templates and found another hack to make it work. Basically it just does a string compare of 2 date stamps to see if they’re equal. This is not very elegant, but it is working…

trigger:
    - platform: template
      value_template: "{{ (as_timestamp((now() + timedelta( seconds=30)))|timestamp_custom('%Y-%m-%d %H:%M', false)) == (as_timestamp(states.sensor.jonathan_next_alarm.state) | timestamp_custom('%Y-%m-%d %H:%M', false)) }}"
      for: "00:00:10"

I add 30 second offset because once the alarm triggers, the app immediately updates it to the next alarm, which seemed to get dropped by home assistant in my testing. Also, when i tried 10 seconds, it wasn’t reliably evaluating true to trigger the automation. So i chose 30 seconds, and then added a 10 second delay with the for condition.

I’m shocked this isn’t a simple thing to do…

That’s thinking out side the box like it bro