Offset time

@123 thanks everything is working as expected… really appreciate your support and patience

Thank you all for helping out with this automation may you’ll be blessed whenever this automation is used.

It would be highly appreciated if someone could help with creating a scrape or web sensor for local masjids.I am using the following website MasjidBoard Live

Thanks

Hi @123 me again :). I found that with the automation/configuration above there is delay between speakers. Is there anyway to fix that? I see that each speaker is delayed ±1sec. Would be good if all speakers are synchronized

If you are using speakers that support Chromecast, you can use Google Home to combine them into a single grouped speaker. The grouped speaker will be discovered by Home Assistant. Playing to this grouped speaker should eliminate any small delays you are currently hearing between individual speakers.

Sonos speakers also support grouping.

Yes that’s what I did however by grouping speakers I didn’t find a way to set specific volume for each speaker. I think when you group speakers it use same volume level for all. I have 5 google mini speakers…

You will have to decide what’s more important to you, no delays or individual volume control.

The calculation of prayers time is not accurate for my location. I am following Diyanet/Turkey times. Can i just store monthly the 5prayers/day to somewhere and just update every month. Now i have to change the offsets duration daily…

@123 someone helped me toi trigger prayer times from a website which creates times.txt and update every 4hours
/config/times.txt

{“time”:[“05:16”,“06:53”,“11:45”,“14:03”,“16:27”,“17:47”],“date”:“20.11.2021”}

this is my configuration file

default_config:

#start ici
media_extractor:

Track the sun

sun:

template:
- sensor:
- name: “today_time_fajr_prayer”
state: ‘{{ (states.sensor.times.state|from_json).time[0] }}’
- name: “today_time_dhuhr_prayer”
state: ‘{{ (states.sensor.times.state|from_json).time[2] }}’
- name: “today_time_asr_prayer”
state: ‘{{ (states.sensor.times.state|from_json).time[3] }}’
- name: “today_time_maghrib_prayer”
state: ‘{{ (states.sensor.times.state|from_json).time[4] }}’
- name: “today_time_isha_prayer”
state: ‘{{ (states.sensor.times.state|from_json).time[5] }}’

sensor:

  • platform: file
    file_path: /config/times.txt
    name: Times
  • platform: time_date
    display_options:
    • ‘time’
    • ‘date’
    • ‘date_time’
    • ‘date_time_iso’
    • ‘time_date’
    • ‘time_utc’
    • ‘beat’

tts:

  • platform: google_translate

group: !include groups.yaml
automation: !include automations.yaml
script: !include scripts.yaml
scene: !include scenes.yaml

I have problem with my automation. It will not play YouTube link based on prayer hours…

alias: Adhan
id: adhan_announcement
trigger:

  • platform: template
    value_template: “{{ now().timestamp()|int == as_timestamp(states(‘sensor.today_time_fajr_prayer’)) }}”
  • platform: template
    value_template: “{{ now().timestamp()|int == as_timestamp(states(‘sensor.today_time_dhuhr_prayer’)) }}”
  • platform: template
    value_template: “{{ now().timestamp()|int == as_timestamp(states(‘sensor.today_time_asr_prayer’)) }}”
  • platform: template
    value_template: “{{ now().timestamp()|int == as_timestamp(states(‘sensor.today_time_maghrib_prayer’)) }}”
  • platform: template
    value_template: “{{ now().timestamp()|int == as_timestamp(states(‘sensor.today_time_isha_prayer’)) }}”
    action:
  • variables:
    players: >
    {{[
    [ {‘player’: ‘basement_speaker’, ‘volume’: 0.5} ],
    [ {‘player’: ‘all_speakers’, ‘volume’: 0.5} ],
    [ {‘player’: ‘all_speakers’, ‘volume’: 0.5} ],
    [ {‘player’: ‘all_speakers’, ‘volume’: 0.6} ],
    [ {‘player’: ‘all_speakers’, ‘volume’: 0.6} ]
    ][trigger.id | default(0) | int]}}
  • repeat:
    count: “{{ players | count }}”
    sequence:
    • variables:
      player: ‘media_player.{{ players[repeat.index-1].player }}’
      volume: ‘{{ players[repeat.index-1].volume }}’
    • service: media_extractor.play_media
      data:
      entity_id: “{{ player }}”
      media_content_id: https://www.youtube.com/watch?v=imF7mu1Mdmk
      media_content_type: audio/youtube
    • service: media_player.volume_set
      data:
      entity_id: “{{ player }}”
      volume_level: “{{ volume }}”

