What is the best way to play media when reading times from json file

I have a REST API, which provides me with different times. You can have a look at this

http://apps.sherazlodhi.com/ramadantimings.json

I want to be able to read this json file, find the times for today and then when a specific time comes like (“Imsak(AM)”: “3:58”) I want to play media on google home at 3:58 or 10 minutes before this time.

Are you able to define your project in a bit more detail? Maybe provide some examples?
It’s a bit vague at the moment

thanks for replying, I have updated it with an example. I hope its clear now

ok, that helps a lot.
if I understand well, you want to look for the Imsak(AM) time for the date matching today and have an announcement at that specific time, right?
I’m not at home so can’t test, but I’d have an automation that runs every min, with a conditions that goes through the list of entries using a for loop, something like:

{% for RamadanDate in states.sensor.ramadanjson.state %}
{%- if
(RamadanDate["Greg"].split("/")[0] | int) == (as_timestamp(now()) | timestamp_custom("%m") | int) and
(RamadanDate["Greg"].split("/")[1] | int) == (as_timestamp(now()) | timestamp_custom("%d") | int) and
(RamadanDate["Greg"].split("/")[2] | int) == (as_timestamp(now()) | timestamp_custom("%Y") | int) and
(RamadanDate["Imsak(AM)"].split(":")[0] | int) == (as_timestamp(now()) | timestamp_custom("%H") | int) and
(RamadanDate["Imsak(AM)"].split(":")[1] | int) == (as_timestamp(now()) | timestamp_custom("%M") | int)
-%}
True
{%- endif -%}

Again Bear in mind I’m not at home so haven’t tested this, but hopefully it gives you something to start playing with.
Now for the full automation, assuming above works:

- alias: Ramadan Announce
  trigger:
    - platform: time
      minutes: '/1'
      seconds: 0
  condition:
    - condition: template
      value_template: >-
        {% for RamadanDate in states.sensor.ramadanjson.state %}
        {%- if
        (RamadanDate["Greg"].split("/")[0] | int) == (as_timestamp(now()) | timestamp_custom("%m") | int) and
        (RamadanDate["Greg"].split("/")[1] | int) == (as_timestamp(now()) | timestamp_custom("%d") | int) and
        (RamadanDate["Greg"].split("/")[2] | int) == (as_timestamp(now()) | timestamp_custom("%Y") | int) and
        (RamadanDate["Imsak(AM)"].split(":")[0] | int) == (as_timestamp(now()) | timestamp_custom("%H") | int) and
        (RamadanDate["Imsak(AM)"].split(":")[1] | int) == (as_timestamp(now()) | timestamp_custom("%M") | int)
        -%}
        True
        {%- endif -%}
  action:
    - service: tts.google_say
      data_template:
        entity_id: media_player.google_mini
        message: "Ramadan Imsak Time"

If you’re interested in an afternoon time, be sure to add +12 to the time read from your sensor.
If you want a 10 min reminder, simply subtract 10 min to the now minutes time in the condition. I would personally add a separate automation for the 10 min reminder else it will become quite complicated…

Hope it helps.

1 Like

maybe stupid, but make sure you rename ramadanjson to match the name of your actual sensor and rename media_player.google_mini to be the name of your actual google home device :wink:

wow, great. Thanks a lot for putting effort. Really thankful.

It helps a lot.