Your iPhone fetches today's Fajr time, calculates your two alarms automatically, and sets them every night, no manual updates needed.
During Ramadan, waking up for Suhoor means you need to be up before Fajr, and since prayer times shift by a minute or two every day, manually updating your alarm each night gets old fast.
In this guide, I'll show you how to build a fully automated system on your iPhone that:
- Fetches today's Fajr prayer time from a live API based on your GPS coordinates
- Calculates your wake-up time (30 minutes before Fajr Adhan)
- Automatically sets or updates your alarm every night while you sleep.
We'll use two free apps ( Scriptable and Apple Shortcuts ) and zero paid services.
What You'll Need
- iPhone running iOS 15 or later
- Scriptable - free on the App Store
- Apple Shortcuts - pre-installed on your iPhone
- An internet connection (to fetch prayer times)
How It Works - Big Picture
[Shortcuts Automation triggers at 1:00 AM every night]
β
[Runs your Scriptable script]
β
[Script fetches today's Fajr time from AlAdhan API]
β
[Script calculates and returns 3 timestamps:
β’ Suhoor β Fajr β 30 min (wake up & eat)
β’ Fajr-adhan β Fajr β 10 min (prayer heads-up)
β’ Fajr β exact Fajr time (for reference)]
β
[Shortcuts sets Alarm: π½οΈ Suhoor (30 min before Fajr)]
[Shortcuts sets Alarm: π Fajr-adhan (10 min before Fajr)]
[Shortcuts sets Alarm: π Fajr]
Step 1 - Install Scriptable
Open the App Store and search for Scriptable:
It's completely free. Scriptable lets you write and run JavaScript on your iPhone - perfect for calling APIs and passing data to Apple Shortcuts.
Step 2 - Add the Script in Scriptable
Open Scriptable, tap the + button in the top-right corner to create a new script.
Tap on the new script, then clear any placeholder text and paste the following script:
// ============================================================
// CONFIG - update these values for your location
// ============================================================
const latitude = 45.57; // Your latitude (Montreal)
const longitude = -73.54; // Your longitude (montreal)
const timezone = "America/Toronto"; // Your timezone (tz database format)
const method = 2; // Calculation method (see table in article)
// Minutes before Fajr for each alarm
const SUHOOR_OFFSET = 30; // minutes - π½οΈ Wake up & eat - adjust to taste (e.g. 45 or 60)
const FAJR_ADHAN_OFFSET = 10; // minutes - π Fajr adhan heads-up
// ============================================================
// DATE (DD-MM-YYYY for the API)
// ============================================================
const now = new Date();
const dd = String(now.getDate()).padStart(2, '0');
const mm = String(now.getMonth() + 1).padStart(2, '0');
const yyyy = now.getFullYear();
const dateStr = `${dd}-${mm}-${yyyy}`;
// ============================================================
// FETCH FAJR TIME FROM ALADHAN API
// ============================================================
const url =
`https://api.aladhan.com/v1/timings/${dateStr}` +
`?latitude=${latitude}` +
`&longitude=${longitude}` +
`&timezone=${timezone}` +
`&method=${method}`;
// console.log("Fetching: " + url);
const req = new Request(url);
const res = await req.loadJSON();
const fajrTimeStr = res.data.timings.Fajr;
// console.log("Fajr time today: " + fajrTimeStr);
// ============================================================
// HELPERS
// ============================================================
function timeToDate(timeStr) {
const [h, m] = timeStr.split(":").map(Number);
const d = new Date();
d.setHours(h, m, 0, 0);
return d;
}
function subtractMinutes(date, minutes) {
return new Date(date.getTime() - minutes * 60000);
}
// Local ISO string - no UTC shift, so Shortcuts reads the correct local time
function toLocalISO(date) {
const pad = n => String(n).padStart(2, "0");
return (
date.getFullYear() + "-" +
pad(date.getMonth() + 1) + "-" +
pad(date.getDate()) + "T" +
pad(date.getHours()) + ":" +
pad(date.getMinutes()) + ":00"
);
}
// ============================================================
// BUILD OUTPUT - 3 keys only
// ============================================================
const fajr = timeToDate(fajrTimeStr);
const fajrAdhan = subtractMinutes(fajr, FAJR_ADHAN_OFFSET);
const suhoor = subtractMinutes(fajr, SUHOOR_OFFSET);
const output = {
"Suhoor": toLocalISO(suhoor), // π½οΈ 30 min before Fajr
"Fajr-adhan": toLocalISO(fajrAdhan), // π 10 min before Fajr
"Fajr": toLocalISO(fajr) // exact Fajr time (reference)
};
console.log(JSON.stringify(output, null, 2));
// ============================================================
// RETURN TO SHORTCUTS
// ============================================================
Script.setShortcutOutput(output);
Script.complete();
βοΈ Customize Your Config
At the top of the script, update these four values:
| Variable | What to change |
|---|---|
latitude / longitude
|
Your home coordinates (find them in Maps β long press β copy coordinates) |
timezone |
Your local timezone string (e.g. "Europe/Paris", "Asia/Riyadh") |
method |
Calculation method - see table below |
Common calculation methods:
| Method # | Authority |
|---|---|
| 1 | University of Islamic Sciences, Karachi |
| 2 | Islamic Society of North America (ISNA) |
| 3 | Muslim World League |
| 4 | Umm Al-Qura University, Makkah |
| 5 | Egyptian General Authority of Survey |
You can also tweak the two offset values. If 30 minutes isn't enough time for Suhoor, bump SUHOOR_OFFSET to 45 or 60. If you want the Adhan reminder a little earlier, change FAJR_ADHAN_OFFSET to 15.
Name Your Script
Tap the script title at the top and rename it to RamadanAlarms - you'll reference this exact name in Shortcuts later.
Test It
Tap the βΆ Run button at the bottom. You should see JSON output in the console at the bottom of the screen with three timestamps like this:
If you see an error, double-check your latitude/longitude and that your phone has internet access. If the times look wrong, verify your timezone string.
Step 3 - Prepare Your Clock App
Before the automation runs for the first time, create the placeholder alarms in your Clock app. The automation loop finds each alarm by its label, deletes it, then recreates it with the correct time, so the labels must exist and must match exactly what the loop produces.
Create all three alarms in Clock β Alarm:
- Open Clock β Alarm tab β tap +
- Create alarm, label it
Suhoor- time doesn't matter, it will be overwritten - Repeat for
Fajr-adhan - Repeat for
Fajr
β οΈ Spelling and capitalization must match exactly - no emoji needed, just the plain text labels as shown above.
Step 4 - Build the Shortcuts Automation
Now we'll wire everything together in Apple Shortcuts. Open the Shortcuts app and go to the Automation tab at the bottom.
Create a New Automation
Tap the + button in the top-right to create a new automation.
Choose Time of Day as your trigger.
Set the time to something like 1:00 AM - early enough that it runs before Suhoor, but after midnight so the date is correct when the API is called. Set it to repeat Daily, and make sure Run Immediately (or "Run After Confirmation" if you prefer) is selected.
Tap Next and start adding actions.
Build the Action Flow
You'll now add a series of actions. Here's the complete flow:
Action 1 - Create New Shortcut & Run the Script
Tap Create New Shortcut and search for "Scriptable". Select Run Script.
In the action block:
- Set Script β
RamadanAlarms(the name you gave your script) - Leave Input empty
- Run it to see the resulting output
Action 2 - Get All Keys from the Script Output
Add a Get Dictionary Value action.
-
Get:
All Keys -
Dictionary: tap the
Outputmagic variable from Action 1
This produces a list of all three keys from your script: Suhoor, Fajr-adhan, and Fajr.
Action 3 - Repeat with Each Key
Add a Repeat with each item in action.
-
Input: the
Keysvariable from Action 2
Everything inside this loop (Actions 4β8) will run once for Suhoor, once for Fajr-adhan, and once for Fajr.
Action 4 - Get the Time Value for the Current Key (inside loop)
Add a Get Dictionary Value action inside the loop.
-
Get:
Value -
Key:
Repeat Item(the magic variable - this is the current key name on each pass) -
Dictionary:
Outputfrom Action 1
This retrieves the ISO timestamp string for whichever key is currently being processed.
![]() |
Action 5 β Find the Existing Alarm by Label (inside loop)
Add a Find Alarms action:
-
Filter: Label is
Repeat Item(the magic variable - this is the current key name on each pass). The script keys are already formatted as proper labels, soRepeat Itemdirectly matches the Clock alarm name. - Sort by: Label
- Order: A to Z
- Limit: ON β Get 1 Item
This finds the existing alarm in your Clock app that matches the current label.
![]() |
![]() |
Action 6 β Delete the Old Alarm (inside loop)
Add a Delete Alarms action:
-
Alarms: the
Alarmsresult from Action 5
This removes the old alarm so it can be recreated with today's correct time.
![]() |
![]() |
Action 7 β Create the New Alarm (inside loop)
Add a Create Alarm action:
-
Time:
aTimeβ set this to theDictionary Valuefrom Action 4 (the ISO timestamp) -
Label:
Repeat Item(the magic variable - this is the current key name on each pass)
![]() |
![]() |
![]() |
Action 8 β Show a Notification (inside loop)
Add a Show Notification action:
This fires a confirmation notification for each alarm as it's set.
![]() |
![]() |
Full Automation at a Glance
![]() |
![]() |
Tap Done to save.
Step 5 β Test the Full Flow
Before relying on this for Ramadan, run the automation manually now:
- Go to your automation in the Automation tab
- Tap on it to open it
- Tap Run (or use the play button if available)
Then open Clock β Alarm and confirm all three alarms were updated β Suhoor, Fajr-adhan, and Fajr β showing the correct times for tonight.
How the Prayer Time API Works
The script uses the free AlAdhan API - no account or API key needed. A sample request:
https://api.aladhan.com/v1/timings/19-03-2025
?latitude=45.57
&longitude=-73.54
&timezone=America/Toronto
&method=2
The response contains all five prayer times in your local timezone. The script pulls only Fajr, then subtracts the two offsets to produce three clean ISO timestamps β for example 2025-03-19T04:17:00 β which Shortcuts parses directly into Date objects to set your alarms.
Troubleshooting
Both alarms are wrong by the same amount β Your offset values (SUHOOR_OFFSET, FAJR_ADHAN_OFFSET) are fine β the Fajr time itself is wrong. Double-check your latitude, longitude, and timezone in the script. Run it manually in Scriptable and verify the console output.
Times are off by exactly one hour β Daylight saving time issue. Use a full tz database timezone string like "America/Montreal" instead of "EST". The API handles DST automatically when given the proper timezone name.
"Script not found" error in Shortcuts β The script name is case-sensitive. Make sure it says RamadanAlarms exactly, matching what you named it in Scriptable.
An alarm isn't being found or updated β The loop matches alarms by their label. Make sure your Clock app has alarms named exactly Suhoor, Fajr-adhan, and Fajr β note the hyphen in Fajr-adhan, not a space. The Clock labels must match the script keys exactly.
The automation doesn't run automatically overnight β Go to Settings β Shortcuts and allow automations to run without confirmation. Also make sure Low Power Mode is off, as it can delay or skip background tasks.
Wrapping Up
Once this is running, your phone handles everything silently β every night at 1 AM:
- Fetches today's Fajr time for your exact location
- Calculates all three alarm times (Suhoor, Fajr Adhan, Fajr)
- Loops through each one β deletes the old alarm, creates a fresh one with today's time
Wake up rested, eat a good Suhoor, and focus on what matters. Ramadan Kareem! π
Found this useful? Share it with someone doing Ramadan!
Have questions or improvements? Drop them in the comments














Top comments (0)