mirror of
https://github.com/thorsten-gehrig/alexa-remote-control.git
synced 2024-11-22 16:59:03 +01:00
Added Alexa routines execution
This commit is contained in:
parent
da697c39d1
commit
b8a082b64c
@ -34,6 +34,7 @@
|
|||||||
# https://github.com/openhab/openhab2-addons/tree/master/addons/binding/org.openhab.binding.amazonechocontrol
|
# https://github.com/openhab/openhab2-addons/tree/master/addons/binding/org.openhab.binding.amazonechocontrol
|
||||||
# (thanks to Ralf Otto for implementing this feature in this script)
|
# (thanks to Ralf Otto for implementing this feature in this script)
|
||||||
# 2018-06-13: v0.10a added album play of imported library
|
# 2018-06-13: v0.10a added album play of imported library
|
||||||
|
# 2018-06-18: v0.10b added Alex routine execution
|
||||||
#
|
#
|
||||||
###
|
###
|
||||||
#
|
#
|
||||||
@ -82,6 +83,7 @@ LIST=""
|
|||||||
LOGOFF=""
|
LOGOFF=""
|
||||||
COMMAND=""
|
COMMAND=""
|
||||||
TTS=""
|
TTS=""
|
||||||
|
UTTERANCE=""
|
||||||
SEQUENCECMD=""
|
SEQUENCECMD=""
|
||||||
STATIONID=""
|
STATIONID=""
|
||||||
QUEUE=""
|
QUEUE=""
|
||||||
@ -106,7 +108,7 @@ usage()
|
|||||||
echo " -i | -p | -P | -S | -a | -m <multiroom_device> [device_1 .. device_X] | -lastalexa | -l | -h"
|
echo " -i | -p | -P | -S | -a | -m <multiroom_device> [device_1 .. device_X] | -lastalexa | -l | -h"
|
||||||
echo
|
echo
|
||||||
echo " -e : run command, additional SEQUENCECMDs:"
|
echo " -e : run command, additional SEQUENCECMDs:"
|
||||||
echo " weather,traffic,flashbriefing,goodmorning,singasong,tellstory,speak:'<text>'"
|
echo " weather,traffic,flashbriefing,goodmorning,singasong,tellstory,speak:'<text>',automation:'<routine name>'"
|
||||||
echo " -b : connect/disconnect/list bluetooth device"
|
echo " -b : connect/disconnect/list bluetooth device"
|
||||||
echo " -q : query queue"
|
echo " -q : query queue"
|
||||||
echo " -r : play tunein radio"
|
echo " -r : play tunein radio"
|
||||||
@ -307,9 +309,13 @@ case "$COMMAND" in
|
|||||||
;;
|
;;
|
||||||
speak:*)
|
speak:*)
|
||||||
SEQUENCECMD='Alexa.Speak'
|
SEQUENCECMD='Alexa.Speak'
|
||||||
TTS=$(echo ${COMMAND##*:} | sed -r 's/[^-a-zA-Z0-9_,?!]//g')
|
TTS=$(echo ${COMMAND##*:} | sed -r 's/[^-a-zA-Z0-9_,?! ]//g' | sed 's/ /_/g')
|
||||||
TTS=",\\\"textToSpeak\\\":\\\"${TTS}\\\""
|
TTS=",\\\"textToSpeak\\\":\\\"${TTS}\\\""
|
||||||
;;
|
;;
|
||||||
|
automation:*)
|
||||||
|
SEQUENCECMD='automation'
|
||||||
|
UTTERANCE=$(echo ${COMMAND##*:} | sed -r 's/[^-a-zA-Z0-9_,?! ]//g')
|
||||||
|
;;
|
||||||
weather)
|
weather)
|
||||||
SEQUENCECMD='Alexa.Weather.Play'
|
SEQUENCECMD='Alexa.Weather.Play'
|
||||||
;;
|
;;
|
||||||
@ -469,8 +475,29 @@ run_cmd()
|
|||||||
{
|
{
|
||||||
if [ -n "${SEQUENCECMD}" ]
|
if [ -n "${SEQUENCECMD}" ]
|
||||||
then
|
then
|
||||||
|
if [ "${SEQUENCECMD}" = 'automation' ] ; then
|
||||||
|
|
||||||
|
${CURL} ${OPTS} -s -b ${COOKIE} -A "${BROWSER}" -H "DNT: 1" -H "Connection: keep-alive" -L\
|
||||||
|
-H "Content-Type: application/json; charset=UTF-8" -H "Referer: https://alexa.${AMAZON}/spa/index.html" -H "Origin: https://alexa.${AMAZON}"\
|
||||||
|
-H "csrf: $(awk "\$0 ~/.${AMAZON}.*csrf[ \\s\\t]+/ {print \$7}" ${COOKIE})" -X GET \
|
||||||
|
"https://${ALEXA}/api/behaviors/automations" > "${TMP}/.alexa.automation"
|
||||||
|
|
||||||
|
AUTOMATION=$(jq --arg utterance "${UTTERANCE}" -r '.[] | select( .triggers[].payload.utterance == $utterance) | .automationId' "${TMP}/.alexa.automation")
|
||||||
|
if [ -z "${AUTOMATION}" ] ; then
|
||||||
|
echo "ERROR: no such utterance '${UTTERANCE}' in Alexa routines"
|
||||||
|
rm -f "${TMP}/.alexa.automation"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
SEQUENCE=$(jq --arg utterance "${UTTERANCE}" -rc '.[] | select( .triggers[].payload.utterance == $utterance) | .sequence' "${TMP}/.alexa.automation" | sed 's/"/\\"/g' | sed "s/ALEXA_CURRENT_DEVICE_TYPE/${DEVICETYPE}/g" | sed "s/ALEXA_CURRENT_DSN/${DEVICESERIALNUMBER}/g" | sed "s/ALEXA_CUSTOMER_ID/${MEDIAOWNERCUSTOMERID}/g" | sed 's/ /_/g')
|
||||||
|
rm -f "${TMP}/.alexa.automation"
|
||||||
|
|
||||||
|
echo "Running routine: ${UTTERANCE}"
|
||||||
|
COMMAND="{\"behaviorId\":\"${AUTOMATION}\",\"sequenceJson\":\"${SEQUENCE}\",\"status\":\"ENABLED\"}"
|
||||||
|
else
|
||||||
echo "Sequence command: ${SEQUENCECMD}"
|
echo "Sequence command: ${SEQUENCECMD}"
|
||||||
COMMAND="{\"behaviorId\":\"PREVIEW\",\"sequenceJson\":\"{\\\"@type\\\":\\\"com.amazon.alexa.behaviors.model.Sequence\\\",\\\"startNode\\\":{\\\"@type\\\":\\\"com.amazon.alexa.behaviors.model.OpaquePayloadOperationNode\\\",\\\"type\\\":\\\"${SEQUENCECMD}\\\",\\\"operationPayload\\\":{\\\"deviceType\\\":\\\"${DEVICETYPE}\\\",\\\"deviceSerialNumber\\\":\\\"${DEVICESERIALNUMBER}\\\",\\\"locale\\\":\\\"${LANGUAGE}\\\",\\\"customerId\\\":\\\"${MEDIAOWNERCUSTOMERID}\\\"${TTS}}}}\",\"status\":\"ENABLED\"}"
|
COMMAND="{\"behaviorId\":\"PREVIEW\",\"sequenceJson\":\"{\\\"@type\\\":\\\"com.amazon.alexa.behaviors.model.Sequence\\\",\\\"startNode\\\":{\\\"@type\\\":\\\"com.amazon.alexa.behaviors.model.OpaquePayloadOperationNode\\\",\\\"type\\\":\\\"${SEQUENCECMD}\\\",\\\"operationPayload\\\":{\\\"deviceType\\\":\\\"${DEVICETYPE}\\\",\\\"deviceSerialNumber\\\":\\\"${DEVICESERIALNUMBER}\\\",\\\"locale\\\":\\\"${LANGUAGE}\\\",\\\"customerId\\\":\\\"${MEDIAOWNERCUSTOMERID}\\\"${TTS}}}}\",\"status\":\"ENABLED\"}"
|
||||||
|
fi
|
||||||
|
echo $COMMAND
|
||||||
|
|
||||||
${CURL} ${OPTS} -s -b ${COOKIE} -A "${BROWSER}" -H "DNT: 1" -H "Connection: keep-alive" -L\
|
${CURL} ${OPTS} -s -b ${COOKIE} -A "${BROWSER}" -H "DNT: 1" -H "Connection: keep-alive" -L\
|
||||||
-H "Content-Type: application/json; charset=UTF-8" -H "Referer: https://alexa.${AMAZON}/spa/index.html" -H "Origin: https://alexa.${AMAZON}"\
|
-H "Content-Type: application/json; charset=UTF-8" -H "Referer: https://alexa.${AMAZON}/spa/index.html" -H "Origin: https://alexa.${AMAZON}"\
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
# Amazon Alexa Remote Control (PLAIN shell)
|
# Amazon Alexa Remote Control (PLAIN shell)
|
||||||
# alex(at)loetzimmer.de
|
# alex(at)loetzimmer.de
|
||||||
#
|
#
|
||||||
# 2018-06-13: v0.10a (for updates see http://blog.loetzimmer.de/2017/10/amazon-alexa-hort-auf-die-shell-echo.html)
|
# 2018-06-18: v0.10b (for updates see http://blog.loetzimmer.de/2017/10/amazon-alexa-hort-auf-die-shell-echo.html)
|
||||||
#
|
#
|
||||||
###
|
###
|
||||||
#
|
#
|
||||||
@ -260,7 +260,7 @@ case "$COMMAND" in
|
|||||||
;;
|
;;
|
||||||
speak:*)
|
speak:*)
|
||||||
SEQUENCECMD='Alexa.Speak'
|
SEQUENCECMD='Alexa.Speak'
|
||||||
TTS=$(echo ${COMMAND##*:} | sed -r 's/[^-a-zA-Z0-9_,?!]//g')
|
TTS=$(echo ${COMMAND##*:} | sed -r 's/[^-a-zA-Z0-9_,?! ]//g' | sed 's/ /_/g')
|
||||||
TTS=",\\\"textToSpeak\\\":\\\"${TTS}\\\""
|
TTS=",\\\"textToSpeak\\\":\\\"${TTS}\\\""
|
||||||
;;
|
;;
|
||||||
weather)
|
weather)
|
||||||
@ -481,6 +481,7 @@ if [ -n "${SEQUENCECMD}" ]
|
|||||||
then
|
then
|
||||||
echo "Sequence command: ${SEQUENCECMD}"
|
echo "Sequence command: ${SEQUENCECMD}"
|
||||||
COMMAND="{\"behaviorId\":\"PREVIEW\",\"sequenceJson\":\"{\\\"@type\\\":\\\"com.amazon.alexa.behaviors.model.Sequence\\\",\\\"startNode\\\":{\\\"@type\\\":\\\"com.amazon.alexa.behaviors.model.OpaquePayloadOperationNode\\\",\\\"type\\\":\\\"${SEQUENCECMD}\\\",\\\"operationPayload\\\":{\\\"deviceType\\\":\\\"${DEVICETYPE}\\\",\\\"deviceSerialNumber\\\":\\\"${DEVICESERIALNUMBER}\\\",\\\"locale\\\":\\\"${LANGUAGE}\\\",\\\"customerId\\\":\\\"${MEDIAOWNERCUSTOMERID}\\\"${TTS}}}}\",\"status\":\"ENABLED\"}"
|
COMMAND="{\"behaviorId\":\"PREVIEW\",\"sequenceJson\":\"{\\\"@type\\\":\\\"com.amazon.alexa.behaviors.model.Sequence\\\",\\\"startNode\\\":{\\\"@type\\\":\\\"com.amazon.alexa.behaviors.model.OpaquePayloadOperationNode\\\",\\\"type\\\":\\\"${SEQUENCECMD}\\\",\\\"operationPayload\\\":{\\\"deviceType\\\":\\\"${DEVICETYPE}\\\",\\\"deviceSerialNumber\\\":\\\"${DEVICESERIALNUMBER}\\\",\\\"locale\\\":\\\"${LANGUAGE}\\\",\\\"customerId\\\":\\\"${MEDIAOWNERCUSTOMERID}\\\"${TTS}}}}\",\"status\":\"ENABLED\"}"
|
||||||
|
echo $COMMAND
|
||||||
|
|
||||||
${CURL} ${OPTS} -s -b ${COOKIE} -A "${BROWSER}" -H "DNT: 1" -H "Connection: keep-alive" -L\
|
${CURL} ${OPTS} -s -b ${COOKIE} -A "${BROWSER}" -H "DNT: 1" -H "Connection: keep-alive" -L\
|
||||||
-H "Content-Type: application/json; charset=UTF-8" -H "Referer: https://alexa.${AMAZON}/spa/index.html" -H "Origin: https://alexa.${AMAZON}"\
|
-H "Content-Type: application/json; charset=UTF-8" -H "Referer: https://alexa.${AMAZON}/spa/index.html" -H "Origin: https://alexa.${AMAZON}"\
|
||||||
|
Loading…
Reference in New Issue
Block a user