Assistance with Datetime Sensor not Triggering Automation

Hello,

I have an automation (below) that is not triggering although it was working great until the middle of last month.

trigger:
  - platform: time
    at: sensor.three_days_until_shabbat_yom_tov

there are no conditions for the automation and the sensor returns as follows:

2024-05-14 23:46:00+00:00

Based on that sensor the automation should have triggered yesterday (5/14) at 11:46 pm but it didn’t. Is the sensor in the wrong format?

Thank you in advance for the help,

What is the device class of the sensor?

Look in Developer Tools → States (right hand column for the entity).

It must be device_class: timestamp

I think that it is a string although I have tried to convert it to Datetime and I thought I was successful.

  - sensor:
    - name: Three days Until Shabbat/Yom Tov
      unique_id: three_days_until_Shabbat_yom_tov
      state: "{{ states('sensor.jewish_calendar_upcoming_candle_lighting_3')|as_datetime - timedelta(hours = 72) }}"
      

Please let me know if you need more information.


Nope I can not see the right hand column as I asked.

However, yes your configuration is missing the device class. Add this

- sensor:
    - name: Three days Until Shabbat/Yom Tov
      unique_id: three_days_until_Shabbat_yom_tov
      devcie_class: timestamp
      state: "{{ states('sensor.jewish_calendar_upcoming_candle_lighting_3')|as_datetime - timedelta(hours = 72) }}"

I’m surprised it ever worked, the trigger docs have always said this:

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

1 Like

Thank you, I added that to the Yaml. I will need to wait and see if it works.
So that I have a better understanding, is that what you were asking for?

No, the “Attributes” column to the right of the “State” column.

it doesn’t seems to be displaying on my app. I will try the desktop version later. Thanks! I will be able to mark your a response as a solution tomorrow.

Not even if you rotate your phone to landscape mode?

I have attached a photo in landscape, it also plays a double role in this post since the automation didn’t trigger. I made a new sensor which is nearly identical to the one above except that I have the time offset by a different amount.

  - sensor:
    - name: Two days Until Shabbat/Yom Tov
      unique_id: two_days_until_Shabbat_yom_tov
      device_class: timestamp
      state: "{{ states('sensor.jewish_calendar_upcoming_candle_lighting_3')|as_datetime - timedelta(hours = 48) - timedelta(minutes = 1) }}"
      

the trigger is the same as above but with the new sensor

alias: testing device class
description: ""
trigger:
  - platform: time
    at: sensor.two_days_until_shabbat_yom_tov
condition: []
action:
  - service: notify.mobile_app_pixel_5
    metadata: {}
    data:
      message: "it worked! "
mode: single

I noticed adding the timestamp device class changed the format of the entity (it now has the “T” in it) so it did go into effect. Any thoughts on why this isn’t triggering?

Check your system time. I see a lot of wildly different times here:

Also note that’s 23:45 UTC (GMT). What timezone are you in?

That makes a lot of things make sense. I am on EST

I had a sensor trigger so the device class made everyone work! @tom_l Thank you for the help!