Event not being triggered

Works fine if triggered manually. But will not trigger at time set. Any help please
The Automation

- id: 'xxxxxxxxxxxxxxx'
  alias: Days to Next Appt
  description: ''
  trigger:
  - platform: time
    at: '17:58:00'
  condition:
  - condition: template
    value_template: '"{{ states.sensor.days_to_next_appt.state | int > 0 and states.sensor.days_to_next_appt.state
      | int < 4 }}"'
  action:
  - service: media_player.volume_set
    data:
      entity_id: media_player.home
      volume_level: 1
  - service: tts.say
    data:
      entity_id: media_player.home
      message: Appointment Reminder.... {{ states.sensor.next_appt_message.state }}
        with {{ states.sensor.next_appt_description.state }} is {{ states.sensor.days_to_next_appt.state
        }}
  mode: single

The Sensors * note all sensors seem to be working *

################# Appontments ####################################

  - platform: template
    sensors:
      next_appt_time:
        friendly_name: "Next Appt Time"
        value_template: "{{ states.calendar.xxxxxxxxxxxx_gmail_com.attributes.start_time | timestamp_custom('%I:%M %p') }}"

  - platform: template
    sensors:
      next_appt_message:
        friendly_name: "Next Appt Type"
        value_template: "{{ states.calendar.xxxxxxxxxxx_gmail_com.attributes.message }}"

  - platform: template
    sensors:
      next_appt_description:
        friendly_name: "Next Appt Description"
        value_template: "{{ states.calendar.xxxxxxxxxxx_gmail_com.attributes.description }}"

  - platform: template
    sensors:
      days_to_next_appt:
        friendly_name: "Days to Next Appt"
        value_template: >
          {% set midnight = now().replace(hour=0, minute=0, second=0, microsecond=0).timestamp() %}
          {% set event = states('sensor.next_appt_date_time') | as_timestamp %}
          {% set int = ((event - midnight) // 86400) | int %}
          {% if int == 0 %}
            0
          {% elif int == 1 %}
            In {{ int }} Day
          {% elif int == 2 %}
            In {{ int }} Days
          {% else %}
            In {{ int }} Days
          {% endif %}

Manually triggered automations will skip all triggers and conditions and go straight to the action section.

So, a few things. Your sensor.days_to_next_appt will only be a number if int ==0. Otherwise, it will say something like “In 2 Days”

      {% if int == 0 %}
        0
      {% elif int == 1 %}
        In {{ int }} Day
      {% elif int == 2 %}
        In {{ int }} Days
      {% else %}
        In {{ int }} Days
      {% endif %}

Meaning states.sensor.days_to_next_appt.state | int will return 0 by default (if no default value is specified, | int will return 0 on failure). The easiest would be get rid of the extra string stuff from that template sensor…but if you really want to keep it, you’re going to have to extract the number from the senor, or calculate it again here.

You also have too many quotes in your value_template. Remove the leading single quote.

Just make your condition template this:

value_template: >
  {% set days = (states('sensor.days_to_next_appt') | regex_findall_index('\d+')) | int %}
  {{ days > 0 and days < 4 }}

Thank you so much.

It looks like this. Can you write the details for me?