Last active
September 14, 2021 17:56
-
-
Save OJ7/5de90d58b31600f6f814b0dfe0aca7b6 to your computer and use it in GitHub Desktop.
Home Assistant Islamic Prayer Times
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
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
Sorry I didn't have notifications enabled and just saw these comments.
@iBasit that is probably a better option (or even getting yearly prayer times) but opted for a quick solution with minimal parsing. :)
@ others I haven't updated my Home Assistant in a while so it may be that parts of this may be outdated. Once I get a chance to update my installation, I will go through and update this tutorial/clean up the code.
I would like to eventually create a component and submit it to the repo so anyone can just install the component directly without having to mess with any of the code. I don't have any timeline for that though.