Montag, 20. September 2021

Alexa Remote Control Shell Script

 It's about time for a new post since a lot of things have changed over the course of the past four years.

First things first though, the good news is there's finally an almost official way to properly use the script with your Amazon Alexa. Luckily all major home automation projects became inspired by the idea of the original script and some inner workings have been discovered by people smarter than me. Michael Geramb of openHAB and Ingo Fischer of ioBroker came up with the idea to proxy the login to Amazon very similar to how a mobile app would.

The result was for example the nodeJs package alexa-cookie2 (by Ingo Fischer). Looking more closely at the result of the login process it became clear that only a single item is required for our purposes. Hence I created a small nodeJS app that will output the token after successfully completing the login.

As not everybody would want to install nodeJS (or run it in Docker) I created packaged binaries using the nodeJS packager pkg.

While the old login flow may still work (for some time) I strongly encourage everybody to try the new cleaner method.

You will have to do this only once - very likely not on the actual machine that is going to run the alexa_remote_control.sh script, but on your browser enabled workstation!

  1. Start the alexa-cookie-cli-<linux|macos|windows> on your workstation from the command-line
    (cli is important as the window might close otherwise!!!)
  2. Point your browser at http://127.0.0.1:8080/
  3. Login to Amazon
  4. Upon successful login the program will exit and return the refresh_token to the command-line output (something like Atnr|...)

This will be the value of the REFRESH_TOKEN environment variable in the alexa_remote_control.sh script. No need to store your precious password anymore!

There are some options that alter the behavior if you are not an amazon.de user. Run the binary with --help to see.

Quite a few changes might have gone unnoticed. One of the most important is the use of environment variables. While you can always edit the script (as I originally intended) and modify the settings there, every SET_ variable has it's counterpart in an environment variable (without the SET_ prefix). 

I am going to demonstrate that behavior by using a feature which also seems not to be well understood. There is individual volume level control by Echo device names. Assume you have three Echos:

DEVICEVOLNAME='Kitchen LivingRoom BedRoom'

and you want the TTS volumes to be different:

DEVICEVOLSPEAK='100 80 25'
(the list of volumes refers to each of the Echo devices)

By creating a wrapper script around alexa_remote_control.sh you could even do something like:

#!/bin/sh
# alexa.sh wrapper script
#
export REFRESH_TOKEN='Atnr|...'
export DEVICEVOLNAME='Kitchen LivingRoom BedRoom'

# hush, hush during evening/night time
H=$(date +%H)
if [ $H -ge 19 -o $H -le 7 ] ; then
        export DEVICEVOLSPEAK="80 50 12"
        export DEVICEVOLNORMAL="70 40 9"
else
        export DEVICEVOLSPEAK="100 80 25"
        export DEVICEVOLNORMAL="80 50 12"
fi

/some/path/alexa_remote_control.sh "$@"

133 Kommentare:

Unknown hat gesagt…

Awesome! Gotta try it out asap, thanks for continuous work you put into this :)

Dan hat gesagt…

Hello,
I would like to use alexa_remote_control.sh in a Rpi4 working in headless mode.

How can I get the token? Please help!

Thanks a lot,
Dan

Unknown hat gesagt…

Ich kann auch keinen Token erhalten. Fehlermeldung bei der WIN Version:
Error: You can try to get the cookie manually by opening http://localhost_8080/ with your browser. / null
Denke eine Ursache könnte sein , dass localhost:8080 in meinem Netzwerk nicht funktioniert. Gibt's noch eine andere Möglichkeit um an den Token zu kommen?

Maddin hat gesagt…

Mich würde mal interessieren, wie ich diese Datei auf meinem Raspi ausführen kann. Eine kleine Schritt für Schritt Anleitung wäre super.
Welche Datei brauche ich überhaupt. Ich habe einen Raspi mit Homebridge am laufen.

Alexander Noack hat gesagt…

Naja, du brauchst die Prozedur eigentlich genau ein Mal. Da ich für Linux_ARM auf Github kein Binary bauen konnte, führst du die passende Datei einfach auf deinem PC oder Mac aus. Folge einfach den Schritten 1.-4. oben

Alexander Noack hat gesagt…

I couldn't figure out how to build linux_arm on Github.
As you need this procedure only a single time, just run it on your x86 PC or Mac and follow steps 1.-4.

Alexander Noack hat gesagt…

alexa-cookie-cli-win-x64.exe --help
Die "Fehlermeldung" stammt aus dem originalen Code, darauf habe ich keinen Einfluss...
Wenn der Port 8080 bei dir belegt ist, kannst du mit "-P 8081" den Port auch umdefinieren.

Paddy hat gesagt…

Hast du eine Idee, warum ich das hier kriege beim Anmelden:

jq: error (at :1): date "6 Nov 2037 09:54:26 GMT" does not match format "%d %b %Y %H:%M:%S %Z"
ERROR: cookie retrieval with refresh_token didn't work

Den Token habe ich unter Windows Edge gemacht
Atnr|EwICIBLkHdc0HX..... und den 1:1 in das Script kopiert zwischen ''
Das Script läuft auf einem Homebridge Docker unter Synology

Was meinst du dazu? Paddy

Alexander Noack hat gesagt…

Hmmm, ich habe einen Workaround für das Jahr 2038 Problem auf 32-Bit Systemen gebaut. In deinem Datum steht 2037 - sollte also funktionieren.

Was bringt denn:
date -d "6 Nov 2037 09:54:26 GMT"
oder
date -d "@2141114066"
oder
date +"%d %b %Y %H:%M:%S %Z"
(jeweils im Docker Container ausführen!)

Paddy hat gesagt…

die bringen bei mir
Fri Nov 6 10:54:26 CET 2037
Fri Nov 6 10:54:26 CET 2037
16 Nov 2021 17:44:44 CET
hoffe es hilft dir & DANKE, dass du versuchst zu helfen!

Anonym hat gesagt…

Bei mir läuft JQ v1.5.1, dieser coder funktioniert bei mir:

