Triggering when a time matches a certain string

Hi,

I’m trying to trigger an automation when the current time, with second accuracy, matches a string. Basically, I want something like:

{{ now().strftime("%H:%M:%S")}} == {{ states.sensor.jewish_calendar_plag_hamincha.state }}

where states.sensor.jewish_calendar_plag_hamincha.state is of the format 18:45:23 (or whatever). However, this trigger never fires, which I believe is because now() isn’t actually evaluated all the time. Most of what I’ve seen suggests using something like sun or the date sensor, but those update daily/every minute, and I’d like something to trigger at the matching second.

You won’t be able to get ‘second’ accuracy. You can get minutely accuracy by using sensor.time.

One possible way might be:

trigger:
  platform: time_pattern
  seconds: '/1'
condition:
  condition: template
  value_template: >
    {{ now().strftime("%H:%M:%S") ==
       states('sensor.jewish_calendar_plag_hamincha') }}
action:
 ...

However, depending on your hardware, and the load on HA, it’s always possible for a second to be missed. So you might have to get more creative to handle that case, such as triggering whenever the time is equal to or after the time, and then in the actions, in addition to whatever the automation would normally do, setting an input_boolean, and add a condition so the automation actions only run when the input_boolean is off. Then have another automation that resets the input_boolean after midnight.

Or, just thought of another approach. Create a template binary sensor that evaluates if the time is at or after the calendar sensor. Use an automation that runs every second update the template binary sensor. Then trigger the original automation with the template binary sensor changing to ‘on’.

Thank you both!