NOTE This script is no longer required. All options now supported in @ keatontaylor custom component
I have been fighting to run the https://loetzimmer.de/patches/alexa_remote_control.sh in Hass.io
After some time I think I have a workable solution
I have created a new post as the original post is enormous and the information is now difficult to extract
This solution is for Hass.io and It will be a long post so ābare with meā
Before I begin . I would recommend anybody using Haas.io to use the excellent custom media player
This will give you TTS and has been extremely reliable in my Hass.io setup. However, it does not have all the features of the alexa_remote_control.sh script.
This post assumes you have SSH access to your Hass.io setup and you have edited the script with the correct website and login details. I am from the UK so unsure if this information is accurate anywhere else.
The first issue in running the alexa_remote_control.sh in Hass.io ( and just about every other environment) is
the following error
cookie does not exist. logging in ...
ERROR: Amazon Login was unsuccessful. Possibly you get a captcha login screen.
Try logging in to https://alexa.amazon.com with your browser. In your browser
make sure to have all Amazon related cookies deleted and Javascript disabled!
This is caused by the script logging into Amazon site and being asked for a captua authentification. If you are very lucky it may work, but the majority of the time it will fail with the above error.
Run the following command ls /tmp -la and you will find an .alexa.login file. For the script to run successfully, it needs to create a .alexa.cookie file. I have tried lots of methods to create this file, all involving copying cookie files from working systems. None have worked all have said cookie expired The only solution that has worked for me is setting up two-factor authentication on the amazon site and using the Authenticator App on my mobile phone. see
https://www.amazon.co.uk/gp/help/customer/display.html?nodeId=202073820
Once your Authenticator app is generating 6 digits codes for the Amazon site. You can append the 6 digits to the end of your password in the alexa_remote_control.sh script. run alexa_remote_control.sh -a to force a login
The extra authentification in the script will bypass the captua authentification and will work correctly. Confirm you have the .alexa.cookie in the \tmp folder by running ls /tmp -la
Remove the 6 digits code from the alexa_remote_control.sh once you have the .alexa.cookie file. This cookie will eventually expire and the keeping the password + the code will ensure the script will never log in again!
Once you have a script which works, you have a second major issue. Hass.io does not support command line sensors, switches or shell commands. So you cannot integrate the script into HA!
https://www.home-assistant.io/hassio/run_local/
Fortunately, I found python scripts do run correctly from the shell and command line sensors. I cannot claim any originality in this insite, just plenty of googling this forum.
You will need to ensure all the files required for alexa_remote_control.sh, reside in the same folder. So I created /config/alexa folder using mkdir /config/alexa command. Copy the alexa_remote_control.sh and the .alexa.cookie from the /tmp folder cp /tmp/.alexa.cookie /config/alexa/.alexa.cookie
You will then need to edit the alexa_remote_control.sh file and change the following line to ensure everything runs in the same dir
TMP=ā/config/alexaā
confirm the script is still working, you may have to recreate the .alexa.cookie file. Then create the following file in the /config/alexa folder
import subprocess
import sys
params = sys.argv[1]
cmd = "/config/alexa/alexa_remote_control.sh " + params
x = subprocess.check_output(cmd, shell=True)
print(x.decode("utf-8"))
Save this as alexa_wrapper.py. This creates a wrapper file to allow the shell scripts to work in Hass.io. Run chmod +x /config/alexa/alexa_wrapper.py to make is executable.
Now you can create the following in HA
command line sensor
- platform: command_line
name: Last Alexa
command: 'python3 /config/alexa/alexa_wrapper.py {{ "-lastalexa" }}'
Shell command
alexa: 'python3 /config/alexa/alexa_wrapper.py "{{ params }}"'
The last Alexa sensor will update with the last Alexa to receive a command
The shell command will take any parameters the alexa_remote.control will accept. Ensure you wrap commands with the correct quotes. Run this from the developerās tools services to test
{āparamsā:ā-d āname of echoā -e speak:ātesting testingāā}
I do not know how long the cookie will last before it expires, but the last alexa sensor should keep the connection alive. I have been running for about 4 days now without issue
hope this helps. thanks for reading to the end