PR #109 Added textcommand

Added textcommand which lets you send anything via CLI you would otherwise say to Alexa
This commit is contained in:
Alex 2020-12-12 21:47:23 +01:00 committed by GitHub
commit 3a290675d1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 104 additions and 88 deletions

162
README.md
View File

@ -1,80 +1,82 @@
# alexa-remote-control # alexa-remote-control
control Amazon Alexa from command Line control Amazon Alexa from command Line
The settings can now be controlled via environment variables. The settings can now be controlled via environment variables.
``` ```
EMAIL - your login email EMAIL - your login email
PASSWORD - your login password PASSWORD - your login password
BROWSER - the User-Agent your browser sends in the request header BROWSER - the User-Agent your browser sends in the request header
LANGUAGE - the Accept-Language your browser sends in the request header LANGUAGE - the Accept-Language your browser sends in the request header
AMAZON - your Amazon domain AMAZON - your Amazon domain
ALEXA - the URL you would use for the Alexa Web App ALEXA - the URL you would use for the Alexa Web App
CURL - location of your cURL binary CURL - location of your cURL binary
OPTS - any cURL options you require OPTS - any cURL options you require
TMP - location of the temp dir TMP - location of the temp dir
OATHTOOL - command line for oathtool MFA OATHTOOL - command line for oathtool MFA
MFA_SECRET- the MFA secret MFA_SECRET- the MFA secret
SPEAKVOL - the volume for speak messages ( if set to 0, volume levels are left untouched) SPEAKVOL - the volume for speak messages ( if set to 0, volume levels are left untouched)
NORMALVOL - if no current playing volume can be determined, fall back to normal volume NORMALVOL - if no current playing volume can be determined, fall back to normal volume
VOLMAXAGE - max. age in minutes before volume is re-read from API VOLMAXAGE - max. age in minutes before volume is re-read from API
DEVICEVOLNAME - a list of device names with specific volume settings (space separated) DEVICEVOLNAME - a list of device names with specific volume settings (space separated)
DEVICEVOLSPEAK - a list of speak volume levels - matching the devices above DEVICEVOLSPEAK - a list of speak volume levels - matching the devices above
DEVICEVOLNORMAL - a list of normal volume levels- matching the devices above DEVICEVOLNORMAL - a list of normal volume levels- matching the devices above
(current playing volume takes precedence for normal volume) (current playing volume takes precedence for normal volume)
USE_ANNOUNCEMENT_FOR_SPEAK - Announcements can be made to multiple devices, while USE_ANNOUNCEMENT_FOR_SPEAK - Announcements can be made to multiple devices, while
regular SPEAK cannot but the announcement feature has regular SPEAK cannot but the announcement feature has
to be turned on for those devices. Also supports SSML! to be turned on for those devices. Also supports SSML!
``` ```
You will very likely want to set the language to: You will very likely want to set the language to:
``` ```
export LANGUAGE='de,en-US;q=0.7,en;q=0.3' export LANGUAGE='de,en-US;q=0.7,en;q=0.3'
``` ```
``` ```
alexa-remote-control [-d <device>|ALL] -e <pause|play|next|prev|fwd|rwd|shuffle|repeat|vol:<0-100>> | alexa-remote-control [-d <device>|ALL] -e <pause|play|next|prev|fwd|rwd|shuffle|repeat|vol:<0-100>> |
-b [list|<"AA:BB:CC:DD:EE:FF">] | -q | -n | -r <"station name"|stationid> | -b [list|<"AA:BB:CC:DD:EE:FF">] | -q | -n | -r <"station name"|stationid> |
-s <trackID|'Artist' 'Album'> | -t <ASIN> | -u <seedID> | -v <queueID> | -s <trackID|'Artist' 'Album'> | -t <ASIN> | -u <seedID> | -v <queueID> |
-w <playlistId> | -i | -p | -P | -S | -a | -z | -l | -h | -w <playlistId> | -i | -p | -P | -S | -a | -z | -l | -h |
-m <multiroom_device> [device_1 .. device_X] | -lastalexa | -lastcommand -m <multiroom_device> [device_1 .. device_X] | -lastalexa | -lastcommand
-e : run command, additional SEQUENCECMDs: -e : run command, additional SEQUENCECMDs:
weather,traffic,flashbriefing,goodmorning,singasong,tellstory, weather,traffic,flashbriefing,goodmorning,singasong,tellstory,
speak:'<text/ssml>',automation:'<routine name>,sound:<soundeffect_name>' speak:'<text/ssml>',automation:'<routine name>',sound:<soundeffect_name>,
-b : connect/disconnect/list bluetooth device textcommand:'<anything you would otherwise say to Alexa>'
-q : query queue
-n : query notifications -b : connect/disconnect/list bluetooth device
-r : play tunein radio -q : query queue
-s : play library track/library album -n : query notifications
-t : play Prime playlist -r : play tunein radio
-u : play Prime station -s : play library track/library album
-v : play Prime historical queue -t : play Prime playlist
-w : play library playlist -u : play Prime station
-i : list imported library tracks -v : play Prime historical queue
-p : list purchased library tracks -w : play library playlist
-P : list Prime playlists -i : list imported library tracks
-S : list Prime stations -p : list purchased library tracks
-a : list available devices -P : list Prime playlists
-m : delete multiroom and/or create new multiroom containing devices -S : list Prime stations
-lastalexa : print device that received the last voice command -a : list available devices
-lastcommand : print last voice command or last voice command of specific device -m : delete multiroom and/or create new multiroom containing devices
-login : Logs in, without further command (downloads cookie) -lastalexa : print device that received the last voice command
-z : print current volume level -lastcommand : print last voice command or last voice command of specific device
-l : logoff -login : Logs in, without further command (downloads cookie)
-h : help -z : print current volume level
``` -l : logoff
-h : help
There's also a "plain" version, which lacks some functionality (-z, -i, -p, -P, -S and no radio station names and no routines) but doesn't require 'jq' for JSON processing. ```
In order to use MFA, one needs to obtain the MFA_SECRET from Amazon account: There's also a "plain" version, which lacks some functionality (-z, -i, -p, -P, -S and no radio station names and no routines) but doesn't require 'jq' for JSON processing.
1. You should have MFA using an App already working before proceeding
1. Add a new app In order to use MFA, one needs to obtain the MFA_SECRET from Amazon account:
1. When presented with the QR-code select "can't scan code" 1. You should have MFA using an App already working before proceeding
1. You will be presented with the MFA shared secret, something like `1234 5678 9ABC DEFG HIJK LMNO PQRS TUVW XYZ0 1234 5678 9ABC DEFG` 1. Add a new app
1. Now you have to generate a valid response code via `oathtool -b --totp "<MFA shared secret from above>"` and enter that in the web form 1. When presented with the QR-code select "can't scan code"
1. Going from here the MFA shared secret becomes the MFA_SECRET for the alexa_remote_control script 1. You will be presented with the MFA shared secret, something like `1234 5678 9ABC DEFG HIJK LMNO PQRS TUVW XYZ0 1234 5678 9ABC DEFG`
*Treat that MFA_SCECRET just like your password - DO NOT share it anywhere!!!* 1. Now you have to generate a valid response code via `oathtool -b --totp "<MFA shared secret from above>"` and enter that in the web form
1. Going from here the MFA shared secret becomes the MFA_SECRET for the alexa_remote_control script
It is assumed that MFA secured accounts are less likely to get a captcha response during login - that's why MFA might yield better results if the plain username/password didn't work for you. *Treat that MFA_SCECRET just like your password - DO NOT share it anywhere!!!*
http://blog.loetzimmer.de/2017/10/amazon-alexa-hort-auf-die-shell-echo.html It is assumed that MFA secured accounts are less likely to get a captcha response during login - that's why MFA might yield better results if the plain username/password didn't work for you.
http://blog.loetzimmer.de/2017/10/amazon-alexa-hort-auf-die-shell-echo.html

