This guide is written especially for newbies who have just a google-home-mini and are trying to make it call for adhan. To follow this tutorial, you must have;
- Raspberry Pi (3/4)
- SD card (8/16 GB)
- Access to home router
- Any google speaker (google home mini/nest)
Please follow the steps in order.
-
Download Home Assistant Platform HassOS image from official website. Download the correct image against your Raspberry Pi model. The downloaded image has an extension .gz which means it is a highly compressed archive. Right-click on it and extract .img from it. To extract it I’d recommend 7zip or WinRar. The end result is you will have an image with .img extension.
-
Download balena etcher, a program to burn HassIO image on SD card, and install it.
-
Put your SD card in an SD card reader and connect it to your laptop/PC.
-
Open balenaEtcher, click on select image, and choose the installation image that you have. Next click on change under the drive icon and select your SD card and click continue. Next click Flash and wait for the process to get completed. Once you get notification Flast Complete, close the balenaEtcher and look for a drive in your PC with name hassos-boot. At this point, windows will ask you to format the SD card. Just cancel/ignore this request. Open hassos-boot drive and make a new folder in it with name CONFIG. Open this folder and create another folder in it with name network. Again open this folder and create a file in it with name my-network. Open this file with notepad and paste the following code in it. After this, save and close the file. This information will help your raspberry-Pi to connect to the internet via WiFi. Don’t forget to replace SSID and password in the code below with correct values of your WiFi.
WiFi Settings File
[connection]
id=my-network
uuid=72111c67-4a5d-4d5c-925e-f8ee26efb3c3
type=802-11-wireless
[802-11-wireless]
mode=infrastructure
ssid=NameOfYourWiFi
[802-11-wireless-security]
auth-alg=open
key-mgmt=wpa-psk
psk=YourPassword
[ipv4]
method=auto
[ipv6]
addr-gen-mode=stable-privacy
method=auto
If your google home mini is not already connected to the internet, now set it up before proceeding further.
-
Remove the SD card from PC, put it in Raspberry-Pi and power-on you raspberry-pi.
-
Now open an internet browser and type:
http://homeassistant.local:8123
At this point, you will be presented with the home assistant homepage with information that it will be ready in 20 minutes. In my case, it took more than 60 minutes to get ready. The homepage refreshes itself and it will ask you to set your name, username and password. Supply this information and go ahead. In the next step, it will detect your time zone. Just go head as we will set this in configuration.yaml file. At this point, if your Google home mini is already connected to the internet, it will be detected automatically. See my video.
-
On the home-assistant main page, look on the right-hand sidebar and click on Hass.io. Then click on ADD-ON-STORE. Under official add-ons, look for File Editor. Click on it and then install it. After installation, you need to start it by pressing start on the same page. Once it starts open web UI will appear. Click on it and you will be presented with an editor where we can modify configuration files.
-
On this page, look on the top for a folder icon in the blue bar. Click on it and a list of files will appear. Click on configuration.yaml. Now copy the code below and paste it in the editor on the right-hand side.
WARNING
Don’t forget to change latitude, longitude, elevation and time zone to match your location.
configuration.yaml
homeassistant:
latitude: 29.406526
longitude: 71.717677
unit_system: metric
time_zone: Australia/Brisbane
default_config:
discovery:
media_extractor:
sun:
# Islamic prayer times integration
islamic_prayer_times:
calculation_method: mwl
# Sensors
sensor:
- platform: time_date
display_options:
- 'time'
- 'date'
- 'time_date'
- platform: template
sensors:
salah_fajr:
friendly_name: "Salah Fajr"
value_template: >
{%- set a = states("sensor.fajr_prayer").split("T")[1].split(":")[0] -%}
{%- set b = states("sensor.fajr_prayer").split("T")[1].split(":")[1] -%}
{{ a + ":" + b }}
salah_dhuhr:
friendly_name: "Salah Dhuhr"
value_template: >
{%- set a = states("sensor.dhuhr_prayer").split("T")[1].split(":")[0] -%}
{%- set b = states("sensor.dhuhr_prayer").split("T")[1].split(":")[1] -%}
{{ a + ":" + b }}
salah_asr:
friendly_name: "Salah Asr"
value_template: >
{%- set a = states("sensor.asr_prayer").split("T")[1].split(":")[0] -%}
{%- set b = states("sensor.asr_prayer").split("T")[1].split(":")[1] -%}
{{ a + ":" + b }}
salah_maghrib:
friendly_name: "Salah Maghrib"
value_template: >
{%- set a = states("sensor.maghrib_prayer").split("T")[1].split(":")[0] -%}
{%- set b = states("sensor.maghrib_prayer").split("T")[1].split(":")[1] -%}
{{ a + ":" + b }}
salah_isha:
friendly_name: "Salah Isha"
value_template: >
{%- set a = states("sensor.isha_prayer").split("T")[1].split(":")[0] -%}
{%- set b = states("sensor.isha_prayer").split("T")[1].split(":")[1] -%}
{{ a + ":" + b }}
# Text to speech
tts:
- platform: google_translate
group: !include groups.yaml
automation: !include automations.yaml
script: !include scripts.yaml
-
Save the file by clicking on the floppy drive icon on the top blue bar and then close it by clicking X icon.
-
Again click on folder icon and then click on automation.yaml file. Copy and paste the code below in the editor on the right-hand side.
Caution: In the code below, against entity_id, don’t forget to replace sahar_google_mini with your Google Home Mini ID.
In the code below you have to enter your google home mini name in small letters. If the name is more than a one-word name, you have to put underscore after every word. Let say the name of your device is My Home, it should be written as my_home. If it is one-word name only, just type it in small letters.
automation.yaml
You need to replace values at TWO such places in code below.
# Automation for 5 times Azan
- action:
- alias: 'Azan'
data:
entity_id: media_player.sahar_google_mini
media_content_id: https://www.islamcan.com/audio/adhan/azan2.mp3
media_content_type: audio/mp3
service: media_extractor.play_media
- data:
entity_id: media_player.sahar_google_mini
volume_level: '0.9'
service: media_player.volume_set
alias: Adhan
trigger:
- platform: template
value_template: '{{ as_timestamp(strptime(states("sensor.time_date"), "%H:%M, %Y-%m-%d")) == as_timestamp(strptime(states("sensor.fajr_prayer"), "%Y-%m-%dT%H:%M:%S")) }}'
- platform: template
value_template: '{{ as_timestamp(strptime(states("sensor.time_date"), "%H:%M, %Y-%m-%d")) == as_timestamp(strptime(states("sensor.dhuhr_prayer"), "%Y-%m-%dT%H:%M:%S")) }}'
- platform: template
value_template: '{{ as_timestamp(strptime(states("sensor.time_date"), "%H:%M, %Y-%m-%d")) == as_timestamp(strptime(states("sensor.asr_prayer"), "%Y-%m-%dT%H:%M:%S")) }}'
- platform: template
value_template: '{{ as_timestamp(strptime(states("sensor.time_date"), "%H:%M, %Y-%m-%d")) == as_timestamp(strptime(states("sensor.maghrib_prayer"), "%Y-%m-%dT%H:%M:%S")) }}'
- platform: template
value_template: '{{ as_timestamp(strptime(states("sensor.time_date"), "%H:%M, %Y-%m-%d")) == as_timestamp(strptime(states("sensor.isha_prayer"), "%Y-%m-%dT%H:%M:%S")) }}'
### Restart HA to force update Islamic Time Sensors at 1AM ###
- alias: Restart HA
trigger:
platform: time
at: "01:00:00"
action:
- service: homeassistant.restart
- Save the file by clicking on the floppy drive icon on the top blue bar and then close it by clicking X icon.
- Now on the very left-hand side in the HomeAssistant vertical bar, click on Configuration and on the right-hand side, click on server control. Now under server management, click on restart.
- Wait for at least 5 minutes. Close the webpage/home assistant page. Open new browser page, type in your raspberry-Pi IP address along with 8213 as you did previously. HomeAssistant page will appear. Key in your credentials and you will see a dashboard with an automation card.
- On this card, you will see Adhan. Click on Adhan and then click on TRIGGER. Wait a minute and if you hear adhan from your google home mini that’s mean everything is successfully setup.
Hurrah !!! You have made it.
Remember me in your prayers. جزاک اللہ