Help with variable in Node Red

I was hoping maybe someone could give me some help with a flow in node red. My echo speaks stopped working today and I can't get it fixed. I have it installed on smartthings, so maybe that's why? Anywho ... I care not.
I've discovered that I can set my announcements through node red ... which is so yesterday for most of you, but I'd like to set up so that the node announces if %something% happens. Like who's lock code was entered, or what mode the house just went into with out writing a bunch of flows. Is someone willing to give me lesson on this?

If you are using the Alexa2 palette, you'll want a "Routine" node with the dropdown option set to "Custom"

Then you need a properly formed message where:

Screenshot 2020-07-10 21.07.02

Depending on the payload coming in will help you build up the message, but that's the format it needs to be to make Alexa speak

"devices" can be an array as well with each value being the exact name or serial number of the device or devices properly escaped. You can pick out your exact device names on this page

1 Like

so i'm trying to announce mode change. so how do I announce what mode it changed to? I've been successful in making alexa talk what I type but I'm not sure of how to get that to point B

That can vary based on what you're using to speak your messages and how the message needs to be formatted. I would personally set that up with a function node, but things like this you can also use a change node to set it up.

Check the state of your mode so you'll get a msg.payload of "Home - Evening" or whatever you have. Then in the function node go

var mode=msg.payload

var message = "The house has just been set to" + mode

msg.payload.domain = "notify"
msg.payload.service = "alexa_media_front_entrance_echo_dot"
msg.payload.data.data.type = "announce"
msg.payload.data.message = message

return msg;

Your msg setup would change based on whatever is needed to call your alexa announcement node.

1 Like

It's tough to just paste in the flow because of all the alexa config information gets exported as well, here are some screenshots.

btw, MRobi's example there is only if you have Home Assistant running

(Note: oh yeah, "msg,payload" may need to be "msg.mode", sorry, I don't use HE's modes any more, so a little rusty)

Screenshot 2020-07-10 21.19.10

1 Like

Correct. I run NR on home assistant, so setting up my alexa message would be different. But setting the variable and inserting the variable into the message would be done the same way. You just need to change the message setup to work with however alexa is called on HE.

1 Like

I am running NR on a pi connected to HE, so even though your solution won't work for me, it might work for someone reading this thread and that is huge. Thanks for putting that out there.

@morningz - let me tinker a minute ... I'll be back. I'm bound to mess something up.
:grin:

1 Like

I'm getting invalid sequence node
this error

image

make sure you have nested payloads... and it's "type = speak" not "type = custom" (Custom gets set in the "Routine" node)

btw, that's only if you are using this palette

The format is a little odd/funky with the "payload" inside another "payload"

Yes, that's the palette I'm running
image

the top "type" use "speak" as the value

the inside "type" can be "regular" or "announcement" (which precedes what she says with an annoying beep first)

This "Create Message" function node works with a Hubitat mode node right before it, just replace with your device name. I had the payload wrong in my previous posts, it's been a while since any Hubitat node has been in a flow of mine.

if you change "regular" to "announcement" you'll see she'll beep before she talks

return {
    "payload": {
        "type": "speak", 
        "payload": {
            "type": "regular", 
            "devices": ["Living Room Echo8"], 
            "text": "Mode Changed to " + msg.payload.value
        }
    }
};

Screenshot 2020-07-10 22.31.32

sorry, had unannounced company. Thanks for this. I'll do it and report back.

I must be doing something wrong. Still getting invalid sequence node. Even when I copy your snip into mine and change it. The message gets logged but not played.
image

image

image

I had terrible trouble getting Alexa to communicate with my stuff last night. I logged out of my pi and it started communicating. So, ... yah ... suggestions?

It's a small difference, but enough to prevent from working: you didn't copy exact, "announcement" has to be lower case, i see upper case "a" in your screen shot.

I even changed my working flow to "Announcement" and confirmed it didn't work.

JavaScript is case sensitive language, so anything that is a key name, flag or setting for a node, use the exact case they have in the documentation

btw, once you get into the groove of using this node, just know that you can use the "saml" option (which is just a different way of putting together the payload) and make Alexa have emotions when speaking. For instance, I was working on something where when batteries need to be replaced on some device, she let's me know in a sad voice. One of those rare times when I have a lot of time on my hands to toy around with things like those kinds of settings lol

This node certainly looks more flexible than the alexa service in HA. I think I might give it a try after seeing these posts.

1 Like

Just to note, the documentation is pretty lacking :-1:

A few of us on this forum have spent a ton of time slogging through it to get what we need from it.

So this is my "Listen" flow. I first have to create a Routine inside the Alexa app to set up the phrases and then set the action to simply "Wait 5 seconds". That's enough inside Alexa, now you can plop an Event node in Node-RED and do what you gotta do.

Screenshot 2020-07-11 08.38.21

Stripped out most of the branches so i could show just that TV example. You have to account that sometimes the wake word gets through, plus this gives an option to catch mistakes. For instance, and not in the code snip below, when i say "raise master blinds", sometimes she hears "raise masterminds", so i have both in my logic and it works more reliably :slight_smile:

That would all be a NIGHTMARE in YAML lol. :: shudder ::

Anyways, back on topic, I hope the speak routine up above works, it definitely should at this point.

You know... You guys could always submit a pull request to update the docs with all the info you've scrounged up... (ASSUMING it is on github, and not just NPM - I didn't look )

I asked him a few months ago, he didn’t seem too interested

2 Likes

I am stumped. I followed your example to the tee and changed the type and still nothing. These are older dots, so in the other flows that I have (like for my radio) I'm using the device serial number to get it to work. Could this be the issue? But it works fine if I use the built in form. Using a function node

image