can you help me?

Ideally you should be asking whoever helped you because they proposed it. However, I think I know why it fails to trigger.

Each Template Sensor (like sensor.today_time_fajr_prayer) only contains the time and not time and date. However, the automation’s Template Trigger is comparing today’s timestamp (which represents today’s time and date) with just the sensor’s time. The two timestamps can never match.

Here’s what I suggest you try. Replace all five Template Triggers with this:

  - platform: template
    value_template: "{{ now().replace(microsecond=0) == today_at(states('sensor.today_time_fajr_prayer')) }}"
  - platform: template
    value_template: "{{ now().replace(microsecond=0) == today_at(states('sensor.today_time_dhuhr_prayer')) }}"
  - platform: template
    value_template: "{{ now().replace(microsecond=0) == today_at(states('sensor.today_time_asr_prayer')) }}"
  - platform: template
    value_template: "{{ now().replace(microsecond=0) == today_at(states('sensor.today_time_maghrib_prayer')) }}"
  - platform: template
    value_template: "{{ now().replace(microsecond=0) == today_at(states('sensor.today_time_isha_prayer')) }}"

Thanks again that fixed the automation.

Hi @123 can you help me improving this automation? I am looking to have separate YouTube link for each prayer time.

alias: Adhan
id: adhan_announcement
trigger:     
  - platform: template
    value_template: "{{ now().replace(microsecond=0) == today_at(states('sensor.today_time_fajr_prayer')) }}"
  - platform: template
    value_template: "{{ now().replace(microsecond=0) == today_at(states('sensor.today_time_dhuhr_prayer')) }}"
  - platform: template
    value_template: "{{ now().replace(microsecond=0) == today_at(states('sensor.today_time_asr_prayer')) }}"
  - platform: template
    value_template: "{{ now().replace(microsecond=0) == today_at(states('sensor.today_time_maghrib_prayer')) }}"
  - platform: template
    value_template: "{{ now().replace(microsecond=0) == today_at(states('sensor.today_time_isha_prayer')) }}"
action:
  - variables:
      players: >
        {{[
          [ {'player': 'basement_speaker', 'volume': 0.5} ],
          [ {'player': 'all_speakers', 'volume': 0.5} ],
          [ {'player': 'all_speakers', 'volume': 0.5} ],
          [ {'player': 'all_speakers', 'volume': 0.6} ],
          [ {'player': 'all_speakers', 'volume': 0.6} ]
          ][trigger.id | default(0) | int]}}
  - repeat:
      count: "{{ players | count }}"
      sequence:
      - variables:
          player: 'media_player.{{ players[repeat.index-1].player }}'
          volume: '{{ players[repeat.index-1].volume }}'
      - service: media_extractor.play_media
        data:
          entity_id: "{{ player }}"
          media_content_id: https://www.youtube.com/watch?v=imF7mu1Mdmk
          media_content_type: audio/youtube
      - service: media_player.volume_set
        data:
          entity_id: "{{ player }}"
          volume_level: "{{ volume }}"

Sorry to hijack this thread, but I think my issue is quite similar. I have an alarm clock with the following automation trigger

trigger:
  - platform: template
    value_template: '{{ states(''sensor.time'') == states(''sensor.wake_time_1'')}}'

But I’d like a separate automation to turn on a switch 45 minutes earlier. I’d think I could just add an offset to my code above but do not know how to do that.

Brother @123 - Your suggestion have resolved my issues in the automation. Jazakallah Khairan

https://community.home-assistant.io/t/adhan-automation-using-home-assistant-and-google-home-mini/135622/441