Advertisement
zubir2k

Home Assistant Azan (Based on JSON file)

Aug 18th, 2021
1,554
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
YAML 6.67 KB | None | 0 0
  1. ## JAKIM eSolat (experimental) ##
  2. # Based on json response stored into a file.
  3. # Place the json file into config/www/
  4.  
  5. ## configuration.yaml ##
  6. sensor:
  7.   - platform: rest
  8.     name: eSolat API
  9.     resource: https://xxx.duckdns.org/local/esolat.json
  10.     json_attributes:
  11.      - zone
  12.       - prayerTime
  13.       - serverTime
  14.     value_template: '{{ value_json.zone }}'
  15.   - platform: template
  16.     sensors:
  17.         esolat_hijri:
  18.             friendly_name: "eSolat Hijri Date"
  19.             icon_template: mdi:calendar
  20.             value_template: >-
  21.               {% set yearday = now().strftime("%j") | int %}
  22.               {{ states.sensor.esolat_api.attributes.prayerTime[yearday-1].hijri }}
  23.         esolat_hijri_full:
  24.             friendly_name: "eSolat Hijri Date Full"
  25.             icon_template: mdi:calendar
  26.             value_template: >-
  27.               {% set months = ['Muharram', 'Safar', 'Rabi\'ul Awwal', 'Rabi\'ul Akhir', 'Jamadil Awwal', 'Jamadil Akhir', 'Rejab', 'Sha\'aban', 'Ramadhan', 'Syawwal', 'Zulkaedah', 'Zulhijjah'] %}
  28.               {% set yearday = now().strftime("%j") | int %}
  29.               {{ states.sensor.esolat_api.attributes.prayerTime[yearday-1].hijri[8:10] }} {{ months[(states.sensor.esolat_api.attributes.prayerTime[yearday-1].hijri[5:7] | int)-1] }} {{ states.sensor.esolat_api.attributes.prayerTime[yearday-1].hijri[0:4] }}h
  30.         esolat_imsak:
  31.             friendly_name: 'Imsak'
  32.             icon_template: mdi:islam
  33.             value_template: '{% set yearday = now().strftime("%j") | int %}{{as_timestamp(strptime(states.sensor.esolat_api.attributes.prayerTime[yearday-1].imsak, "%H:%M:%S")) | timestamp_custom("%I:%M %p", true)}}'
  34.             attribute_templates:
  35.                 24hours: '{% set yearday = now().strftime("%j") | int %}{{as_timestamp(strptime(states.sensor.esolat_api.attributes.prayerTime[yearday-1].imsak, "%H:%M:%S")) | timestamp_custom("%H:%M", true)}}'
  36.         esolat_subuh:
  37.             friendly_name: 'Subuh'
  38.             icon_template: mdi:islam
  39.             value_template: '{% set yearday = now().strftime("%j") | int %}{{as_timestamp(strptime(states.sensor.esolat_api.attributes.prayerTime[yearday-1].fajr, "%H:%M:%S")) | timestamp_custom("%I:%M %p", true)}}'
  40.             attribute_templates:
  41.                 24hours: '{% set yearday = now().strftime("%j") | int %}{{as_timestamp(strptime(states.sensor.esolat_api.attributes.prayerTime[yearday-1].fajr, "%H:%M:%S")) | timestamp_custom("%H:%M", true)}}'
  42.         esolat_syuruk:
  43.             friendly_name: 'Syuruk'
  44.             icon_template: mdi:islam
  45.             value_template: '{% set yearday = now().strftime("%j") | int %}{{as_timestamp(strptime(states.sensor.esolat_api.attributes.prayerTime[yearday-1].syuruk, "%H:%M:%S")) | timestamp_custom("%I:%M %p", true)}}'
  46.             attribute_templates:
  47.                 24hours: '{% set yearday = now().strftime("%j") | int %}{{as_timestamp(strptime(states.sensor.esolat_api.attributes.prayerTime[yearday-1].syuruk, "%H:%M:%S")) | timestamp_custom("%H:%M", true)}}'
  48.         esolat_zohor:
  49.             friendly_name: 'Zohor'
  50.             icon_template: mdi:islam
  51.             value_template: '{% set yearday = now().strftime("%j") | int %}{{as_timestamp(strptime(states.sensor.esolat_api.attributes.prayerTime[yearday-1].dhuhr, "%H:%M:%S")) | timestamp_custom("%I:%M %p", true)}}'
  52.             attribute_templates:
  53.                 24hours: '{% set yearday = now().strftime("%j") | int %}{{as_timestamp(strptime(states.sensor.esolat_api.attributes.prayerTime[yearday-1].dhuhr, "%H:%M:%S")) | timestamp_custom("%H:%M", true)}}'
  54.         esolat_asar:
  55.             friendly_name: 'Asar'
  56.             icon_template: mdi:islam
  57.             value_template: '{% set yearday = now().strftime("%j") | int %}{{as_timestamp(strptime(states.sensor.esolat_api.attributes.prayerTime[yearday-1].asr, "%H:%M:%S")) | timestamp_custom("%I:%M %p", true)}}'
  58.             attribute_templates:
  59.                 24hours: '{% set yearday = now().strftime("%j") | int %}{{as_timestamp(strptime(states.sensor.esolat_api.attributes.prayerTime[yearday-1].asr, "%H:%M:%S")) | timestamp_custom("%H:%M", true)}}'
  60.         esolat_maghrib:
  61.             friendly_name: 'Maghrib'
  62.             icon_template: mdi:islam
  63.             value_template: '{% set yearday = now().strftime("%j") | int %}{{as_timestamp(strptime(states.sensor.esolat_api.attributes.prayerTime[yearday-1].maghrib, "%H:%M:%S")) | timestamp_custom("%I:%M %p", true)}}'
  64.             attribute_templates:
  65.                 24hours: '{% set yearday = now().strftime("%j") | int %}{{as_timestamp(strptime(states.sensor.esolat_api.attributes.prayerTime[yearday-1].maghrib, "%H:%M:%S")) | timestamp_custom("%H:%M", true)}}'
  66.         esolat_isyak:
  67.             friendly_name: 'Isyak'
  68.             icon_template: mdi:islam
  69.             value_template: '{% set yearday = now().strftime("%j") | int %}{{as_timestamp(strptime(states.sensor.esolat_api.attributes.prayerTime[yearday-1].isha, "%H:%M:%S")) | timestamp_custom("%I:%M %p", true)}}'
  70.             attribute_templates:
  71.                 24hours: '{% set yearday = now().strftime("%j") | int %}{{as_timestamp(strptime(states.sensor.esolat_api.attributes.prayerTime[yearday-1].isha, "%H:%M:%S")) | timestamp_custom("%H:%M", true)}}'
  72.         esolat_waktusekarang:
  73.             friendly_name: Waktu Sekarang
  74.             icon_template: mdi:islam
  75.             value_template: >-
  76.                 {% if states("sensor.time") >= state_attr("sensor.esolat_imsak", "24hours") and states("sensor.time") < state_attr("sensor.esolat_subuh", "24hours") %}
  77.                 Imsak
  78.                 {% elif states("sensor.time") >= state_attr("sensor.esolat_subuh", "24hours") and states("sensor.time") < state_attr("sensor.esolat_syuruk", "24hours") %}
  79.                 Subuh
  80.                 {% elif states("sensor.time") >= state_attr("sensor.esolat_syuruk", "24hours") and states("sensor.time") < state_attr("sensor.esolat_zohor", "24hours") %}
  81.                 Syuruk
  82.                 {% elif states("sensor.time") >= state_attr("sensor.esolat_zohor", "24hours") and states("sensor.time") < state_attr("sensor.esolat_asar", "24hours") %}
  83.                 Zohor
  84.                 {% elif states("sensor.time") >= state_attr("sensor.esolat_asar", "24hours") and states("sensor.time") < state_attr("sensor.esolat_maghrib", "24hours") %}
  85.                 Asar
  86.                 {% elif states("sensor.time") >= state_attr("sensor.esolat_maghrib", "24hours") and states("sensor.time") < state_attr("sensor.esolat_isyak", "24hours") %}
  87.                 Maghrib
  88.                 {% elif states("sensor.time") >= state_attr("sensor.esolat_isyak", "24hours") %}
  89.                 Isyak
  90.                 {%- else %}
  91.                 Isyak
  92.                 {%- endif %}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement