Rest API calls no longer update

https://www.muis.gov.sg/api/pagecontentapi/GetPrayerTime?”

like this?

Yes, and if that doesn’t work and you truely need todays date, you can use a resource_template

https://www.muis.gov.sg/api/pagecontentapi/GetPrayerTime?v={{ now().timestamp() | int }}

full config…

- platform: rest
  name: solat
  resource_template: >
    https://www.muis.gov.sg/api/pagecontentapi/GetPrayerTime?v={{ now().timestamp() | int }}
  scan_interval: 21600
  json_attributes:
    - Subuh
    - Syuruk
    - Zohor
    - Asar
    - Maghrib
    - Isyak
1 Like

Interesting, would a resource template be generating random numbers at the end of “?”

or it is doing something else entirely?

I will try using https://www.muis.gov.sg/api/pagecontentapi/GetPrayerTime?
and update tomorrow if it refreshes the data correctly.

the template uses the current seconds from the beginning of time as the value, so it’ll always be unique

That sounds perfect. I will try it and update here. thanks again Pedro!!

Hi all, I can confirm that it works.

Use the resource template.

1 Like

Update:
Unfortunately, the data did not refresh the next day.

I manage to get it to work using the codes above. Its been 3 days, so far so good.

  - platform: rest
    name: solat_muis
    scan_interval: 7200
    resource_template: "https://www.muis.gov.sg/api/pagecontentapi/GetPrayerTime?v={{ now().timestamp() | int }}"
    json_attributes:
      - PrayerDate
      - Hijri
      - Subuh
      - Syuruk
      - Zohor
      - Asar
      - Maghrib
      - Isyak

Sounds great, let me implement this and update if a need arises.

You already implemented this if you copied what I wrote well above his reply…

In that case, I can confirm that it didnt work beyond 2 days (for me). YMMV

May i know if it’s still working for you?

Yes the codes still work for me.

Can share your full codes for this please

sensor:
  - platform: rest
    name: solat_muis
    scan_interval: 7200
    resource_template: "https://www.muis.gov.sg/api/pagecontentapi/GetPrayerTime?v={{ now().timestamp() | int }}"
    json_attributes:
      - PrayerDate
      - Hijri
      - Subuh
      - Syuruk
      - Zohor
      - Asar
      - Maghrib
      - Isyak


  - platform: template
    sensors:
      solat_subuh:
          friendly_name: "Subuh"
          device_class: timestamp
          icon_template: mdi:star-crescent
          value_template: >-          
            {%if is_state('select.solat_source', 'MUIS')%}{{ as_timestamp(strptime(now().date() ~ " " ~ state_attr('sensor.solat_MUIS', 'Subuh'), '%Y-%m-%d %H:%M')) | timestamp_local }}
            {%elif is_state("select.solat_source", "Islamic Prayer Times")%}{{ states('sensor.islamic_prayer_times_fajr_prayer') }}  
            {%endif%}

I have dropdown to choose source of the prayer times. Hence the if and elif. But you can see the codes under MUIS on how i extracted the value from the json.

1 Like

somehow resource_template always breaks for me

so i did thru curl if anyone else want to use this same effect

sensor:
  - platform: command_line
    name: Muis Prayer Times
    command: curl -s "https://www.muis.gov.sg/api/pagecontentapi/GetPrayerTime?v=$(date +%s)"
    scan_interval: 1000  # Update every 24 hours
    json_attributes:
      - PrayerDate
      - Hijri
      - Subuh
      - Syuruk
      - Zohor
      - Asar
      - Maghrib
      - Isyak


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