Adhan Automation (الأذان التلقائي للصلاة) using google speaker

so all of my configs are in sensor.yaml file, put all of the following code in Sensor file not in Template file. Because the codes using Template integration under sensor components.

  - platform: rest
    name: "Prayer Times"
    json_attributes:
      - data
    resource: "http://api.aladhan.com/v1/timings?latitude=50.343535&longitude=-88.454656&method=2&school=1"
    value_template: '{{ value_json["data"]["meta"]["method"]["name"].title() }}'
    scan_interval: 3600

  - platform: template
    sensors:
      fajr_prayer_time:
        friendly_name: "Fajr Prayer Time"
        value_template: >
          {{ today_at(state_attr('sensor.prayer_times','data').timings['Fajr']).strftime("%I:%M %p") }}
      dhuhr_prayer_time:
        friendly_name: "Dhuhr Prayer Time"
        value_template: >
          {{ today_at(state_attr('sensor.prayer_times','data').timings['Dhuhr']).strftime("%I:%M %p") }}
      asr_prayer_time:
        friendly_name: "Asr Prayer Time"
        value_template: >
          {{ today_at(state_attr('sensor.prayer_times','data').timings['Asr']).strftime("%I:%M %p") }}
      maghrib_prayer_time:
        friendly_name: "Maghrib Prayer Time"
        value_template: >
          {{ today_at(state_attr('sensor.prayer_times','data').timings['Maghrib']).strftime("%I:%M %p") }}
      isha_prayer_time:
        friendly_name: "Isha Prayer Time"
        value_template: >
          {{ today_at(state_attr('sensor.prayer_times','data').timings['Isha']).strftime("%I:%M %p") }}
      imsak_time:
        friendly_name: "Imsak"
        value_template: >
          {{ today_at(state_attr('sensor.prayer_times','data').timings['Imsak']).strftime("%I:%M %p") }}
          
          
  - platform: template
    sensors:
      next_prayer:
        friendly_name: Next Prayer
        value_template: >-
          {% set now = strptime(states('sensor.time'), '%H:%M') %}
          {% set imsak = strptime(states('sensor.imsak_time'), '%I:%M %p') %}
          {% set fajr = strptime(states('sensor.fajr_prayer_time'), '%I:%M %p') %}
          {% set dhuhr = strptime(states('sensor.dhuhr_prayer_time'), '%I:%M %p') %}
          {% set asr = strptime(states('sensor.asr_prayer_time'), '%I:%M %p') %}
          {% set maghrib = strptime(states('sensor.maghrib_prayer_time'), '%I:%M %p') %}
          {% set isha = strptime(states('sensor.isha_prayer_time'), '%I:%M %p') %}

          {% if now < imsak %}
            {{ states('sensor.imsak_time') }}
          {% elif imsak <= now < fajr %}
            {{ states('sensor.fajr_prayer_time') }}
          {% elif fajr <= now < dhuhr %}
            {{ states('sensor.dhuhr_prayer_time') }}
          {% elif dhuhr <= now < asr %}
            {{ states('sensor.asr_prayer_time') }}
          {% elif asr <= now < maghrib %}
            {{ states('sensor.maghrib_prayer_time') }}
          {% elif maghrib <= now < isha %}
            {{ states('sensor.isha_prayer_time') }}
          {% else %}
            {% set tomorrow = now + timedelta(days=1) %}
            {% set tomorrow_str = tomorrow.strftime('%Y-%m-%d') %}
            {{ states('sensor.fajr_prayer_time', {'date': tomorrow_str}) }}
          {% endif %}
          
          
  - platform: template
    sensors:
      time_until_next_prayer:
        friendly_name: Time Until Next Prayer
        value_template: >-
          {% set current_time = now().strftime('%H:%M') %}
          {% set next_prayer = states('sensor.next_prayer') %}
          {% set next_prayer_datetime = strptime(next_prayer, '%I:%M %p') %}
          {% set current_datetime = strptime(current_time, '%H:%M').replace(year=next_prayer_datetime.year, month=next_prayer_datetime.month, day=next_prayer_datetime.day) %}
          {% if current_datetime < next_prayer_datetime %}
            {{ (next_prayer_datetime - current_datetime).total_seconds() }}
          {% else %}
            {{ (next_prayer_datetime + timedelta(days=1) - current_datetime).total_seconds() }}
          {% endif %}
        unit_of_measurement: seconds
        
        
  - platform: template
    sensors:
      time_until_next_prayer_formatted:
        friendly_name: Time Until Next Prayer Formatted
        value_template: >-
          {% set total_seconds = states('sensor.time_until_next_prayer') | float %}
          {% set hours = (total_seconds // 3600) | int %}
          {% set minutes = ((total_seconds % 3600) // 60) | int %}
          {{ '%02d:%02d' % (hours, minutes) }}

1 Like

This was it. jazaka Allah khair!!!

1 Like

@Tismo Salam aalikom. Could you please post your yaml code for all the configuration including the card. I am trying to get it work but with no success.

@Tismo @banstro @chintito4ever
I got it working partially but still next prayer showing as unavailable. I have all the sensors in sensors.yaml but still no dice:
image

I am including my code in sensors.yaml:

- platform: rest
  name: "Prayer Times"
  json_attributes:
    - data
  resource: "http://api.aladhan.com/v1/timings?latitude=mylatitude&longitude=-mylongtitude&method=1&school=2"
  value_template: '{{ value_json["data"]["meta"]["method"]["name"].title() }}'
  scan_interval: 3600

- platform: template
  sensors:
      fajr_prayer_time:
        friendly_name: "Fajr Prayer Time"
        value_template: >
          {{ today_at(state_attr('sensor.prayer_times','data').timings['Fajr']).strftime("%I:%M %p") }}
      dhuhr_prayer_time:
        friendly_name: "Dhuhr Prayer Time"
        value_template: >
          {{ today_at(state_attr('sensor.prayer_times','data').timings['Dhuhr']).strftime("%I:%M %p") }}
      asr_prayer_time:
        friendly_name: "Asr Prayer Time"
        value_template: >
          {{ today_at(state_attr('sensor.prayer_times','data').timings['Asr']).strftime("%I:%M %p") }}
      maghrib_prayer_time:
        friendly_name: "Maghrib Prayer Time"
        value_template: >
          {{ today_at(state_attr('sensor.prayer_times','data').timings['Maghrib']).strftime("%I:%M %p") }}
      isha_prayer_time:
        friendly_name: "Isha Prayer Time"
        value_template: >
          {{ today_at(state_attr('sensor.prayer_times','data').timings['Isha']).strftime("%I:%M %p") }}
      imsak_time:
        friendly_name: "Imsak"
        value_template: >
          {{ today_at(state_attr('sensor.prayer_times','data').timings['Imsak']).strftime("%I:%M %p") }}
          
          
- platform: template
  sensors:
      next_prayer:
        friendly_name: Next Prayer
        value_template: >-
          {% set now = strptime(states('sensor.time'), '%H:%M') %}
          {% set imsak = strptime(states('sensor.imsak_time'), '%I:%M %p') %}
          {% set fajr = strptime(states('sensor.fajr_prayer_time'), '%I:%M %p') %}
          {% set dhuhr = strptime(states('sensor.dhuhr_prayer_time'), '%I:%M %p') %}
          {% set asr = strptime(states('sensor.asr_prayer_time'), '%I:%M %p') %}
          {% set maghrib = strptime(states('sensor.maghrib_prayer_time'), '%I:%M %p') %}
          {% set isha = strptime(states('sensor.isha_prayer_time'), '%I:%M %p') %}

          {% if now < imsak %}
            {{ states('sensor.imsak_time') }}
          {% elif imsak <= now < fajr %}
            {{ states('sensor.fajr_prayer_time') }}
          {% elif fajr <= now < dhuhr %}
            {{ states('sensor.dhuhr_prayer_time') }}
          {% elif dhuhr <= now < asr %}
            {{ states('sensor.asr_prayer_time') }}
          {% elif asr <= now < maghrib %}
            {{ states('sensor.maghrib_prayer_time') }}
          {% elif maghrib <= now < isha %}
            {{ states('sensor.isha_prayer_time') }}
          {% else %}
            {% set tomorrow = now + timedelta(days=1) %}
            {% set tomorrow_str = tomorrow.strftime('%Y-%m-%d') %}
            {{ states('sensor.fajr_prayer_time', {'date': tomorrow_str}) }}
          {% endif %}
          
          
- platform: template
  sensors:
      time_until_next_prayer:
        friendly_name: Time Until Next Prayer
        value_template: >-
          {% set current_time = now().strftime('%H:%M') %}
          {% set next_prayer = states('sensor.next_prayer') %}
          {% set next_prayer_datetime = strptime(next_prayer, '%I:%M %p') %}
          {% set current_datetime = strptime(current_time, '%H:%M').replace(year=next_prayer_datetime.year, month=next_prayer_datetime.month, day=next_prayer_datetime.day) %}
          {% if current_datetime < next_prayer_datetime %}
            {{ (next_prayer_datetime - current_datetime).total_seconds() }}
          {% else %}
            {{ (next_prayer_datetime + timedelta(days=1) - current_datetime).total_seconds() }}
          {% endif %}
        unit_of_measurement: seconds
        
        
- platform: template
  sensors:
      time_until_next_prayer_formatted:
        friendly_name: Time Until Next Prayer Formatted
        value_template: >-
          {% set total_seconds = states('sensor.time_until_next_prayer') | float %}
          {% set hours = (total_seconds // 3600) | int %}
          {% set minutes = ((total_seconds % 3600) // 60) | int %}
          {{ '%02d:%02d' % (hours, minutes) }}

it should work, did you put in right place? if you’re using separate file like ‘sensors.yaml’ then do not forget to add ‘sensor: !include sensors.yaml’ in your main ‘configuration.yaml’ file.

@chintito4ever , Yes the sensors.yaml is included in the config file as you can see in the screenshot below:
image
I am including the prayers times in the lovelace card code to check if I have any errors or missing something:

type: custom:stack-in-card
cards:
  - type: custom:button-card
    variables:
      currentview: |
        [[[ 
          return window.location.pathname.split('/').slice(-1);
        ]]]
    name: PRAYER TIMES | أوقات الصلاة
    color_type: card
    styles:
      card:
        - height: 3em
        - align: center
        - font-weight: bold
        - background-color: ''
          color: var(--primary-color)
  - type: custom:mushroom-template-card
    primary: Prayer Timings
    secondary: |-
      {{ states('sensor.next_prayer') }} | {{
         states('sensor.time_until_next_prayer_formatted') }} time left
    icon: mdi:mosque
    entity: sensor.next_prayer
    tap_action:
      action: none
      hold_action:
        action: none
      icon_color: red
      fill_container: false
      multiline_secondary: false
      card_mod:
        style: |
          ha-card {
          --ha-card-box-shadow: 0px ;
           }
  - type: horizontal-stack
    cards:
      - type: custom:mushroom-template-card
        entity: sensor.fajr_prayer_time
        primary: Fajr
        secondary: |
          {{ states('sensor.fajr_prayer_time') }}
        icon: mdi:weather-sunset-up
        icon_color: '#F44336'
        tap_action:
          action: more-info
        layout: vertical
        fill_container: false
        multiline_secondary: false
        card_mod:
          style: |
            .mushroom-template-card .title {
              grid-row: 1 / 2; /* span across the first row */
              justify-self: start; /* align to the left */
            }
            .mushroom-template-card .subtitle {
              grid-row: 2 / 3; /* span across the second row */
              justify-self: end; /* align to the right */
            }
      - type: custom:mushroom-template-card
        entity: sensor.dhuhr_prayer_time
        primary: Dhuhr
        secondary: |
          {{ states('sensor.dhuhr_prayer_time') }}
        icon: mdi:weather-sunny
        icon_color: '#F1C40F'
        tap_action:
          action: more-info
        layout: vertical
        fill_container: false
        multiline_secondary: false
        card_mod:
          style: |
            .mushroom-template-card .title {
              grid-row: 1 / 2; /* span across the first row */
              justify-self: start; /* align to the left */
            }
            .mushroom-template-card .subtitle {
              grid-row: 2 / 3; /* span across the second row */
              justify-self: end; /* align to the right */
            }
      - type: custom:mushroom-template-card
        entity: sensor.asr_prayer_time
        primary: Asr
        secondary: |
          {{ states('sensor.asr_prayer_time') }}
        icon: mdi:weather-sunset-down
        icon_color: '#9C27B0'
        tap_action:
          action: more-info
        layout: vertical
        fill_container: false
        multiline_secondary: false
        card_mod:
          style: |
            .mushroom-template-card .title {
              grid-row: 1 / 2; /* span across the first row */
              justify-self: start; /* align to the left */
            }
            .mushroom-template-card .subtitle {
              grid-row: 2 / 3; /* span across the second row */
              justify-self: end; /* align to the right */
            }
      - type: custom:mushroom-template-card
        entity: sensor.maghrib_prayer_time
        primary: Maghrib
        secondary: |
          {{ states('sensor.maghrib_prayer_time') }}
        icon: mdi:weather-sunset
        icon_color: '#FF9800'
        tap_action:
          action: more-info
        layout: vertical
        fill_container: false
        multiline_secondary: false
        card_mod:
          style: |
            .mushroom-template-card .title {
              grid-row: 1 / 2; /* span across the first row */
              justify-self: start; /* align to the left */
            }
            .mushroom-template-card .subtitle {
              grid-row: 2 / 3; /* span across the second row */
              justify-self: end; /* align to the right */
            }
      - type: custom:mushroom-template-card
        entity: sensor.isha_prayer_time
        primary: Isha
        secondary: |
          {{ states('sensor.isha_prayer_time') }}
        icon: mdi:weather-night
        icon_color: '#673AB7'
        tap_action:
          action: more-info
        layout: vertical
        fill_container: false
        multiline_secondary: false
        card_mod:
          style: |
            .mushroom-template-card .title {
              grid-row: 1 / 2; /* span across the first row */
              justify-self: start; /* align to the left */
            }
            .mushroom-template-card .subtitle {
              grid-row: 2 / 3; /* span across the second row */
              justify-self: end; /* align to the right */
            }
      - type: custom:mushroom-template-card
        entity: sensor.imsak_time_time
        primary: Imsak
        secondary: |
          {{ states('sensor.imsak_time') }}
        icon: mdi:weather-sunset
        icon_color: '#FF9800'
        tap_action:
          action: more-info
        layout: vertical
        fill_container: false
        multiline_secondary: false
        card_mod:
          style: |
            .mushroom-template-card .title {
              grid-row: 1 / 2; /* span across the first row */
              justify-self: start; /* align to the left */
            }
            .mushroom-template-card .subtitle {
              grid-row: 2 / 3; /* span across the second row */
              justify-self: end; /* align to the right */
            }
    style: |
      ha-card {
        background: none;
        box-shadow: none;
      }

Does using Islamic Prayer Times conflict with using the sensors created by the codes above since both use the same api? This might be why the next prayer sensor shows as unavailable?

same issue also by me. I have also installed the official prayer time integration but no way how i can show the next prayer time on the lovelace card like this.
rpyaer

Anyone a solution?

Because there isn’t a default way to show next prayer time. I spent a lot of time to achieve something like this:

Hello Looks great.
Do you mind sharing your card ?

Ofcourse! here you go:
for timer I am using this card: “GitHub - rianadon/timer-bar-card: A progress bar display for Home Assistant timers

type: custom:stack-in-card
cards:
  - type: custom:layout-card
    layout_type: custom:grid
    layout:
      grid-template-columns: auto 120px
      grid-template-rows: auto auto
      margin: '-4px 0px -10px -4px;'
    cards:
      - type: custom:mushroom-template-card
        primary: Prayer Times
        secondary: |-
          Next Prayer: {{ states('sensor.next_prayer') }} | Starts in         {{
           states('sensor.time_until_next_prayer_formatted') }}
        icon: mdi:mosque
        entity: sensor.next_prayer
        tap_action:
          action: none
        hold_action:
          action: none
        icon_color: red
        fill_container: false
        multiline_secondary: false
        style: |
          ha-card {
            background: none;
            box-shadow: none;
          }
  - type: custom:timer-bar-card
    entities:
      - timer.next_prayer_timer
    layout: full_row
    bar_radius: 3em
    bar_height: 15px
    bar_width: 50%
    bar_foreground: '#FF9800'
    bar_background: '#FFE0B2'
  - type: horizontal-stack
    cards:
      - type: custom:mushroom-template-card
        entity: sensor.fajr_prayer_time
        primary: Fajr
        secondary: |
          {{ states('sensor.fajr_prayer_time') }}
        icon: mdi:weather-sunset-up
        icon_color: '#F44336'
        tap_action:
          action: more-info
        layout: vertical
        fill_container: false
        multiline_secondary: false
        card_mod:
          style: |
            .mushroom-template-card .title {
              grid-row: 1 / 2; /* span across the first row */
              justify-self: start; /* align to the left */
            }
            .mushroom-template-card .subtitle {
              grid-row: 2 / 3; /* span across the second row */
              justify-self: end; /* align to the right */
            }
      - type: custom:mushroom-template-card
        entity: sensor.dhuhr_prayer_time
        primary: Dhuhr
        secondary: |
          {{ states('sensor.dhuhr_prayer_time') }}
        icon: mdi:weather-sunny
        icon_color: '#F1C40F'
        tap_action:
          action: more-info
        layout: vertical
        fill_container: false
        multiline_secondary: false
        card_mod:
          style: |
            .mushroom-template-card .title {
              grid-row: 1 / 2; /* span across the first row */
              justify-self: start; /* align to the left */
            }
            .mushroom-template-card .subtitle {
              grid-row: 2 / 3; /* span across the second row */
              justify-self: end; /* align to the right */
            }
      - type: custom:mushroom-template-card
        entity: sensor.asr_prayer_time
        primary: Asr
        secondary: |
          {{ states('sensor.asr_prayer_time') }}
        icon: mdi:weather-sunset-down
        icon_color: '#9C27B0'
        tap_action:
          action: more-info
        layout: vertical
        fill_container: false
        multiline_secondary: false
        card_mod:
          style: |
            .mushroom-template-card .title {
              grid-row: 1 / 2; /* span across the first row */
              justify-self: start; /* align to the left */
            }
            .mushroom-template-card .subtitle {
              grid-row: 2 / 3; /* span across the second row */
              justify-self: end; /* align to the right */
            }
      - type: custom:mushroom-template-card
        entity: sensor.maghrib_prayer_time
        primary: Maghrib
        secondary: |
          {{ states('sensor.maghrib_prayer_time') }}
        icon: mdi:weather-sunset
        icon_color: '#FF9800'
        tap_action:
          action: more-info
        layout: vertical
        fill_container: false
        multiline_secondary: false
        card_mod:
          style: |
            .mushroom-template-card .title {
              grid-row: 1 / 2; /* span across the first row */
              justify-self: start; /* align to the left */
            }
            .mushroom-template-card .subtitle {
              grid-row: 2 / 3; /* span across the second row */
              justify-self: end; /* align to the right */
            }
      - type: custom:mushroom-template-card
        entity: sensor.isha_prayer_time
        primary: Isha
        secondary: |
          {{ states('sensor.isha_prayer_time') }}
        icon: mdi:weather-night
        icon_color: '#673AB7'
        tap_action:
          action: more-info
        layout: vertical
        fill_container: false
        multiline_secondary: false
        card_mod:
          style: |
            .mushroom-template-card .title {
              grid-row: 1 / 2; /* span across the first row */
              justify-self: start; /* align to the left */
            }
            .mushroom-template-card .subtitle {
              grid-row: 2 / 3; /* span across the second row */
              justify-self: end; /* align to the right */
            }
    style: |
      ha-card {
        background: none;
        box-shadow: none;
      }
card_mod:
  style: >
    ha-card {

    background: linear-gradient(to right, #ece9e6, #ffffff); /* A clean and
    serene gradient from light grey to white. */

    }

1 Like

Great thanks.
I managed to have it work. Only missing the for bar cardis it a template and automation

Hello, can you share your timer please. I tried with my sensor remaining but the bas doesn’t show

1 Like

which integration are you using for prayer times?

Salam brother @chintito4ever,

I noticed in the code you have ‘timer.next_prayer_timer’. I was wondering how do you create the timer.

Using the helper, i can create the timer but no idea on the duration, how do you convert the sensor to timer?

Appreciate your help on this, thanks.

1 Like

I use islamic prayer intégration and some templates

Walaikum Assalam brother, so I don’t use official prayer time integration because I follow Hanafi school and official one doesn’t have that option, so instead I use Al-Adhan API. I have shared whole config in this thread, if you filter my comments you’ll find it. In my config you’ll find I have a sensor named ‘sensor.time_until_next_prayer’ that calculates time between now and next prayer in seconds format.

Now, for timer I have created a timer sensor using helper just you did already then set up an automation which automatically put the duration of times between two prayer times.

alias: Start Next Prayer Timer
description: ""
trigger:
  - platform: template
    value_template: >-
      {% set x = states('sensor.dhuhr_prayer_time') %} {{ now() >=
      today_at(strptime(x, "%I:%M %p").time()) }}
    id: dhuhr
  - platform: template
    value_template: >-
      {% set x = states('sensor.asr_prayer_time') %} {{ now() >=
      today_at(strptime(x, "%I:%M %p").time()) }}
    id: asr
  - platform: template
    value_template: >-
      {% set x = states('sensor.isha_prayer_time') %} {{ now() >=
      today_at(strptime(x, "%I:%M %p").time()) }}
    enabled: true
    id: isha
  - platform: template
    value_template: >-
      {% set x = states('sensor.fajr_prayer_time') %} {{ now() >=
      today_at(strptime(x, "%I:%M %p").time()) }}
    id: fajr
  - platform: template
    value_template: >-
      {% set x = states('sensor.maghrib_prayer_time') %} {{ now() >=
      today_at(strptime(x, "%I:%M %p").time()) }}
    id: maghrib
  - platform: homeassistant
    event: start
condition: []
action:
  - service: timer.start
    data:
      duration: "{{ states('sensor.time_until_next_prayer') }}"
    target:
      entity_id: timer.next_prayer_timer
mode: single

If you follow my previous post you don’t need to do anything else, just copy paste my code and change the latitude and longitude of your location.

1 Like

Put all of these condes in your configuration.yaml file under sensor part:

MAKE SURE TO CHANGE YOUR LAT AND LON, AND SCHOOL IF YOU FOLLOW DIFFERENT SCHOOL THAN HANAFI:

You can find Al Adhan API details here: Prayer Times API - Prayer Times and Adhan Player

  - platform: rest
    name: "Prayer Times"
    json_attributes:
      - data
    resource: "http://api.aladhan.com/v1/timings?latitude=YOUR_LATITUDE&longitude=YOUR_LONGITUDE&method=2&school=1"
    value_template: '{{ value_json["data"]["meta"]["method"]["name"].title() }}'
    scan_interval: 3600

  - platform: template
    sensors:
      fajr_prayer_time:
        friendly_name: "Fajr Prayer Time"
        value_template: >
          {{ today_at(state_attr('sensor.prayer_times','data').timings['Fajr']).strftime("%I:%M %p") }}
      dhuhr_prayer_time:
        friendly_name: "Dhuhr Prayer Time"
        value_template: >
          {{ today_at(state_attr('sensor.prayer_times','data').timings['Dhuhr']).strftime("%I:%M %p") }}
      asr_prayer_time:
        friendly_name: "Asr Prayer Time"
        value_template: >
          {{ today_at(state_attr('sensor.prayer_times','data').timings['Asr']).strftime("%I:%M %p") }}
      maghrib_prayer_time:
        friendly_name: "Maghrib Prayer Time"
        value_template: >
          {{ today_at(state_attr('sensor.prayer_times','data').timings['Maghrib']).strftime("%I:%M %p") }}
      isha_prayer_time:
        friendly_name: "Isha Prayer Time"
        value_template: >
          {{ today_at(state_attr('sensor.prayer_times','data').timings['Isha']).strftime("%I:%M %p") }}
      imsak_time:
        friendly_name: "Imsak"
        value_template: >
          {{ today_at(state_attr('sensor.prayer_times','data').timings['Imsak']).strftime("%I:%M %p") }}
          
          
  - platform: template
    sensors:
      next_prayer:
        friendly_name: Next Prayer
        value_template: >-
          {% set now = strptime(states('sensor.time'), '%H:%M') %}
          {% set fajr = strptime(states('sensor.fajr_prayer_time'), '%I:%M %p') %}
          {% set dhuhr = strptime(states('sensor.dhuhr_prayer_time'), '%I:%M %p') %}
          {% set asr = strptime(states('sensor.asr_prayer_time'), '%I:%M %p') %}
          {% set maghrib = strptime(states('sensor.maghrib_prayer_time'), '%I:%M %p') %}
          {% set isha = strptime(states('sensor.isha_prayer_time'), '%I:%M %p') %}

          {% if now < fajr %}
            Fajr | {{ states('sensor.fajr_prayer_time') }}
          {% elif fajr <= now < dhuhr %}
            Dhuhr | {{ states('sensor.dhuhr_prayer_time') }}
          {% elif dhuhr <= now < asr %}
            Asr | {{ states('sensor.asr_prayer_time') }}
          {% elif asr <= now < maghrib %}
            Maghrib | {{ states('sensor.maghrib_prayer_time') }}
          {% elif maghrib <= now < isha %}
            Isha | {{ states('sensor.isha_prayer_time') }}
          {% else %}
            {% set tomorrow = now + timedelta(days=1) %}
            {% set tomorrow_str = tomorrow.strftime('%Y-%m-%d') %}
            Fajr | {{ states('sensor.fajr_prayer_time', {'date': tomorrow_str}) }}
          {% endif %}


  - platform: template
    sensors:
      time_until_next_prayer:
        friendly_name: Time Until Next Prayer
        value_template: >-
          {% set current_time = now().replace(tzinfo=None) %}
          {% set next_prayer = states('sensor.next_prayer').split(' | ')[1] %}
          {% set next_prayer_datetime = strptime(next_prayer, '%I:%M %p').replace(year=current_time.year, month=current_time.month, day=current_time.day, tzinfo=None) %}
          {% set delta = (next_prayer_datetime - current_time).total_seconds() %}
          {% if delta < 0 %}
            {% set next_prayer_datetime = next_prayer_datetime + timedelta(days=1) %}
            {% set delta = (next_prayer_datetime - current_time).total_seconds() %}
          {% endif %}
          {{ delta }}
        unit_of_measurement: seconds
        


  - platform: template
    sensors:
      time_until_next_prayer_formatted:
        friendly_name: Time Until Next Prayer Formatted
        value_template: >-
          {% set total_seconds = states('sensor.time_until_next_prayer') | int %}
          {% set hours = (total_seconds // 3600) %}
          {% set minutes = ((total_seconds % 3600) // 60) %}
          {% if hours > 0 %}
            {{ hours ~ 'h ' ~ minutes ~ 'm' }}
          {% else %}
            {{ minutes ~ ' min' }}
          {% endif %}
          

Then create a TIMER sensor using Helper from Settings>Devices & services>helpers>create helper>choose timer.

After that create an automation and put the following code using yaml mode:

alias: Start Next Prayer Timer
description: ""
trigger:
  - platform: template
    value_template: >-
      {% set x = states('sensor.dhuhr_prayer_time') %} {{ now() >=
      today_at(strptime(x, "%I:%M %p").time()) }}
    id: dhuhr
  - platform: template
    value_template: >-
      {% set x = states('sensor.asr_prayer_time') %} {{ now() >=
      today_at(strptime(x, "%I:%M %p").time()) }}
    id: asr
  - platform: template
    value_template: >-
      {% set x = states('sensor.isha_prayer_time') %} {{ now() >=
      today_at(strptime(x, "%I:%M %p").time()) }}
    enabled: true
    id: isha
  - platform: template
    value_template: >-
      {% set x = states('sensor.fajr_prayer_time') %} {{ now() >=
      today_at(strptime(x, "%I:%M %p").time()) }}
    id: fajr
  - platform: template
    value_template: >-
      {% set x = states('sensor.maghrib_prayer_time') %} {{ now() >=
      today_at(strptime(x, "%I:%M %p").time()) }}
    id: maghrib
  - platform: homeassistant
    event: start
condition: []
action:
  - service: timer.start
    data:
      duration: "{{ states('sensor.time_until_next_prayer') }}"
    target:
      entity_id: timer.next_prayer_timer
mode: single
1 Like

Thank you for all your hard work, the automation for the timer complete the display.

In addition, i make some tweak on the display (lovelace), if anyone intrested, please refer below for the code. Credit and full configuration goes to @chintito4ever .

Display with borders

Display with borders:

type: custom:stack-in-card
cards:
  - type: custom:mushroom-template-card
    primary: Prayer Times
    secondary: >-
      Next Prayer: Solat {{ states('sensor.next_prayer_name') }} | {{
      states('sensor.next_prayer_time') }} | Starts in {{
      states('sensor.time_until_next_prayer_formatted') |
      regex_replace('^(\\d+):.*$', '\\1') | int }}H {{
      states('sensor.time_until_next_prayer_formatted') |
      regex_replace('^\\d+:(\\d+)$', '\\1') | int }}M
    icon: mdi:mosque
    entity: sensor.next_prayer_time
    layout: horizontal
    tap_action:
      action: none
    hold_action:
      action: none
    icon_color: green
    fill_container: false
    multiline_secondary: false
    card_mod:
      style:
        mushroom-shape-icon$: |
          .shape {
            --shape-animation: ping 2s infinite;
          }
          @keyframes ping {
            0% {
              box-shadow: 0 0 5px 1px rgba(var(--rgb-green), 0.7);
            }
            
            100% {
              box-shadow: 0 0 5px 15px transparent;
            }
          }
  - type: custom:timer-bar-card
    entities:
      - timer.next_prayer_timer
    layout: full_row
    bar_radius: 5px
    bar_height: 15px
    bar_width: 50%
    text_width: 70px
    compressed: true
    filter: true
    bar_foreground: '#eb3434'
    bar_background: '#75fa87'
  - type: horizontal-stack
    cards:
      - type: custom:mushroom-template-card
        entity: sensor.subuh_time
        primary: Subuh
        secondary: |
          {{ states('sensor.subuh_time') }}
        icon: mdi:weather-sunset-up
        icon_color: '#F44336'
        tap_action:
          action: more-info
        layout: vertical
        fill_container: false
        multiline_secondary: false
        style: |
          ha-card {
            border: none; align-items: center;
          }
        card_mod:
          style: |
            .mushroom-template-card .title {
              grid-row: 1 / 2; /* span across the first row */
              justify-self: start; /* align to the left */
            }
            .mushroom-template-card .subtitle {
              grid-row: 2 / 3; /* span across the second row */
              justify-self: end; /* align to the right */
            }
      - type: custom:mushroom-template-card
        entity: sensor.zuhur_time
        primary: Zuhur
        secondary: |
          {{ states('sensor.zuhur_time') }}
        icon: mdi:weather-sunny
        icon_color: '#F1C40F'
        tap_action:
          action: more-info
        layout: vertical
        fill_container: false
        multiline_secondary: false
        card_mod:
          style: |
            .mushroom-template-card .title {
              grid-row: 1 / 2; /* span across the first row */
              justify-self: start; /* align to the left */
            }
            .mushroom-template-card .subtitle {
              grid-row: 2 / 3; /* span across the second row */
              justify-self: end; /* align to the right */
            }
      - type: custom:mushroom-template-card
        entity: sensor.asar_time
        primary: Asar
        secondary: |
          {{ states('sensor.asar_time') }}
        icon: mdi:weather-sunset-down
        icon_color: '#9C27B0'
        tap_action:
          action: more-info
        layout: vertical
        fill_container: false
        multiline_secondary: false
        card_mod:
          style: |
            .mushroom-template-card .title {
              grid-row: 1 / 2; /* span across the first row */
              justify-self: start; /* align to the left */
            }
            .mushroom-template-card .subtitle {
              grid-row: 2 / 3; /* span across the second row */
              justify-self: end; /* align to the right */
            }
      - type: custom:mushroom-template-card
        entity: sensor.maghrib_time
        primary: Maghrib
        secondary: |
          {{ states('sensor.maghrib_time') }}
        icon: mdi:weather-sunset
        icon_color: '#FF9800'
        tap_action:
          action: more-info
        layout: vertical
        fill_container: false
        multiline_secondary: false
        card_mod:
          style: |
            .mushroom-template-card .title {
              grid-row: 1 / 2; /* span across the first row */
              justify-self: start; /* align to the left */
            }
            .mushroom-template-card .subtitle {
              grid-row: 2 / 3; /* span across the second row */
              justify-self: end; /* align to the right */
            }
      - type: custom:mushroom-template-card
        entity: sensor.isyak_time
        primary: Isyak
        secondary: |
          {{ states('sensor.isyak_time') }}
        icon: mdi:weather-night
        icon_color: '#673AB7'
        tap_action:
          action: more-info
        layout: vertical
        fill_container: false
        multiline_secondary: false
        card_mod:
          style: |
            .mushroom-template-card .title {
              grid-row: 1 / 2; /* span across the first row */
              justify-self: start; /* align to the left */
            }
            .mushroom-template-card .subtitle {
              grid-row: 2 / 3; /* span across the second row */
              justify-self: end; /* align to the right */
            }

ezgif.com-video-to-gif

Display without borders:

type: custom:stack-in-card
cards:
  - type: custom:mushroom-template-card
    primary: Prayer Times
    secondary: >-
      Next Prayer: Solat {{ states('sensor.next_prayer_name') }} | {{
      states('sensor.next_prayer_time') }} | Starts in {{
      states('sensor.time_until_next_prayer_formatted') |
      regex_replace('^(\\d+):.*$', '\\1') | int }}H {{
      states('sensor.time_until_next_prayer_formatted') |
      regex_replace('^\\d+:(\\d+)$', '\\1') | int }}M
    icon: mdi:mosque
    entity: sensor.next_prayer_time
    layout: horizontal
    tap_action:
      action: none
    hold_action:
      action: none
    icon_color: green
    fill_container: false
    multiline_secondary: false
    card_mod:
      style:
        mushroom-shape-icon$: |
          .shape {
            --shape-animation: ping 2s infinite;
          }
          @keyframes ping {
            0% {
              box-shadow: 0 0 5px 1px rgba(var(--rgb-green), 0.7);
            }
            
            100% {
              box-shadow: 0 0 5px 15px transparent;
            }
          }
  - type: custom:timer-bar-card
    entities:
      - timer.next_prayer_timer
    layout: full_row
    bar_radius: 5px
    bar_height: 15px
    bar_width: 50%
    text_width: 70px
    compressed: true
    filter: true
    bar_foreground: '#eb3434'
    bar_background: '#75fa87'
  - type: horizontal-stack
    cards:
      - type: custom:mushroom-template-card
        entity: sensor.subuh_time
        primary: Subuh
        secondary: |
          {{ states('sensor.subuh_time') }}
        icon: mdi:weather-sunset-up
        icon_color: '#F44336'
        tap_action:
          action: more-info
        layout: vertical
        fill_container: false
        multiline_secondary: false
        style: |
          ha-card {
            border: none; align-items: center;
          }
        card_mod:
          style: |
            .mushroom-template-card .title {
              grid-row: 1 / 2; /* span across the first row */
              justify-self: start; /* align to the left */
            }
            .mushroom-template-card .subtitle {
              grid-row: 2 / 3; /* span across the second row */
              justify-self: end; /* align to the right */
            }
      - type: custom:mushroom-template-card
        entity: sensor.zuhur_time
        primary: Zuhur
        secondary: |
          {{ states('sensor.zuhur_time') }}
        icon: mdi:weather-sunny
        icon_color: '#F1C40F'
        tap_action:
          action: more-info
        layout: vertical
        fill_container: false
        multiline_secondary: false
        card_mod:
          style: |
            .mushroom-template-card .title {
              grid-row: 1 / 2; /* span across the first row */
              justify-self: start; /* align to the left */
            }
            .mushroom-template-card .subtitle {
              grid-row: 2 / 3; /* span across the second row */
              justify-self: end; /* align to the right */
            }
      - type: custom:mushroom-template-card
        entity: sensor.asar_time
        primary: Asar
        secondary: |
          {{ states('sensor.asar_time') }}
        icon: mdi:weather-sunset-down
        icon_color: '#9C27B0'
        tap_action:
          action: more-info
        layout: vertical
        fill_container: false
        multiline_secondary: false
        card_mod:
          style: |
            .mushroom-template-card .title {
              grid-row: 1 / 2; /* span across the first row */
              justify-self: start; /* align to the left */
            }
            .mushroom-template-card .subtitle {
              grid-row: 2 / 3; /* span across the second row */
              justify-self: end; /* align to the right */
            }
      - type: custom:mushroom-template-card
        entity: sensor.maghrib_time
        primary: Maghrib
        secondary: |
          {{ states('sensor.maghrib_time') }}
        icon: mdi:weather-sunset
        icon_color: '#FF9800'
        tap_action:
          action: more-info
        layout: vertical
        fill_container: false
        multiline_secondary: false
        card_mod:
          style: |
            .mushroom-template-card .title {
              grid-row: 1 / 2; /* span across the first row */
              justify-self: start; /* align to the left */
            }
            .mushroom-template-card .subtitle {
              grid-row: 2 / 3; /* span across the second row */
              justify-self: end; /* align to the right */
            }
      - type: custom:mushroom-template-card
        entity: sensor.isyak_time
        primary: Isyak
        secondary: |
          {{ states('sensor.isyak_time') }}
        icon: mdi:weather-night
        icon_color: '#673AB7'
        tap_action:
          action: more-info
        layout: vertical
        fill_container: false
        multiline_secondary: false
        card_mod:
          style: |
            .mushroom-template-card .title {
              grid-row: 1 / 2; /* span across the first row */
              justify-self: start; /* align to the left */
            }
            .mushroom-template-card .subtitle {
              grid-row: 2 / 3; /* span across the second row */
              justify-self: end; /* align to the right */
            }
card_mod:
  style: |
    :host {
      --stack-card-margin: 0px;
      --ha-card-border-radius: 12px;
      --ha-card-border-width: 0px;
    }

For ‘sensor.next_prayer_name’ please refer code as below (paste it inside ‘sensor.yaml’):

- platform: template
  sensors:
    next_prayer_name:
      friendly_name: Next Prayer Name
      value_template: >-
        {% set now = strptime(states('sensor.time'), '%H:%M') %}
        {% set imsak = strptime(states('sensor.imsak_time'), '%I:%M %p') %}
        {% set fajr = strptime(states('sensor.subuh_time'), '%I:%M %p') %}
        {% set dhuhr = strptime(states('sensor.zuhur_time'), '%I:%M %p') %}
        {% set asr = strptime(states('sensor.asar_time'), '%I:%M %p') %}
        {% set maghrib = strptime(states('sensor.maghrib_time'), '%I:%M %p') %}
        {% set isha = strptime(states('sensor.isyak_time'), '%I:%M %p') %}

        {% if now < imsak %}
          {{ state_attr('sensor.imsak_time', 'friendly_name') }}
        {% elif imsak <= now < fajr %}
          {{ state_attr('sensor.subuh_time', 'friendly_name') }}
        {% elif fajr <= now < dhuhr %}
          {{ state_attr('sensor.zuhur_time', 'friendly_name') }}
        {% elif dhuhr <= now < asr %}
          {{ state_attr('sensor.asar_time', 'friendly_name') }}
        {% elif asr <= now < maghrib %}
          {{ state_attr('sensor.maghrib_time', 'friendly_name') }}
        {% elif maghrib <= now < isha %}
          {{ state_attr('sensor.isyak_time', 'friendly_name') }}
        {% else %}
          {{ state_attr('sensor.subuh_time', 'friendly_name') }}
        {% endif %}
1 Like

That’s awesome! now you can use one these themes to remove the borders: GitHub - piitaya/lovelace-mushroom-themes: Additional themes for Lovelace Mushroom Cards 🍄