echo '{"Expires":"6 Nov 2037 09:54:26 GMT"}' | jq -r '.Expires |= ( strptime("%d %b %Y %H:%M:%S %Z") | mktime ) | .Expires'

Markus Wennesheimer hat gesagt…

Erst mal vielen Dank für das script. Ich bin immer wieder begeistert.
Leider habe ich ein Problem mit der neuen Version:

root@rpi3:/home/pi# cd alexa/
root@rpi3:/home/pi/alexa# ./4alexa_remote_control.sh -a
cookie expired, logging in again ...
error: map_values is not defined
.response.tokens.cookies | to_entries[] | .key as $domain | .value[] | map_values(if . == true then "TRUE" elif . == false then "FALSE" else . end) | .Expires |= ( strptime("%d %b %Y %H:%M:%S %Z") | mktime ) | [(if .HttpOnly=="TRUE" then ("#HttpOnly_" + $domain) else $domain end), "TRUE", .Path, .Secure, .Expires, .Name, .Value] | @tsv error: strptime is not defined
.response.tokens.cookies | to_entries[] | .key as $domain | .value[] | map_values(if . == true then "TRUE" elif . == false then "FALSE" else . end) | .Expires |= ( strptime("%d %b %Y %H:%M:%S %Z") | mktime ) | [(if .HttpOnly=="TRUE" then ("#HttpOnly_" + $domain) else $domain end), "TRUE", .Path, .Secure, .Expires, .Name, .Value] | @tsv error: mktime is not defined
.response.tokens.cookies | to_entries[] | .key as $domain | .value[] | map_values(if . == true then "TRUE" elif . == false then "FALSE" else . end) | .Expires |= ( strptime("%d %b %Y %H:%M:%S %Z") | mktime ) | [(if .HttpOnly=="TRUE" then ("#HttpOnly_" + $domain) else $domain end), "TRUE", .Path, .Secure, .Expires, .Name, .Value] | @tsv 3 compile errors
ERROR: cookie retrieval with refresh_token didn't work
root@rpi3:/home/pi
Bitte kontaktiere mich Alexander privat. Hab noch Ideen.

Markus Wennesheimer hat gesagt…

Neue installation. Hurra geht auf rpi5.
Lösche vorherigen Beitrag. Ich WILL DIR was schenken Alexander. Schreib mir.
dein wennes

Tim Shriver hat gesagt…

Hi, Thank you for all of your work! When using the alexa-cookie-cli-win-x64, the only option that returns an error is the --logger. What am I doing wrong?

C:\Users\Tim\Downloads>alexa-cookie-cli-win-x64 -q -p amazon.com -a en-US -L en-US -P 8989 -l Alexa.txt
Alexa.txt undefined
C:\snapshot\alexa-cookie-cli\node_modules\alexa-cookie2\alexa-cookie.js:147
_options.logger && _options.logger('Alexa-Cookie: Use as Login-Amazon-URL: ' + _options.amazonPage);
^

TypeError: _options.logger is not a function
at initConfig (C:\snapshot\alexa-cookie-cli\node_modules\alexa-cookie2\alexa-cookie.js:147:37)
at AlexaCookie.generateAlexaCookie (C:\snapshot\alexa-cookie-cli\node_modules\alexa-cookie2\alexa-cookie.js:267:9)
at Object. (C:\snapshot\alexa-cookie-cli\cli.js)
at Module._compile (pkg/prelude/bootstrap.js:1751:22)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)
at Module.load (internal/modules/cjs/loader.js:863:32)
at Function.Module._load (internal/modules/cjs/loader.js:708:14)
at Function.runMain (pkg/prelude/bootstrap.js:1804:12)
at internal/main/run_main_module.js:17:47


Thank You In Adavance,

Tim

Kai hat gesagt…

Hallo!

Erstmal vielen, vielen Dank für das Script, funktioniert hervorragend und endlich kann meine Homematic auch Hinweise per Sprache ausgeben.

Mir ist aber ein kleines Sicherheitsproblem aufgefallen: Nach dem ersten Login wird der Amazon-Cookie standardmäßig in /tmp abgelegt, und das world readable (bei Standard-umask).

Das sollte entweder im Homedir sein, in einem Config-Folder, der nur vom User lesbar ist, oder wenn es schon /tmp sein muss dann sicherstellen, dass das chmod 0600 ist.

Auf einem Single-User-System oder einem Home Automation Raspi ist das im Prinzip egal, aber es könnte ja mal jemand das in einem Multiuser-Environment auszuführen und dann hat er seinen Amazon-Account für alle anderen User geöffnet.

Anonym hat gesagt…

Deshalb kann man das TMP Verzeichnis auch per Config oder ENV Var auch woanders hin verlegen.
Im ursprünglichen Artikel habe ich darauf verwiesen ;)

Anonym hat gesagt…

Try without the log option. This will just log to StdOut.

Anonym hat gesagt…

Hallo, tolle Arbeit! Die Authentification bekomme ich hin, mit -a werden mir alle Devices angezeigt. Aber leider verstehe ich die Syntax nicht ganz, um eine Device in der Lautstärke zu regeln. Ich habe Devicenamen und seine Soll-Lautstätle in der .sh unter DEVICEVOLNAME und DEVICEVOLNORMAL angepasst, wenn ich das .sh aber aufrufe (./alexa_remote_control.sh) bekomme ich die Ausgabe "no alexa command recieved". Irgendwie auch klar, weil ich das Skript ohne Paramter aufgerufen habe. Bei der beschriebenen Syntax ist z.B. kein Parameter "Setvolume" o.ä. als Kommando dabei. Wie ist der Aufruf zu tätigen, um einen Alexa Dot z.B. auf einen bestimmten Lautstärkewert zu setzen? Danke und frohes Fest, Max

RUBEN hat gesagt…

Thanks a lot for jour job Alexander, (from Madrid)
I was working with 2017 version, then I fixed the OTP by my own (we should join efforts, it tough me 1 week) Now I will try 2021 version as my routines stop working and now i need it to woork again with new Alexa api v2.

