← Back to API Docs
🏠Home Assistant Integration
Integrate prayer times into your smart home with Home Assistant RESTful sensors.
Overview
This guide shows how to set up prayer time sensors in Home Assistant using the PrayCalendar JSON API. You can use these sensors to:
- Display prayer times on your Home Assistant dashboard
- Send notifications when it's time to pray
- Automate lights, speakers, or other devices before prayer times
- Show countdown to next prayer
1. Basic Sensor Setup
Add the following to your configuration.yaml:
rest:
- resource: "https://pray.ahmedelywa.com/api/prayer-times.json?address=Cairo,Egypt&method=5"
scan_interval: 3600
sensor:
- name: "Prayer Times"
value_template: "{{ value_json.nextPrayer.name }}"
json_attributes:
- timings
- nextPrayer
- date
- name: "Next Prayer"
value_template: "{{ value_json.nextPrayer.name }}"
json_attributes_path: "$.nextPrayer"
json_attributes:
- time
- minutesUntil
- name: "Fajr Time"
value_template: "{{ value_json.timings.Fajr }}"
- name: "Dhuhr Time"
value_template: "{{ value_json.timings.Dhuhr }}"
- name: "Asr Time"
value_template: "{{ value_json.timings.Asr }}"
- name: "Maghrib Time"
value_template: "{{ value_json.timings.Maghrib }}"
- name: "Isha Time"
value_template: "{{ value_json.timings.Isha }}"Replace Cairo,Egypt with your city and method=5 with your preferred calculation method.
2. Dashboard Card
Add an Entities card to your Lovelace dashboard:
type: entities
title: Prayer Times
entities:
- entity: sensor.next_prayer
name: Next Prayer
icon: mdi:mosque
- entity: sensor.fajr_time
name: Fajr
icon: mdi:weather-night
- entity: sensor.dhuhr_time
name: Dhuhr
icon: mdi:white-balance-sunny
- entity: sensor.asr_time
name: Asr
icon: mdi:weather-sunset
- entity: sensor.maghrib_time
name: Maghrib
icon: mdi:weather-sunset-down
- entity: sensor.isha_time
name: Isha
icon: mdi:moon-waning-crescent3. Prayer Time Notifications
Create an automation to send mobile notifications at prayer times:
automation:
- alias: "Prayer Time Notification"
trigger:
- platform: template
value_template: >
{{ now().strftime('%H:%M') == states('sensor.fajr_time') }}
- platform: template
value_template: >
{{ now().strftime('%H:%M') == states('sensor.dhuhr_time') }}
- platform: template
value_template: >
{{ now().strftime('%H:%M') == states('sensor.asr_time') }}
- platform: template
value_template: >
{{ now().strftime('%H:%M') == states('sensor.maghrib_time') }}
- platform: template
value_template: >
{{ now().strftime('%H:%M') == states('sensor.isha_time') }}
action:
- service: notify.mobile_app_your_phone
data:
title: "Prayer Time"
message: "It's time for {{ states('sensor.next_prayer') }} prayer"Replace mobile_app_your_phone with your actual mobile app notify service.
4. Advanced: Pre-Prayer Automation
Use the minutesUntil attribute to trigger actions before prayer time:
automation:
- alias: "Pre-Prayer Reminder"
trigger:
- platform: template
value_template: >
{{ state_attr('sensor.next_prayer', 'minutesUntil') | int == 15 }}
action:
- service: light.turn_on
target:
entity_id: light.prayer_room
data:
brightness_pct: 100
color_temp_kelvin: 4000
- service: tts.speak
target:
entity_id: tts.google_translate_say
data:
message: "{{ states('sensor.next_prayer') }} prayer in 15 minutes"Tips
- Use
format=webhookfor detailed timing data including ISO timestamps and Unix timestamps. - The API refreshes every hour (
scan_interval: 3600). Adjust as needed, but avoid polling too frequently. - Add
qibla=trueto include Qibla direction in the response. - For coordinates-based location, use
latitude=...&longitude=...instead of address. - Check the API Documentation for all available parameters.