avraham / hass_radarr_sonarr_search_by_voice

Add movies to radarr by voice
GNU General Public License v3.0
46 stars 8 forks source link

This project migrated to https://github.com/avraham/hass_radarr_actions


As of August 31, 2022 the Google Assistant service on IFTTT doesn't support text ingredients for the Google Assistant service anymore. Until an alternative is found, this can't be activated with Home Assistant via Google speaker.

hass_radarr_sonarr_search_by_voice

Add movies and tv shows to radarr and sonarr by voice with Home Assistant and a smart speaker (Google Home, Echo) and receive voice feedback.

Requirements

Features

Add movies to radarr and tv shows to sonarr by asking your smart speaker to do it. You can set it up only for radarr, only for sonarr or both.

This script has several use cases that can be called with a different phrase depending your setup:

Install Home Assistant (Home Assistant Supervised ) using Docker. (Skip if you already have Home Assistant)

1º - Download the installer.sh from HA(Home Assistant) repository. Command:

curl -Lo installer.sh https://raw.githubusercontent.com/home-assistant/supervised-installer/master/installer.sh

2º - Than execute (You need to change the MACHINE_TYPE with the correct machine type listed bellow) Command:

bash installer.sh --machine MACHINE_TYPE
Supported Machine types

After sometime you should be able to go to http://ip_of_server:8123/ it can take some time on the first start, so be pacient.

Git Clone this script

install git

apt-get install -y git

Now it's time to clone the repo to you folder

git clone THIS_REPOSITORY

A) How to setup

HomeAssistant

Radarr

Sonarr

Services

Note to get your HomeAssistant token go to your home assistant (http://ip_of_server:8123/) then go to Your Profile (last option on the button at the left tab) then go to Long-Lived Access Tokens at the end of the page.

Note to get the HomeAssistant speaker_entity go to your home assistant (http://ip_of_server:8123/) then go to Your Configuration tab -> Entities , there is all entity ID of the devices in your home.

B) How to test from command line

For movies go to the path of the script, make sure the give executable permissions and run: python3 ./hass_radarr_search_by_voice.py "Artemis Fowl" "0" --debug

Note. First parameter is the movie title, second parameter is the mode: See Features section for more information.

For series go to the path of the script, make sure the give executable permissions and run: python3 ./hass_sonarr_search_by_voice.py "The Mandalorian" "0" "future"

Note. First parameter is the movie title, second parameter is the mode: best guess, full search; the third parameter is what should be monitored: future monitors episodes that have not aired yet and missing monitors all missing episodes that do not have files or have not aired yet.

It should let you know if it found and added a movie/tv shows (The Google Home Speaker or Echo, should speak back).

C) Integrate with Home Assistant

1) Hassio only.

1º Copy the content of the _example/homeassistantdocker. go to your cloned folder and copy the files to the Home Assistant folder.

cd hass_radarr_sonarr_search_by_voice

copy hass_radarr_search_by_voice.py, hass_sonarr_search_by_voice.py, ha_radarr_sonarr.conf and hass_radarr_search_by_voice/example/homeassistant_docker/ to the /usr/share/hassio/homeassistant/

!! WARNING: if you have allready a configuration.yaml please backup it First because the the next step will replace it / after that you need to import your configs manually (Copy and paste with nano/vim or any text editor) from your backup file, (configuration.yaml) to the new once have been copied. IF YOUR INSTALLATION IS A FRESH INSTALL JUST IGNORE THIS WARNING !

cp hass_radarr_search_by_voice.py hass_sonarr_search_by_voice.py ha_radarr_sonarr.conf /usr/share/hassio/homeassistant/
cd /example/homeassistant_docker/
cp -r * /usr/share/hassio/homeassistant/
1) Non Hassio only.

1º Copy the content of the example/homeassistant folder to your homeassistant folder. If you already have a custom yaml file for your own scripts and shell commands then just add the content of each files (scripts.yaml and shellcommand.yaml) to your own files. Also copy the examples automations in automations.yaml.

2º Let homeassistant know where your scripts and shell commands will be by adding the following lines to your configuration.yaml (in case you are using the same file structure as me).

script: !include scripts.yaml
shell_command: !include shellcommand.yaml

3º In your homeassistant/scripts/download.sh and _homeassistant/scripts/downloadtvshow.sh files replace ‘/path/to/hass_radarr_search_by_voice.py’ and ‘/path/to/hass_sonarr_search_by_voice.py’ respectively with the actual path where you saved the python file. IMPORTANT NOTE: If you are using Hassio and followed the installation method you don't need to edit the path because it point to /usr/share/hassio/homeassistant/hass_radarr_search_by_voice.py

2) Hassio and Non Hassio.

4º Fill up the User defined variables in Configuration file ha_radarr_sonarr.conf if you haven't done it.

5º Make sure the give executable permissions to _hass_radarr_search_byvoice.py & _hass_sonarr_search_byvoice.py file.

6º Bonus (optional). Fill up the User defined variables in _homeassistant/scripts/removedownload.sh

D) Use it by voice with your smart speaker and IFTTT

0º - Setup IFTTT integration on Home Assistant. Go to Configuration > integrations > IFTTT. It will give you a private IFTTT_WEEBHOOK_ID, save it somewhere this is important.

1º - Go to https://ifttt.com

2º - create a new applet. (One applet for movies and another for tv shows)

3º - click on (if this) -> Google Assistant -> Say a phrase with a text ingredient (or whatever smart speaker)

4º - What do you want to say? Enter: Download the movie $

Note the $(Dollar symbol ) is very important.THIS IS A EXAMPLE OF WHAT YOU MAY SAY TO DOWNLOAD THE MOVIE $

5º - What do you want the Assistant to say in response? Enter: Searching the movie $

Note the $(Dollar symbol ) is very important.THIS IS A EXAMPLE OF WHAT AFTER YOUR REQUEST $

6º - Save!!

7º - Click on (Then That) --> webhook

8º - Enter the following:

URL: the url you copied before at 0.D)
Method: Post
Content Type: application/json
body: { "action": "call_service", "service": "script.download_movie", "movie": "<<<{{TextField}}>>>"}

8.1º - For for sonarr (TVshows)

URL: the url you copied before at 0.D)
Method: Post
Content Type: application/json
body: { "action": "call_service", "service": "script.download_tvshow", "tvshow": " <<<{{TextField}}>>>"}

9º - Save and test with your smart speaker!!

Example folder Files overview (Additional Information):

homeassistant folder. This is your homeassistant folder where the configuration yaml files are.

homeassistant/scripts.yaml.
A separate configuration file for your own scripts instead of including everything in configuration.yaml. It’s required to add the line script: !include scripts.yaml in the configuration.yaml file to let know homeassistant about the separation.

homeassistant/shellcommand.yaml.
A separate configuration file for your own Shell commands instead of including everything in configuration.yaml. It’s required to add the line shell_command: !include shellcommand.yaml in the configuration.yaml file to let know homeassistant about the separation.

homeassistant/scripts/download.sh.
Shell script for homeassistant that will call the python script.

homeassistant/scripts/remove_download.sh Bonus shell script for removing the last movie added to radarr by this script.

Thank you to CyberPoison for the sonarr script and better guide.

Did you find this useful and would like to support my work?