Just two questions, reviwing the script: if i use freshtoken method, is it needed to have the SET_MFA_SECRET= ? is it needed the /oauth binary?

Anonym hat gesagt…

Ah, ich habe es gefunden. '-e vol:0-100' . Wichtig und hilfreich war es, den Hauptartikel bzw. die zugehörigen Kommentare zu lesen :-)

Max

Michael hat gesagt…

Servus, ich habe ein kleines Problem mit dem Abspielen von TTS in die Standard Multiroom Gruppe Überall.

Fehlermeldung: ERROR: unkown device dev:Überall
In der .alexa.devicelist.txt steht komischerweise auch Ãberall drin. Vermutlich ein Problem mit der Codierung?

Wenn ich die Gruppe mal auf Keller ändere, dann funktioniert der Aufruf bash alexa_remote_control.sh -d Keller -e speak:Hallo

Mit
bash alexa_remote_control.sh -d Überall -e speak:Hallo
erhalte ich diese Fehlermeldung.

Kannst du dir das evtl. mal anschauen?

jmleglise hat gesagt…

Hi,

The script currently does not allow to control the volume of the music. (neither by -e vol: , nor by ENV SPEAKVOL ).

Could you add this command? It would be very useful. I see that it is possible with this URL : https://alexa.amazon.fr/api/np/command?
{"type":"VolumeLevelCommand","volumeLevel":20,"contentFocusClientId":null}

Alexander Noack hat gesagt…

By using the Refresh_Token, no username/Password/MFA_SECRET is required anymore. That's the cool thing about it :)

OATHTOOL is not required anymore either.

Alexander Noack hat gesagt…

Hast du die de_DE.UTF-8 Locale installiert? Es ist definitiv ein Problem mit der Kodierung.

Bei mir heiß die Gruppe übrigens auch "Überall"

Alexander Noack hat gesagt…

SPEAKVOL is only for setting the volume of SPEAK commands to a different level than the current playing volume.

To change the volume of a device while it is playing a stream you should use:
alexa_remote_control.sh -d DEVICE -e vol:20

Michael hat gesagt…

Nein, anscheinend nicht. Befehl locale spuckt folgendes aus:
loxberry@loxberry:~ $ locale
LANG=en_GB.UTF-8
LANGUAGE=
LC_CTYPE="en_GB.UTF-8"
LC_NUMERIC="en_GB.UTF-8"
LC_TIME="en_GB.UTF-8"
LC_COLLATE="en_GB.UTF-8"
LC_MONETARY="en_GB.UTF-8"
LC_MESSAGES="en_GB.UTF-8"
LC_PAPER="en_GB.UTF-8"
LC_NAME="en_GB.UTF-8"
LC_ADDRESS="en_GB.UTF-8"
LC_TELEPHONE="en_GB.UTF-8"
LC_MEASUREMENT="en_GB.UTF-8"
LC_IDENTIFICATION="en_GB.UTF-8"
LC_ALL=

Kann man das gefahrlos installieren?

Unknown hat gesagt…

Suuuuper Arbeit!!!
Funktionierte auf Anhieb.
Werde das in FHEM einsetzen.
Weiter so...

Friedemann hat gesagt…

Hallo Alexander,
erst mal vielen Dank für das grandiose Skript und die tollen Ideen dahinter. Eine Frage hätte ich noch:
Ich gehe davon aus, dass alle SSML Sprachelemente, die zwischen "speak" und "/speak" stehen, an den Amazon Prozessor gesendet werden. Wenn dem so ist, müssten also Probleme, dass diverse SSML TAGs funktionieren und andere nicht, vermutlich an Amazon liegen. Ist das so?
Beispielsweise funktionert das von dir gelistete "effect name="whispered" perfekt, aber ein " führt zur gleichen Meldung.

Idee?

Gruß
Friedemann

Friedemann hat gesagt…

Ah, hier werden nicht alle Zeichen demaskiert... 3. Versuch:
Beispielsweise funktionert das von dir gelistete "effect name="whispered" perfekt, aber ein "emotion name=excited" liefert mir die gesprochene Fehlermeldung:"Ich habe momentan Schwierigkeiten auf deinen "Simonses Skills" zuzugreifen. Dabei ist "Simonses" als Lautsprache zu verstehen. Ich habe keinen blassen Schimmer, was Alexa mir da sagen will. Muss ich erst einen Skill dazu installieren? Welchen Sprachumfang der SSML kann ich denn verwenden? Für mich wäre es zum Beispiel sehr interessant, englische Texte sprechen zu lassen, aber die Verwendung des Tags führt zur gleichen Meldung.

Anonym hat gesagt…

"Simon says" ist ein eingebauter Skill, zu deutsch "sprich mir nach".
Wenn die Ansage kommt, ist die SSML Syntax falsch oder evtl. wird ein nicht unterstütztes Feature verwendet.

Unknown hat gesagt…

THANK YOU!

Anonym hat gesagt…

Hallo Alex,

bei der aktuellen Version des Skriptes auf Github (v0.20e) funktioniert das Login mittels Refresh_Token nicht:

cookie expired, logging in again ...
date: invalid date '8 Sep 2042 13:37:00 GMT'
date: invalid date '8 Sep 2042 13:37:00 GMT'
date: invalid date '8 Sep 2042 13:37:00 GMT'
date: invalid date '14 Sep 2022 13:37:00 GMT'
date: invalid date '14 Sep 2022 13:37:00 GMT'
trying to get CSRF from handlebars
trying to get CSRF from devices-v2
ERROR: no CSRF cookie received

Mit v0.20d klappt das hingegen problemlos.

