Sure! I currently have my own code running in a Node.js Express server so I can send commands from anywhere on the network. It's pretty custom and still a messy work in progress; but here are some instructions and code I quickly put together, which will hopefully get you or other people started.
Before you can run it, you'll need to download and install Node.js if you don't already have it. (
Download Node.js)
Step 1:Create a folder on your Desktop called "Alexa", download the attached file to that folder, and rename it to remove the ".txt" extension.
Step 2: Run the following command in Terminal to install alexa-remote from GitHub, as well as its dependencies:- Code: Select all
cd ~/Desktop/Alexa && npm install github:Apollon77/alexa-remote.git && node ./send-alexa-command.js
Step 3:The first time the code runs, you'll get an error like this one since it cannot login to your Amazon account yet:
- Code: Select all
Alexa-Remote: Error from retrieving cookies
Error: You can try to get the cookie manually by opening http://localhost:3001/ with your browser.
Open http://localhost:3001/ with your browser, which brings up an Amazon login page (yup, it's in German). When you login, it will capture the cookie to use from then on.
I added code to save and load the cookie from a file so you should only have to do this once (unless you don't use it long enough for the cookie to expire).
If everything worked, you should get an announcement on all your Alexa devices saying "This is a test."
Since this is just a sample/test program, I just have it exit after sending the command to Alexa. You can then edit the
sendCommand call in the
send-alexa-command.js file and use the following Terminal command to run it again:
- Code: Select all
node ./send-alexa-command.js
The
sendCommand function takes 3 parameters:
- command
string - One of the commands in the createSequenceNode function in alexa-remote.js.
For example:
- speak
- announcement
- ssml (This is a speak command with advanced features like different voices/languages. Click here for reference.)
- volume
- singasong
- value
string or number - If the command doesn't require a value, you can just leave this empty or null.
When the command is ssml, you can enter SSML code or just a simple string that will be spoken using a default voice and language that can be set in the send-alexa-command.js file. - deviceIDs
Can be any one of the following:
- string - Name of Alexa device
- string - Serial number of Alexa device
- array - A list of multiple device names or serial numbers
- null - If omitted, the command will be sent to ALL devices.
You can also just call the functions in the AlexaRemote class directly, but I tried to make one intuitive function that handled all the commands I needed to make.
Examples:Send SSML speech command to 2 devices named "Echo Show" and "Living Room":- Code: Select all
sendCommand("ssml", "This is a test.", ["Echo Show", "Living Room"]);
Have Alexa tell the weather from a device called "Family Room":- Code: Select all
sendCommand("weather", "", "Family Room");
Set the volume to 100% on ALL devices:- Code: Select all
sendCommand("volume", 100);
Send custom SSML to ALL devices:- Code: Select all
let customSSML = "<speak>" +
"<lang xml:lang='en-US'>" +
"<say-as interpret-as='interjection'>hiya. guess what.</say-as>" +
"I wanna tell you a secret" +
"<break time='500ms'/>" +
"<amazon:effect name='whispered'>I can see your browser history.</amazon:effect>" +
"<break time='1s'/>" +
"<say-as interpret-as='interjection'>schwing. oh my.</say-as>" +
"<break time='1500ms'/>" +
"<say-as interpret-as='interjection'>ha ha. gotcha.</say-as>." +
'</lang>' +
'</speak>';
sendCommand("ssml", customSSML);
* The attached file will have to be edited if you are outside the United States. See the
alexa-remote repo for more details.
EDIT: I thought I should mention that I have nothing to do with the GitHub repos or contributing projects that make this happen, I just edited the example.js file from Apollon77's repo and added a few of my own functions. All credit goes to them.