View File

@ -57,6 +57,8 @@
# 2020-06-15: v0.16b added "lastcommand" option # 2020-06-15: v0.16b added "lastcommand" option
# (thanks to Trinitus01 https://github.com/trinitus01) # (thanks to Trinitus01 https://github.com/trinitus01)
# 2020-07-07: v0.16c fixed NORMALVOL if USE_ANNOUNCEMENT_FOR_SPEAK is set # 2020-07-07: v0.16c fixed NORMALVOL if USE_ANNOUNCEMENT_FOR_SPEAK is set
# 2020-12-12: v0.17 added textcommand which lets you send anything via CLI you would otherwise say to Alexa
# ( https://github.com/thorsten-gehrig/alexa-remote-control/issues/108 )
# #
### ###
# #
@ -186,7 +188,8 @@ usage()
echo echo
echo " -e : run command, additional SEQUENCECMDs:" echo " -e : run command, additional SEQUENCECMDs:"
echo " weather,traffic,flashbriefing,goodmorning,singasong,tellstory," echo " weather,traffic,flashbriefing,goodmorning,singasong,tellstory,"
echo " speak:'<text/ssml>',automation:'<routine name>',sound:<soundeffect_name>" echo " speak:'<text/ssml>',automation:'<routine name>',sound:<soundeffect_name>,"
echo " textcommand:'<anything you would otherwise say to Alexa>'"
echo " -b : connect/disconnect/list bluetooth device" echo " -b : connect/disconnect/list bluetooth device"
echo " -q : query queue" echo " -q : query queue"
echo " -n : query notifications" echo " -n : query notifications"
@ -213,7 +216,7 @@ usage()
while [ "$#" -gt 0 ] ; do while [ "$#" -gt 0 ] ; do
case "$1" in case "$1" in
--version) --version)
echo "v0.16a" echo "v0.17"
exit 0 exit 0
;; ;;
-d) -d)
@ -410,6 +413,11 @@ case "$COMMAND" in
exit 1 exit 1
fi fi
;; ;;
textcommand:*)
SEQUENCECMD='Alexa.TextCommand\",\"skillId\":\"amzn1.ask.1p.tellalexa'
SEQUENCEVAL=$(echo ${COMMAND##textcommand:} | sed -r s/\"/\'/g)
SEQUENCEVAL=',\"text\":\"'${SEQUENCEVAL}'\"'
;;
speak:*) speak:*)
TTS=$(echo ${COMMAND##speak:} | sed -r s/\"/\'/g) TTS=$(echo ${COMMAND##speak:} | sed -r s/\"/\'/g)
if [ $USE_ANNOUNCEMENT_FOR_SPEAK -gt 0 ] ; then if [ $USE_ANNOUNCEMENT_FOR_SPEAK -gt 0 ] ; then
@ -650,7 +658,7 @@ if [ -n "${SEQUENCECMD}" ] ; then
ALEXACMD='{"behaviorId":"'${AUTOMATION}'","sequenceJson":"'${SEQUENCE}'","status":"ENABLED"}' ALEXACMD='{"behaviorId":"'${AUTOMATION}'","sequenceJson":"'${SEQUENCE}'","status":"ENABLED"}'
else else
# SequenceCommands are generally not supported on WHA devices # SequenceCommands are generally not supported on WHA devices
if echo $COMMAND | grep -q -E "weather|traffic|flashbriefing|goodmorning|singasong|tellstory|sound" ; then if echo $COMMAND | grep -q -E "weather|traffic|flashbriefing|goodmorning|singasong|tellstory|sound|textcommand" ; then
if [ "${DEVICEFAMILY}" = "WHA" ] ; then if [ "${DEVICEFAMILY}" = "WHA" ] ; then
echo "Skipping unsupported command: ${COMMAND} on dev:${DEVICE} type:${DEVICETYPE} serial:${DEVICESERIALNUMBER} family:${DEVICEFAMILY}" echo "Skipping unsupported command: ${COMMAND} on dev:${DEVICE} type:${DEVICETYPE} serial:${DEVICESERIALNUMBER} family:${DEVICEFAMILY}"
return return

View File

@ -3,7 +3,7 @@
# Amazon Alexa Remote Control (PLAIN shell) # Amazon Alexa Remote Control (PLAIN shell)
# alex(at)loetzimmer.de # alex(at)loetzimmer.de
# #
# 2020-07-07: v0.16c (for updates see http://blog.loetzimmer.de/2017/10/amazon-alexa-hort-auf-die-shell-echo.html) # 2020-12-12: v0.17 (for updates see http://blog.loetzimmer.de/2017/10/amazon-alexa-hort-auf-die-shell-echo.html)
# #
### ###
# #
@ -57,7 +57,7 @@ SET_SPEAKVOL="0"
SET_NORMALVOL="10" SET_NORMALVOL="10"
# Device specific volumes (overriding the above) # Device specific volumes (overriding the above)
SET_DEVICEVOLNAME="EchoDot2ndGen Echo1stGen" SET_DEVICEVOLNAME="EchoDot2ndGen Echo1stGen"
SET_DEVICEVOLSPEAK="100 30" SET_DEVICEVOLSPEAK="100 30"
SET_DEVICEVOLNORMAL="100 20" SET_DEVICEVOLNORMAL="100 20"
@ -121,7 +121,8 @@ usage()
echo echo
echo " -e : run command, additional SEQUENCECMDs:" echo " -e : run command, additional SEQUENCECMDs:"
echo " weather,traffic,flashbriefing,goodmorning,singasong,tellstory," echo " weather,traffic,flashbriefing,goodmorning,singasong,tellstory,"
echo " speak:'<text>'sound:<soundeffect_name>" echo " speak:'<text>',sound:<soundeffect_name>,"
echo " textcommand:'<anything you would otherwise say to Alexa>'"
echo " -b : connect/disconnect/list bluetooth device" echo " -b : connect/disconnect/list bluetooth device"
echo " -q : query queue" echo " -q : query queue"
echo " -n : query notifications" echo " -n : query notifications"
@ -142,7 +143,7 @@ usage()
while [ "$#" -gt 0 ] ; do while [ "$#" -gt 0 ] ; do
case "$1" in case "$1" in
--version) --version)
echo "v0.16a" echo "v0.17"
exit 0 exit 0
;; ;;
-d) -d)
@ -321,6 +322,11 @@ case "$COMMAND" in
exit 1 exit 1
fi fi
;; ;;
textcommand:*)
SEQUENCECMD='Alexa.TextCommand\",\"skillId\":\"amzn1.ask.1p.tellalexa'
SEQUENCEVAL=$(echo ${COMMAND##textcommand:} | sed -r s/\"/\'/g)
SEQUENCEVAL=',\"text\":\"'${SEQUENCEVAL}'\"'
;;
speak:*) speak:*)
TTS=$(echo ${COMMAND##*:} | sed -r 's/["\\]/ /g') TTS=$(echo ${COMMAND##*:} | sed -r 's/["\\]/ /g')
TTS=',\"textToSpeak\":\"'${TTS}'\"' TTS=',\"textToSpeak\":\"'${TTS}'\"'
@ -625,7 +631,7 @@ set_var()
run_cmd() run_cmd()
{ {
if [ -n "${SEQUENCECMD}" ] ; then if [ -n "${SEQUENCECMD}" ] ; then
if echo $COMMAND | grep -q -E "weather|traffic|flashbriefing|goodmorning|singasong|tellstory|speak|sound" ; then if echo $COMMAND | grep -q -E "weather|traffic|flashbriefing|goodmorning|singasong|tellstory|speak|sound|textcommand" ; then
if [ "${DEVICEFAMILY}" = "WHA" ] ; then if [ "${DEVICEFAMILY}" = "WHA" ] ; then
echo "Skipping unsupported command: ${COMMAND} on dev:${DEVICE} type:${DEVICETYPE} serial:${DEVICESERIALNUMBER} family:${DEVICEFAMILY}" echo "Skipping unsupported command: ${COMMAND} on dev:${DEVICE} type:${DEVICETYPE} serial:${DEVICESERIALNUMBER} family:${DEVICEFAMILY}"
return return