Die letzte Änderung in v0.20e (removed call to jq's strptime function, replaced with bash function using 'date' to convert to epoch) scheint fehlerhaft zu arbeiten.

Anonym hat gesagt…

Ich habe dieses Shell Script erst jetzt duch Zufall entdeckt, erstmal ganz dickes Danke und Lob!

2 Fragen:

1. zu DefaultDevice "set device specific variables from JSON device list"
Anstatt hier das erste Device zu wählen, wäre es sinnvoll das Default-Device per Variable im Script angeben zu können?

2. Ist es möglich beim abspielen eines Sounds aus der Amazon soundbank/library die Lautstärke direkt mitzugeben?


Anonym hat gesagt…

Alexander, vielen Dank für den Script.
Kann mir jemand mit dieser Fehler helfen?
electrobot@srv-electrobot:/home/alexa$ sh alexa_remote_control.sh -a
cookie expired, logging in again ...
alexa_remote_control.sh: 595: /usr/bin/jq: not found
alexa_remote_control.sh: 594: /usr/bin/jq: not found
ERROR: cookie retrieval with refresh_token didn't work

Anonym hat gesagt…

Entweder ist "jq" bei dir in einem anderen Verzeichnis installiert (unwahrscheinlich aber möglich) oder Du hast es gar nicht installiert (höchstwahrscheinlich).

From France hat gesagt…

Vielen Danke ! You saved my day !!

Anonym hat gesagt…

Wo und wie findet man eine Liste mit allen möglichen API's ?

Anonym hat gesagt…

Wie Alex die URLs für die Verwendung im Skript herausgefunden hat, kannst in seinem ersten Blog-Eintrag nachlesen: https://blog.loetzimmer.de/2017/10/amazon-alexa-hort-auf-die-shell-echo.html

Nic hat gesagt…

Thanks for the continued improvements, great job! I was curious, are multiturn commands supported using Text based approach, like send a command -> get a response and based on response -> send another command almost like interacting with an Alexa skill?

Alexander Noack hat gesagt…

No, unfortunately that is not possible as there is no way to intercept the response.

Anonym hat gesagt…

Ich habe ähnliche Probleme. Allerdings zeigt der bei mir gar keind Date an, sondern "illegal option -- d" und das CSRF kriegt er auch nicht. Ob es "vorher ging", weiß ich nicht, da ich das Skript erst gestern entdeckt habe.

Anonym hat gesagt…

THX! You made my day with that script and the new authentication method!

Anonym hat gesagt…

Tolle Arbeit - vielen Dank! Funktioniert wunderbar :)

Anonym hat gesagt…

Script stopped working. I tried with "./alexa_remote_control.sh -a" but always got errors (invalid date; no CSRF cookie received). Went back to previous version (0.20d) and that worked fine. When I now use version 0.20e it is also working again. But I assume next time I need to update the cookie I would be facing the same problem again. So I better stick with 0.20d.

Anonym hat gesagt…

Hi, vielen Dank für das Script, das seit Jahren bei mir problemlos lief. Leider funtkioniert es seit einigen Wochen nicht mehr. Ich habe jetzt auf die neue Version umgebaut, bekomme aber immer folgenden Fehler, egal, was ich tue:

cookie expired, logging in again ...
jq: error (at :1): null (null) has no keys
jq: error (at :1): null (null) has no keys
ERROR: cookie retrieval with refresh_token didn't work

Anonym hat gesagt…

Hallo! Habe bis dato das nicht mehr weiterentwickelte Script ohne jq verwendet, da ich noch eine CCU2 habe. Leider funktioniert das Script nun nicht mehr und ich kann die Cookies nicht mehr aktualisieren. Gibt es hier noch irgendeine Lösung, oder ist die Sprachansage für die veraltete CCU2 über Alexa nun endgültig Geschichte?

Alexander Noack hat gesagt…

0.20d uses a JQ function for date conversion. 0.20e uses date -d which doesn't work like that on all platforms. Pick your poison ;)

Alexander Noack hat gesagt…

Welche JQ Version verwendest du?

Alexander Noack hat gesagt…

Welche Hardware ist die CCU2? Leider kann man ohne JQ kaum die erhaltenen Daten parsen. Am besten wäre JQ für die CCU2 zu finden/bauen/etc.

Alexander Noack hat gesagt…

Bei wem JQ die strptime Funktion beherrscht, der sollte bei 0.20d bleiben.
0.20e macht das per "date -d". Das kann je nach Plattform evtl. nicht funktionieren. Wir möchten ein Datum "21 Feb 2038 10:11:12 GMT" in einen Unix-Timestamp wandeln... :)

Anonym hat gesagt…

Thanx for explanation. I am running the script on CCU3. Should be very common. Hope you maintain the JQ version as long as date -d is not working reliable on all devices.

teeff.bln hat gesagt…

Danke für diese Arbeit. Danach habe ich lange gesucht. Zunächst funktionierte die Übernahme der Umgebungsvariable DEVICEVOLNAME nicht, was ich bei mir durch 3 zusätzliche Zeilen im remote-Script lösen konnte:
diff alexa_remote_control.sh alexa_remote_control.sh_org
92a93
>
177a179
>
668,671d669
< if [ -z "${DEVICE}" ] && [ -n "${DEVICEVOLNAME}" ]; then
< DEVICE=$(echo ${DEVICEVOLNAME} | sed -r 's/%20/ /g')
< fi
<
1040a1039
>

Da meine Echos Leerzeichen im Namen haben, kann ich allerdings immer noch nur ein Gerät beim Aufruf angeben.

Anonym hat gesagt…

Hallo Alexander, bei mir funktioniert auf einmal die 2FA nicht mehr. Kannst du das bestätigen? Lief bisher einwandfrei. Auf einmal wars vorbei. Kannst du das es mal überprüfen, ob Amazon da was geändert hat.

Anonym hat gesagt…

Dinge ändern sich.

Verwende den Refresh-Token für die Authentifizierung und alles wird gut.

Anonym hat gesagt…

Was meinst du mit Refresh-Token?

Michael hat gesagt…

Ich bins nochmal. Bisher verwende ich 2FA. Was muss ich machen, auf Refresh-Token umzustellen?

Anonym hat gesagt…

Alexanders Beitrag lesen und umsetzen. Gibt es einen Punkt den du nicht verstehst?

Michael hat gesagt…

Ja woher kommt denn der Refresh-Token?

Anonym hat gesagt…

