How to get your Alexa cookie

If you're trying to figure out how to get a cookie for node-red to use Alexa with node-red-contrib-alexa-remote2-applestrudel, then you probably already know that alexa.amazon.com doesn't take you to a developer portal any longer. Here is little tutorial. Hopefully this will save someone some time and frustration.

These instructions assume you've already installed applestrudel and have not been able to figure out how to get your cookie. If not, do that first. Then do this:

  1. In your Alexa configuration node make sure you have the path for the cookie set to an appropriate path for your OS. On my Rpi I used /home/pi/.node-red/Alexa/alexa-cookie.json. Below is a screen shot of my setup for the node. Note that "This IP" is the IP address for your node-red instance and will almost certainly be different than mine.

  2. Import the following code into node-red from Arkapravo Ghosh and deploy it.

[{"id":"46b76480b6063350","type":"comment","z":"8501894d89672c69","name":"Alexa Init","info":"","x":280,"y":940,"wires":[]},{"id":"599d08388328106e","type":"inject","z":"8501894d89672c69","name":"4 Hours","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"14400","crontab":"","once":false,"onceDelay":0.1,"topic":"A","payload":"refresh","payloadType":"str","x":290,"y":980,"wires":[["b84a118b715e3639"]]},{"id":"a149f1e9267a49a6","type":"inject","z":"8501894d89672c69","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":true,"onceDelay":0.1,"topic":"","payload":"Started!","payloadType":"str","x":300,"y":1040,"wires":[["8345d0a4cc5cdf43"]]},{"id":"19a9340ea3ea7f9f","type":"inject","z":"8501894d89672c69","name":" 5 Minutes","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"300","crontab":"","once":false,"onceDelay":0.1,"topic":"A","payload":"true","payloadType":"bool","x":190,"y":1100,"wires":[["0c52122a9bf132eb"]]},{"id":"8345d0a4cc5cdf43","type":"change","z":"8501894d89672c69","name":"set","rules":[{"t":"set","p":"payload","pt":"msg","to":"alexa","tot":"flow"}],"action":"","property":"","from":"","to":"","reg":false,"x":470,"y":1040,"wires":[["b84a118b715e3639","73c82258588542be"]]},{"id":"73c82258588542be","type":"function","z":"8501894d89672c69","name":"Value","func":"global.set(\"alexa\", msg.payload);\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":650,"y":1040,"wires":[[]]},{"id":"936c9fb8c37e5196","type":"function","z":"8501894d89672c69","name":"","func":"//var x=global.get(\"Rain\");\nglobal.set(\"Alexa__\",0); \nif(msg.payload!=true)\n{\n msg.payload=\"refresh\";\n return msg;\n}\n","outputs":1,"noerr":0,"initialize":"","finalize":"","x":780,"y":1120,"wires":[["b84a118b715e3639"]]},{"id":"b84a118b715e3639","type":"alexa-remote-init","z":"8501894d89672c69","name":"","account":"0a0ffea839d389b9","option":"initialise","x":880,"y":980,"wires":[["dbdfbe3297782bcf"]]},{"id":"dbdfbe3297782bcf","type":"change","z":"8501894d89672c69","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload.csrf","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":1100,"y":1020,"wires":[["ae43e79942aa3bb2"]]},{"id":"ae43e79942aa3bb2","type":"function","z":"8501894d89672c69","name":"","func":"async function delay(timeMs) {\n  await new Promise(resolve => setTimeout(resolve, timeMs));\n} \nvar newInit = msg.payload;\nvar oldInit = global.get(\"alexa\");\nif (newInit != oldInit)\n{\n global.set(\"alexa\", msg.payload); \n msg.payload=\"refresh\";\n await delay(20000);  \n return msg;\n}\n\n","outputs":1,"noerr":0,"initialize":"","finalize":"","x":1260,"y":1000,"wires":[["b84a118b715e3639"]]},{"id":"cc609f2260c84def","type":"alexa-remote-other","z":"8501894d89672c69","name":"","account":"0a0ffea839d389b9","config":{"option":"checkAuthentication"},"x":520,"y":1120,"wires":[["936c9fb8c37e5196"]]},{"id":"0c52122a9bf132eb","type":"delay","z":"8501894d89672c69","name":"","pauseType":"random","timeout":"5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"0","randomLast":"5","randomUnits":"seconds","drop":false,"outputs":1,"x":340,"y":1120,"wires":[["cc609f2260c84def"]]},{"id":"cb18d6504adb7116","type":"catch","z":"8501894d89672c69","name":"Check Authentication","scope":["cc609f2260c84def"],"uncaught":false,"x":460,"y":1200,"wires":[["2d8421e311a6b63d"]]},{"id":"2d8421e311a6b63d","type":"delay","z":"8501894d89672c69","name":"","pauseType":"delay","timeout":"4","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"outputs":1,"x":660,"y":1200,"wires":[["cc609f2260c84def"]]},{"id":"dc4f67109f20612f","type":"catch","z":"8501894d89672c69","name":"Initialise","scope":["b84a118b715e3639"],"uncaught":false,"x":680,"y":920,"wires":[["7d841cccf0303f9a"]]},{"id":"7d841cccf0303f9a","type":"delay","z":"8501894d89672c69","name":"","pauseType":"delay","timeout":"5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"outputs":1,"x":900,"y":920,"wires":[["c062a06f4e6099e3"]]},{"id":"c062a06f4e6099e3","type":"change","z":"8501894d89672c69","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"refresh","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1060,"y":920,"wires":[["b84a118b715e3639"]]},{"id":"0a0ffea839d389b9","type":"alexa-remote-account","name":"","authMethod":"proxy","proxyOwnIp":"192.168.29.5","proxyPort":"3456","cookieFile":"/mnt/dietpi_userdata/node-red/cookie.txt","refreshInterval":"1","alexaServiceHost":"alexa.amazon.in","amazonPage":"amazon.in","acceptLanguage":"en-IN","onKeywordInLanguage":"on","userAgent":"","useWsMqtt":"on","autoInit":"on"}]
  1. Now you will see something similar after initializing. Note the flashing text you see on screen under the two Alexa nodes.

  2. Open a private browser window and type in your IP and port. In my case it's "192.168.68.130:3456". Your's will be what you see in the flashing text in node-red. This will open a log in page for your Alexa account.

  3. Type in your log in credentials. If successful, you should see this:

  4. Go back to your node-red tab and do a restart or full deploy for good measure. You should now see your Alexa nodes initialize properly.

4 Likes

very comfortable. when I had problems with the proxy it was because of the old browser cookie, all I had to do was clear the cache

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.