Alexa Announcements

Posted on
Fri Nov 08, 2019 3:50 pm
jay (support) offline
Site Admin
User avatar
Posts: 16815
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Alexa Announcements

[MODERATOR NOTE] Moved this topic from the Alexa-Hue Bridge forum to this forum since it doesn't directly relate to that plugin.

I know nothing about how this integration works, but I can address a few of the Python and UNIX specific things mentioned in the last couple of posts:

whmoorejr wrote:
I guess Return Code -= 1 is bad, 0 is good.? That's the extent of my knowledge on how that script actually works... 0 good, 1 bad.


Point of fact: in UNIX (and derivatives like macOS), a return code of 0 is good, anything else is generally considered bad. This isn't universal, but close to it.

whmoorejr wrote:
My code, alexa-variable.py has no shebang stuff at the top, begins at "import indigo"


The shebang line will be ignored for Indigo Python scripts. Shebangs are generally only useful when you make a script executable so that when you try to run the script by just using it's name, what to run the script with can be discovered from the shebang. Since Indigo Python scripts are always (and, in fact, must be) run by Indigo, Indigo already knows how to execute it.

whmoorejr wrote:
Line 7, I think echo_name is supposed to be in " " not ' '. My line 7 is
Code: Select all
echo_name = ""  # Leave echo name blank to send to all devices


In Python, you can use either single or double quotes to identify a string - it makes no difference.

Anything else, unfortunately, I can't really help with since it's specific to the integration.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Fri Nov 08, 2019 4:16 pm
ckeyes888 offline
Posts: 2280
Joined: Nov 26, 2009
Location: Kalispell, MT

Re: Alexa Announcements

Wow, thanks so much! Not sure which bit of code fixed it but it’s working great.

This allows me to get rid of quite a few Airplay speakers around the house.

Thanks,

Carl

Posted on
Wed Dec 04, 2019 4:05 pm
siclark offline
Posts: 1570
Joined: Jun 13, 2017
Location: UK

Re: Alexa Announcements

This is freakin amazing.. and up and running in 5 mins. Amazing

For anyone else struggling as ckeyes888 was, or if he still is then the you need to remove <> from the echo name.

ie
echo_name = 'Kitchen'
not
echo_name = '<Kitchen>'

Posted on
Sat Dec 07, 2019 8:34 am
katiaf offline
Posts: 85
Joined: Jul 01, 2014

Re: Alexa Announcements

Thanks for the modified .js and these instructions! I got it working too :)

I had never done anything with Alexa's API before and I had a little of trouble getting it to work. I wanted to add a couple of tips that can help other newbies:

It is very helpful to turn on debugging. In your Indigo python script that calls the announcement, just change "debug = True"

Using debugging help I got a message about not finding "alexa-remote2". A quick google search sent me to a GitHub page and I found out that I needed to install the npm package: "sudo npm install alexa-remote2". I hope this is helpful for someone else.

Posted on
Sun Feb 02, 2020 12:21 pm
whmoorejr offline
User avatar
Posts: 522
Joined: Jan 15, 2013
Location: Houston, TX

Re: Alexa Announcements

autolog wrote:
The modified script checks for incoming arguments:
  1. SSML - fixed, non-user amendable
  2. announcement - passed through from the Indigo variable
  3. Echo name - optional, may be blank
. The script sends accordingly (see lines 74 thru 82.


Question on #3. Is there a way to use two or more devices? I'm getting good results with one device or an announcement to all devices. Every alteration of the code I've tried to do just two or three device results in either no announcement at all or just the first device in the list gets the announcement.

I'm not sure if I can make this happen with just an edit to the .py file. I'm guessing I may have to also manipulate the .js file?

Bill
My Plugin: My People

Posted on
Sun Feb 02, 2020 12:57 pm
autolog offline
Posts: 3506
Joined: Sep 10, 2013
Location: West Sussex, UK [GMT aka UTC]

Re: Alexa Announcements

whmoorejr wrote:
autolog wrote:
The modified script checks for incoming arguments:
  1. SSML - fixed, non-user amendable
  2. announcement - passed through from the Indigo variable
  3. Echo name - optional, may be blank
. The script sends accordingly (see lines 74 thru 82.


Question on #3. Is there a way to use two or more devices? I'm getting good results with one device or an announcement to all devices. Every alteration of the code I've tried to do just two or three device results in either no announcement at all or just the first device in the list gets the announcement.

I'm not sure if I can make this happen with just an edit to the .py file. I'm guessing I may have to also manipulate the .js file?

Probably the simplest thing to do (without any significant script changes) is to duplicate the python script and change the name of the Echo. Repeat this duplication for each additional Echo that you want to send the message to . Then just additional actions to the existing Action to invoke these additional scripts.

Doing it this way will require no change to the .js file. :)

Posted on
Thu Jun 18, 2020 4:03 pm
ckeyes888 offline
Posts: 2280
Joined: Nov 26, 2009
Location: Kalispell, MT

Re: Alexa Announcements Is This Still Working?

This had been working fine up until a few days ago but now has stopped working on any of my devices.
Haven't made any changes to anything.

Get this in the log:
Action Group Alexa Announce Deck
Script NODEJS [Announcement] = Testing, 1, 2, 3.
Script NODEJS Poll Loop Count = 1, Return Code = 1

Maybe something has changed?

Edit: Seeing this in Terminal when I tried reinstalling.
TV:Alexa TV$ cd ~/Desktop/Alexa && npm install github:Apollon77/alexa-remote.git && node ./send-alexa-command.js
npm ERR! Error while executing:
npm ERR! /usr/bin/git ls-remote -h -t ssh://git@github.com/Apollon77/alexa-remote.git
npm ERR!
npm ERR! xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools), missing xcrun at: /Library/Developer/CommandLineTools/usr/bin/xcrun
npm ERR!
npm ERR! exited with error code: 1

npm ERR! A complete log of this run can be found in:
npm ERR! /Users/TV/.npm/_logs/2020-06-18T22_27_49_892Z-debug.log

Thanks,

Carl

Posted on
Sun Jun 21, 2020 8:58 pm
ckeyes888 offline
Posts: 2280
Joined: Nov 26, 2009
Location: Kalispell, MT

Re: Alexa Announcements

Tried reinstalling Homebrew and node.js which I believe installs npm.

Getting this in Terminal now:

TV:Alexa TV$ cd ~/Desktop/Alexa && npm install github:Apollon77/alexa-remote.git && node ./send-alexa-command.js
npm WARN ws@7.3.0 requires a peer of bufferutil@^4.0.1 but none is installed. You must install peer dependencies yourself.
npm WARN ws@7.3.0 requires a peer of utf-8-validate@^5.0.2 but none is installed. You must install peer dependencies yourself.
npm WARN Alexa No description
npm WARN Alexa No repository field.
npm WARN Alexa No license field.

+ alexa-remote2@3.2.2
updated 1 package, moved 10 packages and audited 85 packages in 8.968s
found 0 vulnerabilities

undefined:13
}
^

SyntaxError: Unexpected token } in JSON at position 3687
at JSON.parse (<anonymous>)
at Object.<anonymous> (/Users/TV/Desktop/Alexa/send-alexa-command.js:20:46)
at Module._compile (internal/modules/cjs/loader.js:778:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
at Module.load (internal/modules/cjs/loader.js:653:32)
at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
at Function.Module._load (internal/modules/cjs/loader.js:585:3)
at Function.Module.runMain (internal/modules/cjs/loader.js:831:12)
at startup (internal/bootstrap/node.js:283:19)
at bootstrapNodeJSCore (internal/bootstrap/node.js:622:3)

Really appreciate any help getting this working again.

Thanks,

Carl

Posted on
Tue Jun 23, 2020 7:00 pm
ckeyes888 offline
Posts: 2280
Joined: Nov 26, 2009
Location: Kalispell, MT

Re: Alexa Announcements

Set debug to True in the script and get this error in the log:
Code: Select all
Action Group                    Alexa Announce Kitchen
   Script                          NODEJS [Announcement] = testing, 1 2 3
   Script                          >>> undefined:13
   Script                          >>> }
   Script                          >>> ^
   Script                          >>>
   Script                          >>> SyntaxError: Unexpected token } in JSON at position 3687
   Script                          >>>     at JSON.parse (<anonymous>)
   Script                          >>>     at Object.<anonymous> (/Users/TV/Desktop/Alexa/send-alexa-command-kitchen.js:20:46)
   Script                          >>>     at Module._compile (internal/modules/cjs/loader.js:1138:30)
   Script                          >>>     at Object.Module._extensions..js (internal/modules/cjs/loader.js:1158:10)
   Script                          >>>     at Module.load (internal/modules/cjs/loader.js:986:32)
   Script                          >>>     at Function.Module._load (internal/modules/cjs/loader.js:879:14)
   Script                          >>>     at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12)
   Script                          >>>     at internal/main/run_main_module.js:17:47
   Script                          NODEJS Poll Loop Count = 0, Return Code = 1


Any ideas?

Thanks,

Carl

Posted on
Tue Jun 23, 2020 8:36 pm
whmoorejr offline
User avatar
Posts: 522
Joined: Jan 15, 2013
Location: Houston, TX

Re: Alexa Announcements

ckeyes888 wrote:
Any ideas?


I'm not a programmer, but I tried to at least duplicate your debug log with my working debug log to see what looks different....

Code: Select all
 Script                          NODEJS [Announcement] = hello
   Script                          >>> Alexa-Remote: Use as User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36
   Script                          >>> Alexa-Remote: Use as Login-Amazon-URL: amazon.com
   Script                          >>> Alexa-Remote: Use as Base-URL: pitangui.amazon.com
   Script                          >>> Alexa-Remote: cookie was provided
   Script                          >>> Alexa-Remote: Sending Request with {"host":"pitangui.amazon.com","path":"/api/bootstrap?version=0","method":"GET","timeout":10000,"headers":{}}
   Script                          >>> Alexa-Remote: Response: {"authentication":{"authenticated":true,"canAccessPrimeMusicContent":true,"customerEmail":"bill.....
Bunch of junk....
Code: Select all
 Script                          >>> >>>>START<<<<<
   Script                          >>> 0 -> /usr/local/bin/node
   Script                          >>> 1 -> /Users/williammoore/Desktop/Alexa/send-alexa-variable.js
   Script                          >>> 2 -> ssml
   Script                          >>> 3 -> hello
   Script                          >>> 4 -> Echo Bill's Office
   Script                          >>> >>>>END<<<<<
   Script                          >>> Saving cookie to file: /Users/williammoore/Desktop/Alexa/my-cookie.json
   Script                          >>> Sending command(s):
   Script                          >>> {
   Script                          >>>     "devices": [
   Script                          >>>         "Echo Bill's Office"
   Script                          >>>     ],
   Script                          >>>     "commands": [
   Script                          >>>         {
   Script                          >>>             "command": "ssml",
   Script                          >>>             "value": "<speak><voice name=\"Brian\"><lang xml:lang=\"en-UK\">hello</lang></voice></speak>"
   Script                          >>>         }
   Script                          >>>     ]
   Script                          >>> }
   Script                          >>> Alexa-Remote: No authentication check needed (time elapsed 2041)
More Junk.....
Code: Select all
Script                          NODEJS Poll Loop Count = 0, Return Code = 0


So, I wonder if it's an Alexa-Remote thing? I know there are 2 flavors, but I'm not sure which is for what. Alexa-Remote & Alexa-Remote2. For this speech thing, I think it uses Alexa-Remote. (From my log, it's referencing Alexa-Remote). In Node-Red stuff, I'm using the Alexa-Remote2 Pallet (which I think is written by the same guy).

Again, I'm not a programmer.... for me, it's more like poking a bear with a stick. Sometimes the bear goes where I want it to, sometimes he eats my face.

Bill
My Plugin: My People

Posted on
Tue Jun 23, 2020 9:27 pm
ckeyes888 offline
Posts: 2280
Joined: Nov 26, 2009
Location: Kalispell, MT

Re: Alexa Announcements

[quote=.....sometimes he eats my face.[/quote]

Yes, I consider my face eaten. :lol:

Thanks for looking into it. No idea where to go from here though.

Carl

Posted on
Wed Aug 26, 2020 11:58 am
mundmc offline
User avatar
Posts: 814
Joined: Sep 14, 2012

Re: Alexa Announcements

@autolog, first off, thank you so much for your Python script that allows indigo to communicate the contents of a variable to the nodejs that controls Alexa. Question- I'm in the weeds with javascript in my efforts to have a second variable that contains a list of destination-Echoes which I want to say a given announcement. Presently, I have an indigo variable that has no problem exporting one destination, but if I try to put in a list or dictionary, as a string, I cannot get it into the sendCommand function of the javascript.

This works fine for one destination (or all of them if no destination is specified):
Code: Select all
announcement = indigo.variables[1330859711].value  # Variable which contains text to speak
echo = indigo.variables[229302118].value # "ALEXACOMMAND_destination"
indigo.server.log (u'NODEJS [Announcement] = {}'.format(announcement))
command = u'node ~/Desktop/Alexa/send-alexa-command.js "ssml" "{}" "{}"'.format(announcement, echo)


My main problem is implementing a python-> shell script -> node methodology.
Any thoughts on how best to approach this? I can keep the destinations in any suitable format in an Indigo Variable (list, dict, etc)

I suspect the problem lies in the send-alexa-command.js script reading in multiple entries as arguments here:
Code: Select all
    function (err) {
        if (err) {
            console.log(err);
            return;
        }

        argCommand = ''
        argDetail = ''
        argDevice = ''

        console.log('>>>>START<<<<<')
        for (let j = 0; j < process.argv.length; j++) {
            if (j == 2) {
                argCommand = process.argv[j]
            }

            if (j == 3) {
                argDetail = process.argv[j]
            }

            if (j == 4) {
                argDevice = process.argv[j]
            }

            console.log(j + ' -> ' + (process.argv[j]));
        }
        console.log('>>>>END<<<<<')

        saveCookie();

        if (argCommand !== '') {
            if (argDetail !== '') {
                if (argDevice !== '') {
                    sendCommand(argCommand, argDetail, [argDevice]);
                } else {
                    sendCommand(argCommand, argDetail)
                }
            }
        }

        setTimeout(function(){
            process.exit();
        },5000);
    }


Though it also could be something different I need to do here:
Code: Select all
function sendCommand(command, value, deviceIDs) {
    try {
        // See createSequenceNode function in alexa-remote.js for a list of commands.

        // If no devices are specified, the command will be sent to ALL devices.
        if (!deviceIDs) deviceIDs = getAllDeviceSerialNumbers();
        if (!Array.isArray(deviceIDs)) deviceIDs = [deviceIDs];

        // Build list of commands
        // The 'ssml' and 'announcement' commands support sending to multiple devices at once. The other commands do not.
        let allCommands = [];
        if (['ssml','announcement'].includes(command)) {
            let thisCommand = {};
            thisCommand.command = command;
            thisCommand.value = (command == 'ssml') ? stringToSSML(value) : value;
            allCommands.push(thisCommand);
        } else {
            deviceIDs.forEach(function(name) {
                let thisCommand = {};
                thisCommand.command = command;
                thisCommand.value = value;
                thisCommand.device = name;
                allCommands.push(thisCommand);
            });
        }

        console.log("Sending command(s):\n" + JSON.stringify({
            devices: deviceIDs,
            commands: allCommands,
        },null,4));

        alexa.sendMultiSequenceCommand(deviceIDs, allCommands);

        return;

    } catch (e) {
        console.log("Error sending command: \n" + JSON.stringify(e, null, 4));
    }
}
:

Any thoughts super appreciated!

Posted on
Wed Aug 26, 2020 1:24 pm
autolog offline
Posts: 3506
Joined: Sep 10, 2013
Location: West Sussex, UK [GMT aka UTC]

Re: Alexa Announcements

mundmc wrote:
..... Any thoughts super appreciated!

It is a long time since I have looked at this and will have to refresh my memory on how it works.

I will see if I can find some time tomorrow to look into it for you. :)

UPDATE: Re-reading this thread, the question has been previously asked and my suggestion for the easiest solution was to duplicate the scripts and have one for each Echo you want to announce to. That may still be the best way to do it. :)

Posted on
Wed Aug 26, 2020 9:45 pm
mundmc offline
User avatar
Posts: 814
Joined: Sep 14, 2012

Re: Alexa Announcements

autolog wrote:
mundmc wrote:
..... Any thoughts super appreciated!

It is a long time since I have looked at this and will have to refresh my memory on how it works.

I will see if I can find some time tomorrow to look into it for you. :)

UPDATE: Re-reading this thread, the question has been previously asked and my suggestion for the easiest solution was to duplicate the scripts and have one for each Echo you want to announce to. That may still be the best way to do it. :)
I am embarrassed that I spent way more time screwing with the code and working on it than I should have, whereas I should have been reading this post through again!

Asked and answered- that’s not a hard implementation, no need to devote any more time to it, my thanks :)

Edit- I previously tried having the python script loop through a list and individually call each one, but they had progressive delays- not sure if it was my crappy understanding of how computers work. I might have been calling Indigo IN the loop. Will tinker)

Posted on
Mon Dec 14, 2020 10:09 pm
ryanbuckner offline
Posts: 455
Joined: Oct 08, 2011

Re: Alexa Announcements

I was able to get this working by referencing the steps in the original post. This is awesome!

This would make an amazing plugin.

Who is online

Users browsing this forum: No registered users and 1 guest