Nachdem du Punkt 1 bis 3 aufgeführt hast, erhälst du ihn bei Punkt 4.

Anonym hat gesagt…

Kurze Frage: Ich habe einen Alexa Echo Dot und eine Alexa Echo Plus 1. Generation. Mit dem Dot funktioniert das Skript tadellos, beim Echo Plus kommt nichts an. Kann es sein, dass die alten Geräte dafür nicht geeignet sind?

Anonym hat gesagt…

Das funktioniert auch mit alten Echos der ersten Generation.

Anonym hat gesagt…

Ja... habe inzwischen gemerkt, dass es möglicherweise an nicht aktualisierten Devicenamen o.Ä. liegt, die über die AlexaApp umbenannt wurden (ich wollte anstelle des Dot den Echo Plus ich im Büro nehmen, da ich da mehr Platz habe und habe die Namen durch zyklisches Vertauschen gewechselt). Die -a Option lieferte mehrere Tage die alten Namen. Aber selbst nachdem -a irgendwann (Woche oder so) die richtigen Namen angezeigt hat, findet die Ausgabe immer auf dem ursprünglichen Echo Dot statt, auch wenn der definitiv inzwischen einen anderen Namen hat. Man hat den Eindruck, dass die Ausgabe noch an einen anderen Identifikator gebunden ist und nicht (nur) an den Devicenamen. Irgendwie total komisch.

Anonym hat gesagt…

Die Device Namen werden in /tmp/alexa.devices gecached. Einfaches Löschen der Datei sollte sie wieder richtig anlegen.

Anonym hat gesagt…

Ok, Dateien neu generiert (/tmp/.alexa.*), aber es bleibt dabei. Eine Ausgabe auf -d "WZ1" und eine weitere Ausgabe auf -d "WZ2" kommt in beiden Fällen auf WZ1 raus. Das ist der ursprünglich konfigurierte Dot.

Anonym hat gesagt…

Das klingt nach einer vermurksten Gesamtkonfiguration. Richte die Echos neu ein und vergib neue, beschreibende Namen. Dann die devicelist löschen und neu generieren lassen und testen.

Anonym hat gesagt…

Hi, I can't change the amazon site to .co.uk - even after adding -p amazon.co.uk after the executable. am I doing something wrong?

Anonym hat gesagt…

Bin ich der Einzige bei dem es nicht mehr funktioniert? Binary ohne Parameter starten, auf localhost:8080 gehen. UserPW von Amazon eingeben. SMS Code eingeben -> Fehlerseite 404 und kein Token in der Shell. Bei Windows und bei Linux...

Anonym hat gesagt…

Amazon hat leider die "Alexa SPA" Seite entfernt, darüber hat das Script die Eingaben übergeben...

Anonym hat gesagt…

Habe das jetzt nicht richtig verstanden, bei mir ging es immer mit PASSWORD, dann einige Wochen unzuverlaessig, da habe ich das schwierige MFA_SECRET hinbekommen und seitdem ging es bis vor Kurzem jahrelang ohne Probleme, glaube so Ende September 2023. Jetzt geht gar nichts mehr. (nutze das Plain Script), richtig verstanden meint, derzeit geht gar nichts mehr weil Amazon was geändert hat? Oder gibt es Lösungen?

Alexander Noack hat gesagt…

Hmm, ich hab's gerade bei mir ausprobiert. Ein 404 bekomme ich nicht und das Token landet korrekt in der Shell Ausgabe.
Ist es eine Amazon 404 Seite?

Alexander Noack hat gesagt…

Tatsächlich werden gerade eine Reihe von API Aufrufen geändert. Anfänglich war die Alexa Web-Anwendung eine wertvolle Hilfe, da das Debugging im Browser sehr simpel war.
Inzwischen benutzen wir Man-in-the-Middle Proxies und andere Tricks, um den Datenverkehr zu analysieren und die APIs entsprechend anzupassen.

Alexander Noack hat gesagt…

Die einzig zukunftssichere Variante ist das im Post beschriebene Refresh-Token Verfahren. Leider benötige ich dafür "jq" für das Parsen der JSON Antworten. Deshalb ist der Umstieg auf die nicht-"plain" Script anzuraten.

AlexaUser hat gesagt…


Hallo,
habe bisher Alexa mit den Android Apps Text2Speech oder SayIt zum sprechen gebracht aber beide Apps funktionieren seit kurzem nicht mehr, weil Amazon das Alexa Webinterface abgeschaltet hat.
Wenn dieses Script nicht davon betroffen ist und weiterhin funktioniert, erbitte ich Hilfe, da meine Kenntnisse diesbezüglich und in Englisch (Github Artikel usw.) begrenzt sind.
Geplant ist, alexa_remote_control.sh per Tasker Shell Aufruf auf einem gerooteten und einem ungerootetem Handy auszuführen.
Den REFRESH_TOKEN konnte ich mit Umleitung in eine Datei (alexa-cookie-cli > token.txt) auf PC erzeugen und sichern und habe den so in das Script inkl. EMAIL und PASSWORD eingetragen.
Beim Ausführen des Script mit -a bekomme ich folgenden Fehler

cookie does not exist. logging in ...
ERROR: cookie retrieval with refresh_token didn't work

und ich nehme an - sofern das Script trotz Webinterface-Abschaltung noch funktioniert - dass das an der fehlenden Eintragung unter MFA_SECRET und/oder am fehlenden Cookie liegt.
Wie komme ich also an die fehlenden Daten mittels Android Handy oder Windows PC?

Danke für jegliche Hilfe (in Deutsch bitte)

Anonym hat gesagt…

Hallo,

ich bekomme seit einigen Tage immer einen Fehler angezeigt und das Skript lässt sich nicht mehr ausführen.

pi@raspberrypi:~/Alexa $ ./alexa1.sh -lastalexa
parse error: Invalid numeric literal at line 1, column 10

Gibt es dazu schon eine Idee?

Anonym hat gesagt…

Ich kann das Problem bestätigen. In meinen Skripten nutze ich -lastalexa immer. Deswegen ist die Funktion sehr wichtig für mich. Ist das Problem lösbar?

Anonym hat gesagt…

Die neue URL heißt /alexa-privacy/apd/rvh/customer-history-records/?startTime=___&endTime=___&recordType=VOICE_HISTORY&maxRecordSize=___

Habe diese Woche keinen Rechner in der Nähe. Kann es nach meinem Urlaub umbauen

Alex

Anonym hat gesagt…

Hallo zusammen,

ich habe mir das mal angeguckt und ein Workaround gefunden.

habe die Zeile 1201:

"https://${ALEXA}/api/activities?startTime=&size=10&offset=1" | ${JQ} -r '[.activities[] | select( .activityStatus == "SUCCESS" )][0] | .sourceDeviceIds[0].serialNumber' | xargs -i grep -m 1 {} ${DEVLIST}.txt

durch:

"https://www.amazon.de/alexa-privacy/apd/rvh/customer-history-records/?startTime=0&endTime=2005090388459&recordType=VOICE_HISTORY&maxRecordSize=100" | jq -r '.customerHistoryRecords[0].device.deviceName'

ersetzt.

Geht so erst einmal wieder aber Alex sollte das mal professionell anpassen.

Anonym hat gesagt…

Bei mir funktioniert der Fix nicht. -lastalexa liefert dann folgende Fehlermeldung:
curl: no URL specified!
curl: try 'curl --help' or 'curl --manual' for more information
Ich muss zugeben, dass mir auch nicht ganz klar ist, was dort alternativ gemacht wird, um den parsing-Fehler zu beheben.

Anonym hat gesagt…

Geht doch, Zeilenumbruch-Problem... :-|

AlexaUser hat gesagt…

Darf ich meine Frage noch mal aufwärmen und noch mal nachfragen, ob man dieses Script auch auf einem ungerooteten Handy in's Laufen bringt?
Danke für alle Antworten

Anonym hat gesagt…

Ich kann mir gerade nicht vorstellen, dass das für weitere Benutzer einen sinnvollen Einsatzzweck des Skriptes darstellt.

Anonym hat gesagt…

Hallo Alex,

ich habe leider auch das Problem mit der 404-Seite. Es handelt sich um eine Amazon-Fehlerseite. Nach dem Start von alexa-cookie-cli (Mac binary, aber auch wenn ich es per per node starte) kann ich per localhost:8080 auf den Amazon Login zugreifen, den Login komplett inkl. SMS-2FA durchführen, und lande dann auf der Fehlerseite.

Ich habe schon alles mögliche ausprobiert (bestehende Cookies löschen, per package.json auf die neuste Version von alexa-cookie2, usw.), aber bisher hat leider nichts geholfen. :( Wenn ich dir noch irgendwelche Infos liefern kann, um das Problem zu rekonstruieren, sag bitte Bescheid.

Anonym hat gesagt…

Kleiner Nachtrag: Ich habe es noch mit einem anderen Amazon-Konto probiert, damit hat es geklappt. Der Unterschied liegt in der 2FA: Per Authenticator funktioniert es, bei SMS kommt aber eine 404 Seite. Ich hoffe, dass das weiterhilft.

Anonym hat gesagt…

Ich habe eine Änderung an das AlexaCookie Repo gepusht, die vorgestern mit der 5.0.1 gemergt wurde.
Ich baue heute Abend eine neue Release für das CLI.
Da gibt es dann auch neue Default Werte. Ich hatte z.B. das Problem, dass localhost night funktioniert, 127.0.0.1 klappte dann.
Alles

Alexander Noack hat gesagt…

v5.0.1 ist released - probiert es bitte mal damit.

Anonym hat gesagt…

Hallo Alex,

der Workaround funktioniert soweit. Allerdings läuft es nicht mit dem Echo Auto.
Ich vermute es liegt daran, dass mit dem Workaround der deviceName und nicht die deviceID verwendet wird. Ich bin leider nicht gut genug im Scripting:-(
Könntest Du da helfen? Das wäre super!

Gruß Michael

Anonym hat gesagt…

Hallo Leute, leider bin ich zu blöde den Refreshschlüssel zu bekommen. Ich starte die Windowsversion um den Schlüssel zu erhalten.
Als Antwort bekomme ich im Browser immer diese URL-Zeile: http://127.0.0.1:8080/www.amazon.com/404 und keinen Schlüssel.
Was mache ich falsch bzw. übersehe ich? Gruß Lolli

wennes hat gesagt…

bitte schreib einen link zum script. Bin halt 100% behindert...

Anonym hat gesagt…

Zur Beantwortung deiner Frage solltest du sehr detailliert beschreiben, wie du vorgeganen bist.

Anonym hat gesagt…

I just tested the v5.0.1 with 2 accounts and I still recieved the 404-error. However, after activating the 2FA, it worked like charm again- Thanks a lot for your work! Note, the 2FA limitation is already mentioned in the readme of the alexa-cookie repo.

Anonym hat gesagt…

Hallo,

ich habe mittlerweile noch einen Echo-Studio. Mit dem funktioniert es auch nicht mehr.
Ich habe sehr lange herumgebastelt und einen Workaround für die -lastalexa-Methode im Script gefunden.
Hat bei mir zumindest funktioniert. Ich habe es mehrfach versucht hier zu posten...aber mein kompletter Kommentar ist jedesmal verschwunden.

Ich habe es deswegen hier abgelegt:
https://snippet.host/nppguw



Gruß

Michael

Anonym hat gesagt…

Hallo, Das von mir partiell geänderte Script funktioniert zwar für '-lastalexa' super, aber gibt es inzwischen irgendwo ein professionell vom Urheber angepasstes Script?

Anonym hat gesagt…

Was genau hast du denn angepasst, dass "-lastalexa" bei dir läuft? Und vor allem: Läuft es aktuell noch?

Alexander Noack hat gesagt…

Ich habe gerade eine Version mit der ganz neuen API eingecheckt.
Damit sollte es wieder laufen.

Anonym hat gesagt…

Hallo Alexander, danke für die neue Version. Leider funktioniert es mit der Alexa-App bzw. Echo Auto nicht. Ich denke es ist das gleiche Problem, welches Du mit Version v0.20c gefixt hattest. Gruß Michael

Alberto hat gesagt…

Hallo Alexandre,
Entschuldigung für die Übersetzung, aber ich habe Google Übersetzer verwendet.

Seit ein paar Wochen werden meine Cookies nicht mehr aktualisiert und es funktioniert nicht mehr.

Ich habe auf die neueste Version 2024-01-31: v0.21a aktualisiert, aber es funktioniert immer noch nicht.

Ich habe sowohl das Refresh-Token als auch die Cookies manuell aktualisiert und es funktioniert etwa 20 Minuten lang, dann stürzt es ab und gibt mir diesen Fehler:

"
cookie expired, logging in again ...
error: map_values is not defined
.response.tokens.cookies | to_entries[] | .key as $domain | .value[] | map_values(if . == true then "TRUE" elif . == false then "FALSE" else . end) | [(if .HttpOnly=="TRUE" then ("#HttpOnly_" + $domain) else $domain end), "TRUE", .Path, .Secure, .Expires, .Name, .Value] | @tsv 1 compile error
ERROR: cookie retrieval with refresh_token didn't work
"

Anonym hat gesagt…

This might be a JQ version related problem. What is JQ's version?

Anonym hat gesagt…

In der Tat, die neue Funktionalität ist ein breaking change.
Leider liefert die API nur den Namen des Geräts.
Wie sieht es bei dir in der Alexa App aus? Kannst du dir die Geräte in der History unterscheiden?

Alberto hat gesagt…

My actual JQ version is: jq-1.6-145-ga9f97e9-dirty

Anonym hat gesagt…

Hallo, ich habe einen Workaround gefunden: https://snippet.host/psnjpt allerdings funktioniert es nur mit der bash (#!/bin/bash - erste Zeile im Skript). Bin im Bash-Programmieren leider nicht so gut:-( Gruß Michael

Alexander Noack hat gesagt…

Danke für die Gedankenstütze - im recordKey war die Seriennummer enthalten :)
Habe das Script entsprechend korrigiert.

Alexander Noack hat gesagt…

You only need the refresh_token (no other cookies).
I don't really understand what you mean by "it crashes after 20 minutes"...

Every time you start the script will check if it has valid access credentials. If not it uses the refresh_token to retrieve a session cookie, which is valid for about 1 day. During that time the refresh_token won't be needed anymore. (And the code part you quoted shouldn't be called at all.)

The session cookie is stored in /tmp/.alexa.cookie and it is created from a JSON response message that is stored in /tmp/.alexa.cookie.json.

The latest version doesn't delete the alexa.cookie.json. If you encounter the problem again, please have a look at the file and post relevant output here or better yet please open an issue in Github.

Anonym hat gesagt…

Hallo,

Ich möchte mein gestrigen Erfahrungen mal kurz posten. Aufwand eine halbe Stunde dann kamen die ersten Sprachnachrichten über die Echo Geräte.

Software Installiert, Variablen in Homematic eingerichtet, Cookie-win.exe ausgeführt und Anmeldung bei Amazon Konto durchgeführt, refresh Token erhalten, eingetragen und ausprobiert, funktioniert.
Macht Spaß damit zu experimentieren. Funktionen bei mir direkt genutzt um Text-Sprach Nachricht über alle Alexas im Haus zu versenden wenn einer der Wassermelder (Waschküche, Heizung oder Küche) anspricht und ein Leck festgestellt wird.
Danke für die tolle Arbeit

Anonym hat gesagt…

Hi, trying to set this up I get these errors when running the script. Any ideas why? Thanks

:/usr/bin# opkg find jq
jq - 1.6-2
:/usr/bin# alexa_remote_control.sh
cookie expired, logging in again ...
Error relocating /usr/bin/jq: __gettimeofday_time64: symbol not found
Error relocating /usr/bin/jq: __fstat_time64: symbol not found
Error relocating /usr/bin/jq: __stat_time64: symbol not found
Error relocating /usr/bin/jq: __localtime64_r: symbol not found
Error relocating /usr/bin/jq: __time64: symbol not found
Error relocating /usr/bin/jq: __gmtime64_r: symbol not found
Error relocating /usr/bin/jq: __mktime64: symbol not found
Error relocating /usr/bin/jq: __gettimeofday_time64: symbol not found
Error relocating /usr/bin/jq: __fstat_time64: symbol not found
Error relocating /usr/bin/jq: __stat_time64: symbol not found
Error relocating /usr/bin/jq: __localtime64_r: symbol not found
Error relocating /usr/bin/jq: __time64: symbol not found
Error relocating /usr/bin/jq: __gmtime64_r: symbol not found
Error relocating /usr/bin/jq: __mktime64: symbol not found
ERROR: cookie retrieval with refresh_token didn't work

Anonym hat gesagt…

Its a Linux box based on OpenWRT its a home automation hub, Z-Wave / Zigbee called Ezlo.

I manually download a JQ package from this Url and then installed using an opkg install command. i am not so good with Linux stuff.

This was the URL for the package

https://downloads.openwrt.org/releases/packages-23.05/arm_cortex-a7_neon-vfpv4/packages/jq_1.6-2_arm_cortex-a7_neon-vfpv4.ipk

Thanks

Anonym hat gesagt…

Please give it a try with the latest version. Date calculations have been removed completely now.

Anonym hat gesagt…

Hallo, wie kann man das ganze auch unter Win11 24H2 zum Laufen bekommen? Ich versuche es mit WSL und Debian als Distro, aber mir ist nicht klar wie ich den Code in das System dort bekomme und dann eine Verknüpfung starten kann mit einem imitiertem Sprachbefehl. Mit Debian und einer GUI kein Problem, aber ohne bekom ichs nicht gebacken.

Anonym hat gesagt…

Using this alexa script, How you can play music using URL?

Peter hat gesagt…

