Skip to content

Instantly share code, notes, and snippets.

@zubir2k
Last active April 26, 2022 06:01
Show Gist options
  • Save zubir2k/04a3180f50f621c5840bbdc477d0027f to your computer and use it in GitHub Desktop.
Save zubir2k/04a3180f50f621c5840bbdc477d0027f to your computer and use it in GitHub Desktop.
HomeAssistantSolatGPS
## Solat by Location ##
# Based on API Provided by Malaysia Prayer Time (https://mpt.i906.my/api.html)
# Please change the person sensor (person.zubir) accordingly..
# Place this code into configuration.yaml
sensor:
- platform: rest
name: "Solat GPS"
scan_interval: 1800
resource_template: "https://mpt.i906.my/api/prayer/{{ state_attr('person.zubir', 'latitude') ~ ',' ~ state_attr('person.zubir', 'longitude') }}"
value_template: "{{ value_json['data']['place'] }}"
json_attributes_path: "$.data"
json_attributes:
- attributes
- times
## Template YAML ##
# Tested working in WearOS Companion App.
# Template contains condition if person is not at home, it will show sensor.solat_GPS. Else, local
{% set date_index = now().strftime("%d") | int - 1%}
-:{ Waktu Solat }:-
{%if not is_state('person.zubir', 'home')%}Location: {{states('sensor.solat_GPS')}}
Subuh: {{state_attr('sensor.solat_GPS', 'times')[date_index][0] | int | timestamp_custom('%I:%M %p')}}
Zohor: {{state_attr('sensor.solat_GPS', 'times')[date_index][2] | int | timestamp_custom('%I:%M %p')}}
Asar: {{state_attr('sensor.solat_GPS', 'times')[date_index][3] | int | timestamp_custom('%I:%M %p')}}
Maghrib: {{state_attr('sensor.solat_GPS', 'times')[date_index][4] | int | timestamp_custom('%I:%M %p')}}
Isyak: {{state_attr('sensor.solat_GPS', 'times')[date_index][5] | int | timestamp_custom('%I:%M %p')}}
{%else%}Waktu Sekarang: {{states('sensor.solat_sekarang')}}
Subuh: {{states('sensor.solat_subuh')}}
Zohor: {{states('sensor.solat_zohor')}}
Asar: {{states('sensor.solat_asar')}}
Maghrib: {{states('sensor.solat_maghrib')}}
Isyak: {{states('sensor.solat_isyak')}}
{%endif%}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment