Scraping shows no value

Thank you for sharing. (logbook filters)
I have not come across it before.

In regards to the praying times, there is a 24 hour format provided by this website,
an affiliate of MUIS.
However, I did not successfully manage to retrieve/scrape the timings from that website.

How do we know whether the 12 hour format praying times are for AM or PM:
I would say it’s because of the arrangement and the meaning of the prayers.
Subuh means dawn
Syuruk means sunrise
etc

Ah! I misunderstood and assumed these names to be city names with every city each own local time for a prayer…
OK, so these names are the six prayers to be done each day at the given time, and these are all always either in the morning or in the afternoon?
If so, then this might be a solution:

sensor:
  - platform: rest
    name: Singapore Prayer times
    resource: https://www.muis.gov.sg/api/pagecontentapi/GetPrayerTime
    scan_interval: 28800
    json_attributes:
      - Subuh
      - Syuruk
      - Zohor
      - Asar
      - Maghrib
      - Isyak

template:
  - sensor:
      - name: Subuh praying time
        state: "{{ as_timestamp(strptime(state_attr('sensor.singapore_prayer_times', 'Subuh')~' AM', '%I:%M %p')) | timestamp_custom('%H:%M') }}"
      - name: Isyak praying time
        state: "{{ as_timestamp(strptime(state_attr('sensor.singapore_prayer_times', 'Isyak')~' PM', '%I:%M %p')) | timestamp_custom('%H:%M') }}"

Like this you can create template sensors for each prayer with the correct AM or PM code.
What this template does is:

  1. it reads the 12-hour time as a string from the rest sensor
  2. it adds either “ AM” or “ PM” to complete the 12-hour string format
  3. it converts this 12-hour format string to a timestamp
  4. it converts that timestamp into a 24-hour format
1 Like

Thank you, you’re awesome!!

I will be trying these out. I would love to learn more about this, do you have notes/documentation for the template you just created?

(just to correct you, it’s five prayer times)
“Syuruk” indicates to us humans that the time period to perform the subuh period at its appropriate time has ended.

I do have some documentation sources that I collected (see below), but I learned, and still do learn, the most from trying to understand code that is posted in this community by others.

Some applicable coding sources:
HA Templating
HA Template integration
Jinja Template Designer Documentation
Expressions
Python - datetime — Basic date and time types

1 Like

Hello guys, great solution by the way. it works in getting the prayer times, but the timing that i get is from 29 Dec 2023

sensor:
  - platform: rest
    name: Singapore Prayer times
    resource: "https://www.muis.gov.sg/api/pagecontentapi/GetPrayerTime?v={{ as_timestamp(now()) | int }}"
    scan_interval: 28800
    json_attributes:
      - Subuh
      - Syuruk
      - Zohor
      - Asar
      - Maghrib
      - Isyak
      - PrayerDate
      - Hijri

template:
  - sensor:
      - name: Zuhur praying time
        state: "{{ strptime(state_attr('sensor.singapore_prayer_times', 'Zohor')~' PM', '%I:%M %p').strftime('%H:%M') }}"
  - sensor:
      - name: Subuh praying time
        state: "{{ strptime(state_attr('sensor.singapore_prayer_times', 'Subuh')~' AM', '%I:%M %p').strftime('%H:%M') }}"
  - sensor:
      - name: Syuruk praying time
        state: "{{ strptime(state_attr('sensor.singapore_prayer_times', 'Syuruk')~' AM', '%I:%M %p').strftime('%H:%M') }}"
  - sensor:
      - name: Asar praying time
        state: "{{ strptime(state_attr('sensor.singapore_prayer_times', 'Asar')~' PM', '%I:%M %p').strftime('%H:%M') }}"
  - sensor:
      - name: Maghrib praying time
        state: "{{ strptime(state_attr('sensor.singapore_prayer_times', 'Maghrib')~' PM', '%I:%M %p').strftime('%H:%M')  }}"
  - sensor:
      - name: Isyak praying time
        state: "{{ strptime(state_attr('sensor.singapore_prayer_times', 'Isyak')~' PM', '%I:%M %p').strftime('%H:%M') }}"
  - sensor:
      - name: Prayer Date
        state: "{{ state_attr('sensor.singapore_prayer_times', 'PrayerDate') }}"
  - sensor:
      - name: Hijri Date
        state: "{{ state_attr('sensor.singapore_prayer_times', 'Hijri') }}"
  - sensor: 
      - name: Time Now
        state: '{{ now().strftime("%H:%M") }}'

This is working

Hi,

I tried adding the code you indicated above to my configurations.yaml file but can’t seem to get an output on either the Template Editor or a new sensor entity.

Does the above still work on your end? Did the API url for the prayer times change?

The Islamic Prayer Times integration is not accurate (1-3mins offset) so I would really appreciate any help on this matter.

Thank you for looking in this, looking forward to your response. Ramadan Kareem.

Eid Mubarakw, apologies on getting to this later than expected. The month was full of bustlings on my end.

The website underwent changes in calling their API to fetch the prayer times. It no longers fetches the timing on a daily basis.

However, we do have a workaround that provide the prayer times that the website calls to as well.

Also, apologies in advance as I am not near a computer at the moment. I shall reply now before i miss responding to you.

Using REST,

1 Like

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