Hallo Alex, ganz großes Kino und alles funktioniert wunderbar. Vielen Dank für die tolle Arbeit.

Ich habe eine Frage: Statt einem Aufruf wie z.B. ""peters Test" -e playmusic:SPOTIFY:Awolnation", wäre es doch schöner, wenn man das ganze Album abspielen möchte, die Spotify-ID, oder die Apple-Album-ID, anzugeben um eindeutig das gewünschte Album abzuspielen.
Ist das irgendwo implementiert, oder wie würdest Du damit umgehen?

Viele Grüße
Peter

Anonym hat gesagt…

Hallo
ich versuche das Windows Tool um den cookie zu bekommen. Die Website auf localhost ist aber nur ein Barcode mit dem versucht wird die Alexa app zu installeren, kein Amamzon login.
Was tun ?
Danke!

Anonym hat gesagt…

Nachtrag
Das liegt wohl daran, dass Amazon die Alexa Website abgeschaltet hat ? Gbt es eine Alternative ?

Anonym hat gesagt…

Hmmm, bei mir funktioniert es. Kommt die normale Amazon Anmeldung...

Anonym hat gesagt…

Hallo,
bei mir funktioniert seit einigen Tagen das "pause" Kommando nicht mehr (alexa.sh -d "Schlafzimmer" -e pause). Ausschalten eines Radiosenders ist nicht mehr möglich per Script. Zuvor ist das jetzt jahrelang normal gelaufen. Alles andere funktioniert auch weiterhin, nnur Pause geht nicht mehr.

Anonym hat gesagt…

es gibt auch keine Fehlermeldung und sieht so aus als würde es funktionieren. Nur Stoppt Alexa die Wiedergabe nicht.

sending cmd:{"type":"PauseCommand"} to dev:Schlafzimmer type:XXXXXXXXXX serial:XXXXXXXXX customerid:XXXXXXXX

Anonym hat gesagt…

Seit gestern klappt der Login nicht mehr. Refresh Token kann ich wunderbar abgreifen mit der Hilfsapp, jedoch sagt login dann immer Cookie expired und login failed. Habe alles nun mehrfach probiert. Auch mit den Amazon MFA Einstellungen habe ich gespielt, SMS oder Authenticator oder ganz ohne, macht alles kein Unterschied.

Anonym hat gesagt…

Kann ich bestätigen. Der Token ist jedesmal anders. Ich glaube der war früher immer gleich.

Anonym hat gesagt…

Same here. When I type in cli:
sudo ./alexa_remote_control.sh -d Echo -e speak:'Test 123'
I get:
cookie expired, logging in again ...
log in failed, aborting
And even if I refresh the token, same error.

Anonym hat gesagt…

https://docs.aws.amazon.com/de_de/singlesignon/latest/userguide/generate-token.html
Es ist vielleicht nicht mehr kostenlos.

Anonym hat gesagt…

Bei mir das gleiche Problem
cookie expired, logging in again ...
log in failed, aborting

Anonym hat gesagt…

Suspect there might be a clue here to how to get around this, maybe(!)
https://github.com/Apollon77/alexa-remote

MainyMike hat gesagt…

The URL to use appears to have changed, but I don't see how the returned values from the api/customer-status are used to provide the authentication. It seems like the existing script needs to incorporate the changes shown here, but I can't figure out how, right now.
See Changes https://github.com/Apollon77/alexa-remote/commit/f79905f94896a18d2f3d3214eb34672589e2a303

MainyMike hat gesagt…

See this issue log: https://github.com/thorsten-gehrig/alexa-remote-control/issues/189
I've made this change and the script works again :)

Anonym hat gesagt…

Danke sehr! Mit dem Patch geht es wieder.

Anonym hat gesagt…

Auch vielen Dank, klappt wieder

Anonym hat gesagt…

The script is now updated.

Anonym hat gesagt…

Hello, thank you for the script update. But now, for each request I have this error : "Invalid request. Please check your input and try again."
Thank you for your help.
$ ./alexa_remote_control.sh -l
only logout option present, logging off ...
$ ./alexa_remote_control.sh -login
cookie does not exist. logging in ...
device list does not exist. downloading ...
logged in
$ ./alexa_remote_control.sh -d Dot3 -e speak:"hello"
sending cmd:speak:hello to dev:Dot3 type:A1RABVCXXXXIKC serial:G091B00XXXX21DHM customerid:"A3ZXXXXXXE31C"
Invalid request. Please check your input and try again.

Anonym hat gesagt…

Exactly the same issue here

Anonym hat gesagt…

Stupid mistake on my end. The mediaOwnerId was enclosed in additional quotes. I just pushed an updated version.

DJay hat gesagt…

Thanks a lot. Now everything is working again for me and I'm up-to-date. Danke schön. :)

Anonym hat gesagt…

You are the best : it works again, thank you !

Anonym hat gesagt…

It works again with the patch. Many thanks!

Anonym hat gesagt…

Hallo,
vielen Dank für diese Lösung mit dem token.
Ich habe alles entsprechend getan und das token bekommen.
Wenn ich nun eins meiner Scripte aufrufe, passiert aber leider nichts.
Mein Testaufruf (hatte vorher immer fkt.):
/home/pi/alexa_remote_control.sh -d "Dr.s Echo Show" -e speak:'Hallo Peter'
Beim ersten Mal kam folgendes:
cookie does not exist. logging in ...
device list does not exist. downloading ...
sending cmd:speak:Hallo Peter to dev:Dr.s Echo Show type:A1Z88NGR2BK6A2 serial:XXXXXXXXXXX customerid:XXXXXXXXXXX
Danach nur noch die letzte Zeile...
Aber es passiert dann nichts...
Alle anderen Scripte funktionieren auch nicht...
Hat jemand ein Idee?
Vielen Dank,
Peter

Anonym hat gesagt…

Hallo zusammen, das Problem hat sich erledigt. Ich hatte gestern einen neuen Router installiert und nicht gemerkt, dass Alexa keine Verbindung hatte... Sorry.
Peter