Skip to content

Instantly share code, notes, and snippets.

@OJ7
Last active September 14, 2021 17:56
Show Gist options
  • Save OJ7/5de90d58b31600f6f814b0dfe0aca7b6 to your computer and use it in GitHub Desktop.
Save OJ7/5de90d58b31600f6f814b0dfe0aca7b6 to your computer and use it in GitHub Desktop.
Home Assistant Islamic Prayer Times
import json
from datetime import datetime, timedelta
try:
from urllib.request import Request, urlopen # Python 3
except ImportError:
from urllib2 import Request, urlopen # Python 2
def convertTime(salatTime, offset):
salatTime = datetime.strptime(salatTime, '%I:%M %p')
salatTime = salatTime + timedelta(hours=0, minutes=offset)
salatTime = datetime.strftime(salatTime, '%H:%M')
return salatTime
location = "baltimore,md"
apiKey = "1383220a5e440a4e2b47623ddde2b6fa91" # http://muslimsalat.com/api/#key
url = "http://muslimsalat.com/" + location + "/daily.json?key=" + apiKey
req = Request(url)
req.add_header('Accept', 'application/json')
req.add_header('Content-Type', 'application/json')
response = urlopen(req).read().decode('utf-8')
jsonString = json.loads(response)
times = jsonString['items'][0]
fajr = convertTime(times['fajr'], 0)
dhuhr = convertTime(times['dhuhr'], 0)
asr = convertTime(times['asr'], 0)
maghrib = convertTime(times['maghrib'], -5)
isha = convertTime(times['isha'], 0)
print (fajr)
print (dhuhr)
print (asr)
print (maghrib)
print (isha)
# 05:14
# 13:07
# 16:48
# 19:43
# 21:00
DOMAIN = 'salat_times'
def setup(hass, config):
hass.states.set('salat.fajr', fajr)
hass.states.set('salat.dhuhr', dhuhr)
hass.states.set('salat.asr', asr)
hass.states.set('salat.maghrib', maghrib)
hass.states.set('salat.isha', isha)
return True
@Alshukaily
Copy link

Salamalykum brother,
I just started using home assistant and I couldn't follow what's new and what is old so goes for adding the integration from home the UI, but I found the calculation methods missing Oman as times are different and I didn't know how to edit them. I have opened a feature request at this link https://community.home-assistant.io/t/please-add-oman-prayer-claculation-method-in-islamic-prayer-times/338650 if you could help me.
And I will be honoerd to give you any help or additional information I can get.

Thank you very much.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment