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

Error return code 1 #2

Closed IIIdefconIII closed 5 years ago

IIIdefconIII commented 6 years ago

sep 17 01:28:41 HTPC-01 hass[1803]: 2018-09-17 01:28:41 ERROR (MainThread) [homeassistant.components.shell_command] Error running command:/home/homeassistant/.homeassistant/download.sh "{{movie}}" 0`, return code: 1

Cant get it to work


############################################
##                 RADARR                 ##
############################################
homeassistant:
  customize:

###### SHELL COMMAND--------------------------------------------
shell_command:
  download_movie: /home/homeassistant/.homeassistant/download.sh "{{movie}}" 0
  search_movie: /home/homeassistant/.homeassistant/download.sh "{{movie}}" 1
  download_option: /home/homeassistant/.homeassistant/download.sh "{{option}}" 2

###### PANELS -------------------------------------------------
panel_iframe:
  radarr:
    title: 'Radarr Movies Download'
    icon: mdi:movie
    url: 'http://10.3.1.2:7878'

###### SCRIPTS -------------------------------------------------
script:
  download_movie:
    alias: download_movie
    sequence:
    - service: shell_command.download_movie
      data_template:
        movie: '{{ movie }}'

  search_movie:
    alias: search_movie
    sequence:
    - service: shell_command.search_movie
      data_template:
        movie: '{{ movie }}'

  download_option:
    alias: download_option
    sequence:
    - service: shell_command.download_option
      data_template:
        option: '{{ option }}'

`

IIIdefconIII commented 6 years ago

https://github.com/IIIdefconIII/homeassistant/tree/master

avraham commented 6 years ago

Ok. First of all let's make sure the script works when we execute it from the console.

Uncomment line 162 in hass_radarr_search_by_voice.py to get additional feedback from the console. Go to the directory where you saved the file hass_radarr_search_by_voice.py and try python ./hass_radarr_search_by_voice.py "deadpool" "0"

It should let you know it added deadpool 2, if it's not working then you might be missing something of the User defined variables at the beginning of the file.

IIIdefconIII commented 5 years ago

Sorry for the late respons, my whole home assistant crashed after update and i had to start over: Im at the point of testing this again. I did what you ask for and im getting:

htpc@HTPC-01:/home/homeassistant/.homeassistant$ python ./hass_radarr_search_by_voice.py "deadpool" "0"
Traceback (most recent call last):
  File "./hass_radarr_search_by_voice.py", line 2, in <module>
    import requests
ImportError: No module named requests

maybe its good to mention that this is in a virtual envoirement

EDIT:

homeassistant@HTPC-01:/srv/homeassistant$ pip3 install requests
Requirement already satisfied: requests in /usr/local/lib/python3.6/dist-packages (2.19.1)
Requirement already satisfied: urllib3<1.24,>=1.21.1 in /usr/local/lib/python3.6/dist-packages (from requests) (1.23)
Requirement already satisfied: idna<2.8,>=2.5 in /usr/local/lib/python3.6/dist-packages (from requests) (2.7)
Requirement already satisfied: chardet<3.1.0,>=3.0.2 in /usr/lib/python3/dist-packages (from requests) (3.0.4)
Requirement already satisfied: certifi>=2017.4.17 in /usr/local/lib/python3.6/dist-packages (from requests) (2018.8.24)
avraham commented 5 years ago

I forgot about the dependency. Did it work after installing the requests module?

IIIdefconIII commented 5 years ago

No it doesnt as you see im my previous command the request module is already installed, but its only installed in the virtual envoirement, not localy. so i did

sudo -u homeassistant -H -s pip3 install request

avraham commented 5 years ago

I don't have experience with virtual environments and how this could affect the way a script is run.

IIIdefconIII commented 5 years ago

Im getting the same error outside the python env so it has nothing to do with that. i doo see request in usr/local/lib/python3.6/dist-packages

pip list:

request 1.0.2
requests 2.19.1

ok i got it running after reinstaller request. not sure if this is 100% correctly but i did:

pip uninstall request pip install request pip2 install request pip3 install request

and now when i run the python script it returns a deadpool 0 output but no movie is added in radarr

IIIdefconIII commented 5 years ago

wow this is great! the python script does work, but when i use the

python ./hass_radarr_search_by_voice.py "deadpool" "0" command it add deadpool 2 instead :D

avraham commented 5 years ago

It's great you got it working after all. My guess is you probably have python 2 and 3 versions installed, but the requests module was only installed on python3, and for some reason the script is being executed by python2, once you used pip and pip3 to install the module again that did the trick.

Yeah, deadpool 2 is the expected behavior for mode "0" (best guess from recent and upcoming years). It narrows the search between 2 years ago from the current year and the next year. The intended use for this mode is to add 'new' movies with the given full or partial title.

For older movies or in cases where the script is not guessing right, there's mode "1" (search), which will search the given full or partial title and offer you 3 options found for you to add. It may not be ideal to narrow the search to 3 results, but it should be good enough most of the time.

In the case of any movie title that includes a number written as a word instead of a numeric character (like three seconds), I found out that google assistant tends to transcript the voice search into '3 seconds', which messes up the results.

If you have any ideas of how this can be improved I would appreciate it.

IIIdefconIII commented 5 years ago

What do i have to say to google? when i say ok google, download movie, or download movie redline, nothing happens? doe i NEED to iftt to get this working by voice?

avraham commented 5 years ago

Yes, you need to either use IFTTT or to follow the google home component instructions. I provide some screenshots as example of my IFTTT setup.

I want to note that for movies older than 2 years the search command has to be used. The download command (which searches and automatically adds the movie) was purposely designed to search for newish movies only, so it can quickly add movies with a high successful rate without worrying about older movies with the same or very similar title.

I might rework the script for a more general use, where the scope of the download command isn't limited and in case of multiple movies with the same title it would offers the options to choose from.

IIIdefconIII commented 5 years ago

I have google assistant component setup and working but it doesn download anything

Op di 9 okt. 2018 om 21:06 schreef Abraham Valenzuela < notifications@github.com>:

Yes, you need to either use IFTTT or to follow the google home component https://www.home-assistant.io/components/google_assistant/ instructions. I provide some screenshots as example of my IFTTT setup.

I want to note that for movies older than 2 years the search command has to be used. The download command (which searches and automatically adds the movie) was purposely designed to search for newish movies only, so it can quickly add movies with a high successful rate without worrying about older movies with the same or very similar title.

I might rework the script for a more general use, where the scope of the download command isn't limited and in case of multiple movies with the same title it would offers the options to choose from.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/avraham/hass_radarr_search_by_voice/issues/2#issuecomment-428313002, or mute the thread https://github.com/notifications/unsubscribe-auth/AJdU24HHHQTE7m62TTrZGzpk0IDmr7pVks5ujPOvgaJpZM4WrGWU .

-- Met vriendelijke Groet,

Thomas van Dalen E: thomasvdalen@gmail.com T: 06 239 88 343

avraham commented 5 years ago

Actually, I have no idea how it would work without IFTTT.

IFTTT recipes allow to define variables within a voice command, so these variables are used for sending the data to home assistant when calling the script

sinker1345 commented 5 years ago

I had the same issue. I fixed it by adding #!/usr/bin/env python3 to the very beginning of the hass_radarr_search_by_voice.py file and editing download.sh as follows, response=$(python3 /home/homeassistant/.homeassistant/hass_radarr_search_by_voice.py "$movie" "$mode").

Once those edits were complete the script worked normally. I'm on my phone ATM but I can add more info or create a pull request if need be.