Trigger Automation with timestamps from file

It is in the format

I grab them from a different app and process the file with Python. I can manipulate the data to any format

Yes, I’m currently using it. Unfortunately, the calculation method used here are not supported.

I don’t know what this implies , weather it(some of the various method) differs “minutes”, in that case you can use a template-sensor to i.e “correct/add”,the outcome of the sensor, from this integration.
If it’s another “unsupported method” , you could ask for a Feature-Request … i have no knowledge in this “topic” in how many different methods is used for this
But i guess it no stranger than request support for a language ( should be easier to add yet another “method” actually )( as i guess the method is “static” per definition )

I’d prefer to do it myself. As they would need to provide more granularity in calculation and it would not be a straightforward.
I don’t know why such a simple trigger is so complex.

I tried to trigger it with template

{{ sensor.date_time == "2024-03-13, 20:00:00" }}

But no luck either.

In Developer Tools you can test your “template” attempts

https://w.ww.home-assistant.io/integrations/template/.
Templating - Home Assistant.
Automation Trigger - Home Assistant.

Here are 3 urls to the documentation, and when i asked in which “format/source” , i mend whether you get a file-state(s) or you write a document, your python-result could be parsed to a template-sensor, but you have to present your “Source” and explain how you want your “integration” to work, i.e “for each datetime in “list” trigger automation”

If Using the file-integration, you need to pass every(incoming) entry into a “list”, or “touch” a file and trigger upon “last-updated” ( unreliable !)
You can’t use the file-integration, to write a txt.file with 10 entries, and use that like you want , changing it ones a day, with new entries

or use this, and call it a service-call

Thanks for the links, this template now works

  - platform: template
    value_template: '{{ now().strftime("%m-%d %H:%M") == "03-01 12:26" }}'

I manipulated all entries in my file to look similar and copied it over to automation.yaml
It looks bad and the file is huge now but at least it works.
I will try to figure it out with the file sensor or a python script and I will post the solution as well.

If you can make your python to ingest the timestamp(or something) to the file-sensor(at “specific time”, you could either use the last_updated/last changed ( it changes every time the file-content is changed … maybe even at other times :laughing:(not sure which “circumstances” which can causes delays etc, so not so reliable)( or the you use that “last entry” in the file-sensor in an automation/template sensor )
Just remember the “State of the file-sensor Is the last entry only” , so the entries has to be ingested in a synchronized pattern … somehow ( which kind of “move” your automation into the python-file, or what ever ( if you don’t build a list(array) in a “rotating” template-sensor

Right now, it all turning my head upside down, maybe you even can bulk-ingest a series of date-time (meeting entries i the calendar, and use to trigger the automation)

Here is my final solution to create an automation to play azan based on custom prayer times from a csv file.

I created an automation that plays a media file at 4 random time triggers.

- id: '1725198356227'
  alias: newAzan
  description: ''
  trigger:
  - platform: time
    at: '13:12:00'
  - platform: time
    at: '14:52:00'
  - platform: time
    at: '15:47:00'
  - platform: time
    at: '16:17:00'
  condition: []
  action:
  - action: media_player.play_media
    target:
      entity_id: media_player.living_room_speaker
    data:
      media_content_id: media-source://media_source/local/azan.mp3
      media_content_type: audio/mpeg
    metadata:
      title: azan.mp3
      thumbnail:
      media_class: music
      children_media_class:
      navigateIds:
      - {}
      - media_content_type: app
        media_content_id: media-source://media_source
  mode: single

Then I created a python script that modify this automation based on today’s date from a csv file and placed it in python_scripts folder

import csv
import datetime

today_str = datetime.datetime.now().strftime('%m-%d')
with open('/config/python_scripts/calender.csv', 'r', encoding='utf-8-sig') as file:
    reader = csv.DictReader(file)
    for row in reader:
        if row['Date'] == today_str:
            dhuhrTime = row['Dhuhr']
            asrTime = row['Asr']
            maghribTime = row['Maghrib']
            ishaTime = row['Isha']
autoFile =  open('/config/automations.yaml', 'r', encoding="utf8")
autoString = autoFile.read()
autoFile.close()

startIdx = autoString.find('alias: newAzan')
oldString = autoString[startIdx+48:startIdx+48+148]
newString = f"platform: time\n    at: '{dhuhrTime}:00'\n  - platform: time\n    at: '{asrTime}:00'\n  - platform: time\n    at: '{maghribTime}:00'\n  - platform: time\n    at: '{ishaTime}:00'\n"
newAutoString = autoString.replace(oldString, newString)

autoFile = open("/config/automations.yaml", "w", encoding='utf-8-sig')
autoFile.write(newAutoString)
autoFile.close()

unfortunately you cannot run this as python script directly because of the imports, so I created a shell command to run it in the configuration.yaml file.

shell_command:
  updateazan: python3 /config/python_scripts/azan.py

and finally made a second automation to run the shell command every day at midnight to update the azan call times

- id: '1725199442128'
  alias: updateAzan
  description: ''
  trigger:
  - platform: time
    at: '00:01:00'
  condition: []
  action:
  - action: shell_command.updateazan
    data: {}
  mode: single

I added a second action to the last automation to reload yaml filers to load the updated automations.yaml but I’m not sure if it is needed or not

- action: homeassistant.reload_all