From 22f87e8e10129d710a767b91d0689f562499fe98 Mon Sep 17 00:00:00 2001 From: Martin Weber Date: Sun, 25 Aug 2019 17:18:04 +0200 Subject: [PATCH 1/5] extend alexa script with notification info --- alexa_remote_control.sh | 47 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 46 insertions(+), 1 deletion(-) diff --git a/alexa_remote_control.sh b/alexa_remote_control.sh index cf344dd..6149228 100755 --- a/alexa_remote_control.sh +++ b/alexa_remote_control.sh @@ -155,6 +155,7 @@ usage() echo " weather,traffic,flashbriefing,goodmorning,singasong,tellstory,speak:'',automation:''" echo " -b : connect/disconnect/list bluetooth device" echo " -q : query queue" + echo " -n : query notifications" echo " -r : play tunein radio" echo " -s : play library track/library album" echo " -t : play Prime playlist" @@ -302,6 +303,9 @@ while [ "$#" -gt 0 ] ; do -q) QUEUE="true" ;; + -n) + NOTIFICATIONS="true" + ;; -lastalexa) LASTALEXA="true" ;; @@ -771,6 +775,19 @@ show_queue() "https://${ALEXA}/api/np/queue?deviceSerialNumber=${DEVICESERIALNUMBER}&deviceType=${DEVICETYPE}" | jq '.' } +# +# show notifications and alarms +# +show_notifications() +{ + echo "/api/notifications" + ${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/notifications?deviceSerialNumber=${DEVICESERIALNUMBER}&deviceType=${DEVICETYPE}" + echo +} + # # deletes a multiroom device # @@ -860,7 +877,7 @@ rm -f ${COOKIE} rm -f ${TMP}/.alexa.*.list } -if [ -z "$LASTALEXA" -a -z "$BLUETOOTH" -a -z "$LEMUR" -a -z "$PLIST" -a -z "$HIST" -a -z "$SEEDID" -a -z "$ASIN" -a -z "$PRIME" -a -z "$TYPE" -a -z "$QUEUE" -a -z "$LIST" -a -z "$COMMAND" -a -z "$STATIONID" -a -z "$SONG" -a -n "$LOGOFF" ] ; then +if [ -z "$LASTALEXA" -a -z "$BLUETOOTH" -a -z "$LEMUR" -a -z "$PLIST" -a -z "$HIST" -a -z "$SEEDID" -a -z "$ASIN" -a -z "$PRIME" -a -z "$TYPE" -a -z "$QUEUE" -a -z "$NOTIFICATIONS" -a -z "$LIST" -a -z "$COMMAND" -a -z "$STATIONID" -a -z "$SONG" -a -n "$LOGOFF" ] ; then echo "only logout option present, logging off ..." log_off exit 0 @@ -919,6 +936,34 @@ if [ -n "$COMMAND" -o -n "$QUEUE" ] ; then echo fi fi +elif [ -n "$COMMAND" -o -n "$NOTIFICATIONS" ] ; then + if [ "${DEVICE}" = "ALL" ] ; then + while IFS= read -r DEVICE ; do + set_var + if [ -n "$COMMAND" ] ; then + echo "sending cmd:${COMMAND} to dev:${DEVICE} type:${DEVICETYPE} serial:${DEVICESERIALNUMBER} customerid:${MEDIAOWNERCUSTOMERID}" + run_cmd + # in order to prevent a "Rate exceeded" we need to delay the command + sleep 1 + echo + else + echo "notifications info for dev:${DEVICE} type:${DEVICETYPE} serial:${DEVICESERIALNUMBER}" + show_notifications + echo + fi + done < ${DEVALL} + else + set_var + if [ -n "$COMMAND" ] ; then + echo "sending cmd:${COMMAND} to dev:${DEVICE} type:${DEVICETYPE} serial:${DEVICESERIALNUMBER} customerid:${MEDIAOWNERCUSTOMERID}" + run_cmd + echo + else + echo "notifications info for dev:${DEVICE} type:${DEVICETYPE} serial:${DEVICESERIALNUMBER}" + show_notifications + echo + fi + fi elif [ -n "$LEMUR" ] ; then DEVICESERIALNUMBER=$(jq --arg device "${LEMUR}" -r '.devices[] | select(.accountName == $device and .deviceFamily == "WHA") | .serialNumber' ${DEVLIST}) if [ -n "$DEVICESERIALNUMBER" ] ; then From 045458d837757a4b3d943ca78a65efcb17b235cc Mon Sep 17 00:00:00 2001 From: Martin Weber <7472943+martinweu@users.noreply.github.com> Date: Sun, 25 Aug 2019 17:20:59 +0200 Subject: [PATCH 2/5] adapt readme --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 94673f2..d8d8726 100644 --- a/README.md +++ b/README.md @@ -24,7 +24,7 @@ export LANGUAGE='de,en-US;q=0.7,en;q=0.3' ``` alexa-remote-control [-d |ALL] -e > | - -b [list|<"AA:BB:CC:DD:EE:FF">] | -q | -r <"station name"|stationid> | + -b [list|<"AA:BB:CC:DD:EE:FF">] | -q | -n | -r <"station name"|stationid> | -s | -t | -u | -v | -w | -i | -p | -P | -S | -a | -l | -h | -m [device_1 .. device_X] | -lastalexa @@ -34,6 +34,7 @@ alexa-remote-control [-d |ALL] -e ',automation:'' -b : connect/disconnect/list bluetooth device -q : query queue + -n : query notifications -r : play tunein radio -s : play library track/library album -t : play Prime playlist From bf69335aee24fa254c979a5f1d22ca5dc007e05e Mon Sep 17 00:00:00 2001 From: Martin Weber Date: Sun, 25 Aug 2019 17:48:35 +0200 Subject: [PATCH 3/5] also add notifications in plain --- alexa_remote_control_plain.sh | 44 +++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/alexa_remote_control_plain.sh b/alexa_remote_control_plain.sh index b794c66..8ce379a 100755 --- a/alexa_remote_control_plain.sh +++ b/alexa_remote_control_plain.sh @@ -114,6 +114,7 @@ usage() echo " weather,traffic,flashbriefing,goodmorning,singasong,tellstory,speak:''" echo " -b : connect/disconnect/list bluetooth device" echo " -q : query queue" + echo " -n : query notifications" echo " -r : play tunein radio" echo " -s : play library track/library album" echo " -t : play Prime playlist" @@ -245,6 +246,9 @@ while [ "$#" -gt 0 ] ; do -q) QUEUE="true" ;; + -n) + NOTIFICATIONS="true" + ;; -lastalexa) LASTALEXA="true" ;; @@ -708,6 +712,18 @@ ${CURL} ${OPTS} -s -b ${COOKIE} -A "${BROWSER}" -H "DNT: 1" -H "Connection: keep "https://${ALEXA}/api/media/state?deviceSerialNumber=${DEVICESERIALNUMBER}&deviceType=${DEVICETYPE}" echo } +# +# show notifications and alarms +# +show_notifications() +{ + echo "/api/notifications" + ${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/notifications?deviceSerialNumber=${DEVICESERIALNUMBER}&deviceType=${DEVICETYPE}" + echo +} # # deletes a multiroom device @@ -856,6 +872,34 @@ if [ -n "$COMMAND" -o -n "$QUEUE" ] ; then echo fi fi +elif [ -n "$COMMAND" -o -n "$NOTIFICATIONS" ] ; then + if [ "${DEVICE}" = "ALL" ] ; then + while IFS= read -r DEVICE ; do + set_var + if [ -n "$COMMAND" ] ; then + echo "sending cmd:${COMMAND} to dev:${DEVICE} type:${DEVICETYPE} serial:${DEVICESERIALNUMBER} customerid:${MEDIAOWNERCUSTOMERID}" + run_cmd + # in order to prevent a "Rate exceeded" we need to delay the command + sleep 1 + echo + else + echo "notifications info for dev:${DEVICE} type:${DEVICETYPE} serial:${DEVICESERIALNUMBER}" + show_notifications + echo + fi + done < ${DEVALL} + else + set_var + if [ -n "$COMMAND" ] ; then + echo "sending cmd:${COMMAND} to dev:${DEVICE} type:${DEVICETYPE} serial:${DEVICESERIALNUMBER} customerid:${MEDIAOWNERCUSTOMERID}" + run_cmd + echo + else + echo "notifications info for dev:${DEVICE} type:${DEVICETYPE} serial:${DEVICESERIALNUMBER}" + show_notifications + echo + fi + fi elif [ -n "$LEMUR" ] ; then DEVICE="${LEMUR}" set_var From 834c7785fe9ad389de94082647583ef5e951aa50 Mon Sep 17 00:00:00 2001 From: Martin Weber Date: Sun, 25 Aug 2019 17:50:27 +0200 Subject: [PATCH 4/5] add linebreak --- alexa_remote_control_plain.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/alexa_remote_control_plain.sh b/alexa_remote_control_plain.sh index 8ce379a..a6b7a04 100755 --- a/alexa_remote_control_plain.sh +++ b/alexa_remote_control_plain.sh @@ -712,6 +712,7 @@ ${CURL} ${OPTS} -s -b ${COOKIE} -A "${BROWSER}" -H "DNT: 1" -H "Connection: keep "https://${ALEXA}/api/media/state?deviceSerialNumber=${DEVICESERIALNUMBER}&deviceType=${DEVICETYPE}" echo } + # # show notifications and alarms # From d9c9a02bf393b5d57e7b7b6149d98d6c9916465a Mon Sep 17 00:00:00 2001 From: Martin Weber Date: Sun, 25 Aug 2019 17:53:37 +0200 Subject: [PATCH 5/5] fix missing change in plain --- alexa_remote_control_plain.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/alexa_remote_control_plain.sh b/alexa_remote_control_plain.sh index a6b7a04..ac52f7c 100755 --- a/alexa_remote_control_plain.sh +++ b/alexa_remote_control_plain.sh @@ -814,7 +814,7 @@ rm -f ${DEVALL} rm -f ${COOKIE} } -if [ -z "$LASTALEXA" -a -z "$BLUETOOTH" -a -z "$LEMUR" -a -z "$PLIST" -a -z "$HIST" -a -z "$SEEDID" -a -z "$ASIN" -a -z "$QUEUE" -a -z "$COMMAND" -a -z "$STATIONID" -a -z "$SONG" -a -n "$LOGOFF" ] ; then +if [ -z "$LASTALEXA" -a -z "$BLUETOOTH" -a -z "$LEMUR" -a -z "$PLIST" -a -z "$HIST" -a -z "$SEEDID" -a -z "$ASIN" -a -z "$QUEUE" -a -z "$NOTIFICATIONS" -a -z "$COMMAND" -a -z "$STATIONID" -a -z "$SONG" -a -n "$LOGOFF" ] ; then echo "only logout option present, logging off ..." log_off exit 0