Control any Alexa device using Node-RED

This article will show you how to get your computer (Windows or Raspberry Pi) to control Alexa devices by simply placing a speaker next to an Alexa Dot and using Node-RED to do the talking

Once you’ve got your computer speaking to Alexa, I recommend getting a Flex (when they are on offer at £9.99) and then attach a pound shop headphone, near one of the microphone holes, with a bit of hot-glue.

 

That way, you won’t get disturbed by all the chat 🙂

Using a Windows machine

If you use a windows machine, it trivial to set up as windows and chrome browser give you built in text to speech

Just set up this flow

Press inject – and your computer should speak to Alexa and your Alexa should respond!

After that, the world is your oyster in controlling all your devices by simply getting Node-RED to send out the correct Alexa commands.

But … it means having a spare windows machine or putting up with a lot of chat, so great for testing and playing around with but we we really need a more standalone method

Using a Raspberry Pi (or other Debian based Linux machine)

Unfortunately, a Pi doesn’t speak straight out of the box but for a Pi4 (probably a Pi3 as well but not tested) its not too hard to set up by following these instructions

https://flows.nodered.org/node/node-red-contrib-pico2wave/in/Qn4a6AEtnjAw

i.e: Install the libraries using a terminal command line and then install the node as normal

Then create a flow:

Press inject – and your computer should speak to Alexa and your Alexa should respond!

After that, the world is your oyster in controlling all your devices by simply getting Node-RED to send out the correct Alexa commands.

Old Raspberry Pi (see further down for easier but not as good method)

Now, you might not want to dedicate a Pi4 for the job but to use an older Pi (I’m using an old original Model B), you might need to compile the libraries and do a bit of bodging on the pico2wave node but you can do it (well I managed)

This post should show you how to do it

https://discourse.nodered.org/t/node-play-audio-and-text-to-speech-on-a-raspberry-pi/40401/6?u=cymplecy

I have hopefully documented all the necessary steps but I might have missed something off or not been clear enough so please tell me via @cymplecy on twitter if I’ve got it wrong

Then setup a flow like ths:

with this setting in pico2wave

and this setting in the exec node

Note the -Dhw:1,0 is to force playback from the audio jack

Alternative on a Pi

If you want to avoid the time and effort of compilation on an older Pi, instead of pico2wave, you can simply use espeak.

It sounds a little more robotic than pico2wave but as long as Alexa understands it, then you are good to go.

To install do

sudo apt-get install espeak

and then setup Node-RED with this flow

and configure the template node

and the 1st exec node like this

and the 2nd one like this

Or just copy this flow and import it into Node-RED

[{"id":"448741955bdaea32","type":"debug","z":"cd746c470932d185","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":910,"y":760,"wires":[]},{"id":"996b265257515c60","type":"exec","z":"cd746c470932d185","command":"aplay -Dhw:1,0 /home/pi/alexa.wav ","addpay":"payload","append":"","useSpawn":"false","timer":"","winHide":false,"oldrc":false,"name":"","x":720,"y":680,"wires":[["448741955bdaea32"],["448741955bdaea32"],["448741955bdaea32"]]},{"id":"2f5c26c5e3ec8bb0","type":"exec","z":"cd746c470932d185","command":"espeak -w /home/pi/alexa.wav ","addpay":"payload","append":"","useSpawn":"false","timer":"","winHide":false,"oldrc":false,"name":"","x":430,"y":740,"wires":[["996b265257515c60"],[],[]]},{"id":"c74b66e26655e1a9","type":"template","z":"cd746c470932d185","name":"","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"\"{{payload}}\"","output":"str","x":320,"y":680,"wires":[["2f5c26c5e3ec8bb0"]]},{"id":"86b379e3542d9f48","type":"inject","z":"cd746c470932d185","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"Alexa, what is the time","payloadType":"str","x":140,"y":680,"wires":[["c74b66e26655e1a9"]]}]

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *