Help for local prayer times

Hi all, i have created local prayer times method using own calculation in template developer tool. Now i want to implement that as a sensor in HA. How to implement the code as sensors such as sensor.subuh, sensor.dhuha in HA? or may be any better way to achieve the goal. here’s the code:

{% set zona = 7 %}
{% set Lintang = -6.175536342730509 %}
{% set Bujur = 106.82699699277022 %}
{% set ketinggian = 1 %}
{% set Sudut_subuh = 20 %} {# sudut antara 15 - 20 derajat #}
{% set Sudut_dhuha = 5 %} {# sudut antara 3,5 - 5 derajat #}
{% set Sudut_isya = 18 %}
{% set ikhtiyat_subuh = 2 %}
{% set ikhtiyat_zuhur = 3 %}
{% set ikhtiyat_ashar = 2 %}
{% set ikhtiyat_maghrib = 2 %}
{% set ikhtiyat_isya = 2 %}

{% set wkt = as_timestamp(now()) -%}
{% set tgl = wkt | timestamp_custom('%-d') %}
{% set bln = wkt | timestamp_custom('%-m') %}
{% set thn = wkt | timestamp_custom('%Y') %}
{% set PI = 3.141592654 %}
{% set J = 3600 %}

{% if bln | int < 3 -%}
  {% set M = bln | int + 12 %}
  {% set Y = thn | int - 1 %}
{% else %}
  {% set M = bln | int %}
  {% set Y = thn | int %}
{% endif %}

{% set A = (thn | int / 100) | round %}
{% set B = (2 - A) + ((A / 4) | round )  %}
{% set JulianUT = 1720994.5+(365.25*Y)|round(0,'floor')+(30.60001*(M+1))|round(0,'floor')+B+tgl|int+12/24 %}
{% set JulianLT = JulianUT-zona/24 %}
{% set SudutTgl = 2 * PI * (JulianLT-2451545)/365.25 %}
{% set U = (JulianLT-2451545)/36525 %}
{% set L0 = (280.46607 + 36000.7698*U) * PI/180 %}
{% set Deklinasi = 0.37877+23.264*sin((57.297*SudutTgl-79.547)*PI/180)+0.3812*sin((2*57.297*SudutTgl-82.682)*PI/180)+0.17132*sin((3*57.297*SudutTgl-59.722)*PI/180) %}
{% set EqOfTime = (-1*(1789 + 237*U)*sin(L0) - (7146 - 62*U)*cos(L0) + (9934 - 14*U)*sin(2*L0) - (29 + 5*U)*cos(2*L0) + (74 + 10*U)*sin(3*L0) + (320 - 4*U)*cos(3*L0) - 212*sin(4*L0))/1000 %}
{% set DeklinasiRad = Deklinasi * PI/180 %}
{% set LintangRad = Lintang * PI/180 %}
{% set TransitM = 12+zona-Bujur/15-EqOfTime/60 %}

{% set sub = (1 + ikhtiyat_subuh)/60 + TransitM-(12/PI)*acos((sin(-1*Sudut_subuh*PI/180)-sin(DeklinasiRad)*sin(LintangRad))/(cos(DeklinasiRad)*cos(LintangRad))) %}
{% set dhu = TransitM-(12/PI)*acos((sin(Sudut_dhuha*PI/180)-sin(DeklinasiRad)*sin(LintangRad))/(cos(DeklinasiRad)*cos(LintangRad))) %}
{% set zuh = (1 + ikhtiyat_zuhur)/60 + TransitM %}
{% set ash = (1 + ikhtiyat_ashar)/60 + TransitM+(12/PI)*acos((sin(atan(1/(1+tan((LintangRad-DeklinasiRad)|abs))))-sin(DeklinasiRad)*sin(LintangRad))/(cos(DeklinasiRad)*cos(LintangRad))) %}
{% set mag = (1 + ikhtiyat_maghrib)/60 + TransitM+(12/PI)*acos((sin((-0.8333-0.0347*ketinggian**0.5)*PI/180)-sin(DeklinasiRad)*sin(LintangRad))/(cos(DeklinasiRad)*cos(LintangRad))) %}
{% set isy = (1 + ikhtiyat_isya)/60 + TransitM+(12/PI)*acos((sin(-1*Sudut_isya*PI/180)-sin(DeklinasiRad)*sin(LintangRad))/(cos(DeklinasiRad)*cos(LintangRad))) %}
{% set ims = sub - 10/60  %}
{% set subuh = (sub | float * J) | timestamp_custom('%-H:%-M', false) %}
{% set dhuha = (dhu | float * J) | timestamp_custom('%-H:%-M', false)  %}
{% set zuhur = (zuh | float * J) | timestamp_custom('%-H:%-M', false)  %}
{% set ashar = (ash | float * J) | timestamp_custom('%-H:%-M', false)  %}
{% set maghrib = (mag | float * J) | timestamp_custom('%-H:%-M', false)  %}
{% set isya = (isy | float * J) | timestamp_custom('%-H:%-M', false)  %}
{% set imsak = (ims | float * J) | timestamp_custom('%-H:%-M', false) %}

There is an integration for Islamic prayer times - have you looked at that?

1 Like

thanks @Stiltjack for pointing this integration. This integration based on cloud CMIIW, i want to make fully local sensor for praying times due to the lack of internet at the place I want to use HA . And after digging a bit, i realized that it requires a lot off knowledge to achieve my needs, so I don’t think I want to continue it anymore. thanks a lot @Stiltjack

1 Like

i managed to created a custom integration for local prayer time using above method at https://github.com/AndroX55/Mq-Islamic-Local-Prayer-Times feel free to try it.