Hi,
After working on this for some time, I have managed to find a functional RESTful Sensor setup to provide MUIS Prayer Times for 2025 in 24h format. You should be able to use this for automation purposes. Unfortunately the API URL will need to be updated every year but below is the functional code for Subuh, Syuruk, Zohor, Asar, Maghrib & Isyak Prayer times, each as an individual sensor.
sensor:
- platform: rest
name: "Subuh MUIS"
resource: "https://data.gov.sg/api/action/datastore_search?resource_id=d_e81ea2337599b674c4f645c1af93e0dc&limit=365&fields=Date,Subuh"
value_template: >
{% set today = now().strftime('%Y-%m-%d') %}
{% set tomorrow = (now() + timedelta(days=1)).strftime('%Y-%m-%d') %}
{% set records = value_json.result.records %}
{% set today_row = records | selectattr("Date", "equalto", today) | list %}
{% set tomorrow_row = records | selectattr("Date", "equalto", tomorrow) | list %}
{% if today_row and tomorrow_row %}
{% set t_hour, t_minute = today_row[0].Subuh.split(':') %}
{% set now_total = now().hour * 60 + now().minute %}
{% set prayer_total = (t_hour | int) * 60 + (t_minute | int) %}
{% if now_total < prayer_total %}
{{ today }}T{{ '%02d' % (t_hour | int) }}:{{ '%02d' % (t_minute | int) }}:00
{% else %}
{% set th, tm = tomorrow_row[0].Subuh.split(':') %}
{{ tomorrow }}T{{ '%02d' % (th | int) }}:{{ '%02d' % (tm | int) }}:00
{% endif %}
{% else %}
unknown
{% endif %}
scan_interval: 300
headers:
Accept: application/json
- platform: rest
name: "Syuruk MUIS"
resource: "https://data.gov.sg/api/action/datastore_search?resource_id=d_e81ea2337599b674c4f645c1af93e0dc&limit=365&fields=Date,Subuh"
value_template: >
{% set today = now().strftime('%Y-%m-%d') %}
{% set tomorrow = (now() + timedelta(days=1)).strftime('%Y-%m-%d') %}
{% set records = value_json.result.records %}
{% set today_row = records | selectattr("Date", "equalto", today) | list %}
{% set tomorrow_row = records | selectattr("Date", "equalto", tomorrow) | list %}
{% if today_row and tomorrow_row %}
{% set t_hour, t_minute = today_row[0].Syuruk.split(':') %}
{% set now_total = now().hour * 60 + now().minute %}
{% set prayer_total = (t_hour | int) * 60 + (t_minute | int) %}
{% if now_total < prayer_total %}
{{ today }}T{{ '%02d' % (t_hour | int) }}:{{ '%02d' % (t_minute | int) }}:00
{% else %}
{% set th, tm = tomorrow_row[0].Syuruk.split(':') %}
{{ tomorrow }}T{{ '%02d' % (th | int) }}:{{ '%02d' % (tm | int) }}:00
{% endif %}
{% else %}
unknown
{% endif %}
scan_interval: 300
headers:
Accept: application/json
- platform: rest
name: "Zohor MUIS"
resource: "https://data.gov.sg/api/action/datastore_search?resource_id=d_e81ea2337599b674c4f645c1af93e0dc&limit=365&fields=Date,Zohor"
value_template: >
{% set today = now().strftime('%Y-%m-%d') %}
{% set tomorrow = (now() + timedelta(days=1)).strftime('%Y-%m-%d') %}
{% set records = value_json.result.records %}
{% set today_row = records | selectattr("Date", "equalto", today) | list %}
{% set tomorrow_row = records | selectattr("Date", "equalto", tomorrow) | list %}
{% if today_row and tomorrow_row %}
{% set t_hour, t_minute = today_row[0].Zohor.split(':') %}
{% set t_hour = t_hour | int + 12 %}
{% set now_total = now().hour * 60 + now().minute %}
{% set prayer_total = t_hour * 60 + (t_minute | int) %}
{% if now_total < prayer_total %}
{{ today }}T{{ '%02d' % t_hour }}:{{ '%02d' % (t_minute | int) }}:00
{% else %}
{% set th, tm = tomorrow_row[0].Zohor.split(':') %}
{% set th = th | int + 12 %}
{{ tomorrow }}T{{ '%02d' % th }}:{{ '%02d' % (tm | int) }}:00
{% endif %}
{% else %}
unknown
{% endif %}
scan_interval: 300
headers:
Accept: application/json
- platform: rest
name: "Asar MUIS"
resource: "https://data.gov.sg/api/action/datastore_search?resource_id=d_e81ea2337599b674c4f645c1af93e0dc&limit=365&fields=Date,Asar"
value_template: >
{% set today = now().strftime('%Y-%m-%d') %}
{% set tomorrow = (now() + timedelta(days=1)).strftime('%Y-%m-%d') %}
{% set records = value_json.result.records %}
{% set today_row = records | selectattr("Date", "equalto", today) | list %}
{% set tomorrow_row = records | selectattr("Date", "equalto", tomorrow) | list %}
{% if today_row and tomorrow_row %}
{% set t_hour, t_minute = today_row[0].Asar.split(':') %}
{% set t_hour = t_hour | int + 12 %}
{% set now_total = now().hour * 60 + now().minute %}
{% set prayer_total = t_hour * 60 + (t_minute | int) %}
{% if now_total < prayer_total %}
{{ today }}T{{ '%02d' % t_hour }}:{{ '%02d' % (t_minute | int) }}:00
{% else %}
{% set th, tm = tomorrow_row[0].Asar.split(':') %}
{% set th = th | int + 12 %}
{{ tomorrow }}T{{ '%02d' % th }}:{{ '%02d' % (tm | int) }}:00
{% endif %}
{% else %}
unknown
{% endif %}
scan_interval: 300
headers:
Accept: application/json
- platform: rest
name: "Maghrib MUIS"
resource: "https://data.gov.sg/api/action/datastore_search?resource_id=d_e81ea2337599b674c4f645c1af93e0dc&limit=365&fields=Date,Maghrib"
value_template: >
{% set today = now().strftime('%Y-%m-%d') %}
{% set tomorrow = (now() + timedelta(days=1)).strftime('%Y-%m-%d') %}
{% set records = value_json.result.records %}
{% set today_row = records | selectattr("Date", "equalto", today) | list %}
{% set tomorrow_row = records | selectattr("Date", "equalto", tomorrow) | list %}
{% if today_row and tomorrow_row %}
{% set t_hour, t_minute = today_row[0].Maghrib.split(':') %}
{% set t_hour = t_hour | int + 12 %}
{% set now_total = now().hour * 60 + now().minute %}
{% set prayer_total = t_hour * 60 + (t_minute | int) %}
{% if now_total < prayer_total %}
{{ today }}T{{ '%02d' % t_hour }}:{{ '%02d' % (t_minute | int) }}:00
{% else %}
{% set th, tm = tomorrow_row[0].Maghrib.split(':') %}
{% set th = th | int + 12 %}
{{ tomorrow }}T{{ '%02d' % th }}:{{ '%02d' % (tm | int) }}:00
{% endif %}
{% else %}
unknown
{% endif %}
scan_interval: 300
headers:
Accept: application/json
- platform: rest
name: "Isyak MUIS"
resource: "https://data.gov.sg/api/action/datastore_search?resource_id=d_e81ea2337599b674c4f645c1af93e0dc&limit=365&fields=Date,Isyak"
value_template: >
{% set today = now().strftime('%Y-%m-%d') %}
{% set tomorrow = (now() + timedelta(days=1)).strftime('%Y-%m-%d') %}
{% set records = value_json.result.records %}
{% set today_row = records | selectattr("Date", "equalto", today) | list %}
{% set tomorrow_row = records | selectattr("Date", "equalto", tomorrow) | list %}
{% if today_row and tomorrow_row %}
{% set t_hour, t_minute = today_row[0].Isyak.split(':') %}
{% set t_hour = t_hour | int + 12 %}
{% set now_total = now().hour * 60 + now().minute %}
{% set prayer_total = t_hour * 60 + (t_minute | int) %}
{% if now_total < prayer_total %}
{{ today }}T{{ '%02d' % t_hour }}:{{ '%02d' % (t_minute | int) }}:00
{% else %}
{% set th, tm = tomorrow_row[0].Isyak.split(':') %}
{% set th = th | int + 12 %}
{{ tomorrow }}T{{ '%02d' % th }}:{{ '%02d' % (tm | int) }}:00
{% endif %}
{% else %}
unknown
{% endif %}
scan_interval: 300
headers:
Accept: application/json