#Time trigger not executed for datetime sensor

1 messages · Page 1 of 1 (latest)

normal shore
#

Hello.

I'm creating a 'prayer reminders' package using YAML. I've created a sensor that gets the time for the current prayer, automatically changing it to the next one when the time for the previous lapses:

template:
  - sensor:
      # -- Prayer Current Sensor --
      - name: "Prayer Next"
        unique_id: prayer_current
        device_class: timestamp
        state: >
          ...

My goal is to have a notification sent every time the 'prayer_next' datetime == the current datetime, which happens/updates several times a day.

After reading the docs I setup my test automation is setup as follows, but unfortunately it never executes, whether I wait for the time to actually lapse, or if I manually update the sensor value to a future timestamp in Developer Tools. Can anyone confirm what's going wrong here?

# -- Notification Group --
notify:
  - platform: group
    name: prayer_notifications_group
    services:
      - action: mobile_app_user_1
      - action: mobile_app_user_2

automation:
  - alias: "Notify When Prayer Time"
    description: "Sends a notification when the time is reached for each prayer."
    id: prayer_notify_when_time
    triggers:
      - trigger: time
        at: sensor.prayer_current
    actions:
      - action: notify.prayer_notifications_group
        data:
          title: "Prayer Test"
          message: "Prayer Reminder Test"
jovial veldt
normal shore
#

Sorry that was a mistake which has caused some confusion, the sensor is actually called 'prayer_current', and its value changes as soon as the time for the current prayer has been reached. 'prayer_next' is also present, and also switches at the same moment to contain the next prayer time, but I thought it would be more idiomatic to use 'prayer_current' in the automation

#

But the trigger simply never executes when the current/system time and 'prayer_current' coincide

jovial veldt
#

my point is that you don't need to check the time in the trigger.

if they only change when prayer time has been reached then just trigger off them changing. it doesn't matter what they are changing to. theres no need to compare to current time because this trigger would only happen at prayer time?

#

but if you want to go for the time approach you might have to create an offset so it triggers 5 seconds before or something. because it never actually reaches the same time because as soon as you get to the target time the target time has changed.

normal shore
jovial veldt
#

that will trigger on any change to the entity

normal shore
#

Vaguely remember going down this route before and I think I wanted to switch to the time trigger to try and avoid it. Unfortunately adding an offset of 5 secs to the previous time trigger didn't seem to have any effect

jovial veldt
#

set the trigger attribute to one that only changes at the time

#

e.g.

entity_id:
  - sensor.prayer_current
attribute: prayer_name
#

or prayer_end

#

you are right it was probably triggering on the remaining time updating. so just trigger on the right attribute changing

normal shore
#

Thanks - that looks like it's worked!

#

I'll mark as resolved, but quick sidebar question - is there a way to have it just update an existing notification each time the prayer updates if that notification hasnt dismissed?

#

Not particularly useful to have to dismiss a stack of notifications when only the latest one is of relevance

#

Not sure if this is persistent notifications or another setting

jovial veldt
#

I think there are ways to clear or edit previous notifications in some situations but i have no idea on how to actually do it.

#

next up, get smart speakers playing a call to prayer maybe?

normal shore
#

Did think about that, but I think I'd find it a bit jarring haha (and a bit of a weird one to explain to someone not particularly religious should they come over?!)

jovial veldt
#

yeah that is fair enough. just a random idea. I had in passing

normal shore
#

Thanks for the tip on editing an existing notification managed to figure it out (highlighted) works exactly as intended now, thanks so much for saving me all this troubleshooting time!!

jovial veldt
#

oh thats awesome