Easy Node Red Room aware Alexa voice commands

This is an example with lights. This way you will just have to say ‘Turn the light on’ (or whichever sentence Alexa understands to turn a light on) and the appropiate light will turn on depending on the area you are in. That applies to any device: fans, tvs, curtains, ‘the mirror’ and so on… just one word for them all and no need to create a dozen routines to cover all kinds of sentences.

you will need: node-red-contrib-alexa-remote2
and: node-red-contrib-alexa-home-skill

First section, ‘Setting currently listening device’: https://pastebin.ubuntu.com/p/vdYV7FQbqj/

First node listens to Alexa’s events, acknowledges which device you’re talking to and sets a flow.echodevice containing the name of the listening device. You needn’t change anything in the nodes without a label, leave them as they are. In fact you only need to add you account to the first node, leave everything else as is. Don’t worry abou having several devices near listening to you, the node picks the right device

Second section, ‘Turn light on according to which device listened’: https://pastebin.ubuntu.com/p/hCZsRg8pTg/

You have to create an account and an alexa device called ‘Light’ or ‘The light’ in: https://alexa-node-red.bm.hardill.me.uk/docs

after creating the device ‘Light’, go to your Alexa app and install the Node Red Skill, which will allow Alexa to discover the device ‘Light’

Once discovered, you must read the documentation to understand how to make requests. It allows turning on/off, changing color and white temperature, increasing and setting brightness percentages.

In the node ‘Echo Device’, you must set the name of your devices as they show in your Alexa app

for the Action Node, read the documentation

It works really nice!

Final flow: https://pastebin.ubuntu.com/p/3xb8VZsKtQ/

1 Like

A far simpler way is to use the Alexa app to tell your echo devices which devices are in the same room as them.

For sure, in fact I have it that way and I’m gonna leave it that way… But for some people that need more complex actions when they say ‘Turn on’ or whatever, this is a great solution

for example, when I say turn on the light, if it’s dark, turn it on white and at 100%, however, if I’m watching a movie, turn it on blue and at 20%… you just can’t do that with the Alexa app, unless you don’t mind recalling various different sentences, one for each state

Here goes the flow for all light related actions but increase/decrease brightness %. Set % is included

But that’s not relevant to the room.

“Alexa, turn on the light” > Alexa knows which light to turn on because it’s grouped in the Alexa app > Homeassistant/node red receives the command to turn on the light > applies the correct parameters based on whether or not you’re watching a movie.

At no point in that flow did homeassistant need to know which Alexa device was used, and in fact it would be counterintuitive as I could just as easily used a different echo device in the house to turn on the same light - “Alexa, turn on the living room light” to the bedroom echo device.

you might be right

There was a mistake in the previous flow, final flow:

https://pastebin.ubuntu.com/p/3xb8VZsKtQ/

Do alexa groups work the same way when you say, for example, ‘Alexa, turn off the fan’? or ‘Turn off the TV’… Cause I don’t think so… Final flow.

Of course. You tell Alexa what’s in the same room as the device, and then when you say turn on X it turns on that room’s X. Or you can say turn on bedroom X and it will turn that one on instead.

you can’t have two smart switches with the same name ‘Fan’, can you? It would work for that.

Another advantage is that when you turn off a light, lifx for example, home assistant can take up to 15 seconds to realize it’s been turned off. If you have any automation that triggers when that light changes its state, this is a great thing to have.

Or for example let’s say you have 3 mirror spread over your house in 3 different locations, and you want to be able to say ‘turn on the mirror’… it would be useful in that scenario too.

another advantage is probably with DIY projects?

but hey, no problem my man, if you don’t find it useful, just ignore it. I might just be a silly guy who likes to overwork

I would appreciate if you could send me a flow or some code to completely understand what you mean when you say you can do the exact same thing using only the Alexa app, cause I don’t see that

I’m using node-red-contrib-amazon-echo (node) - Node-RED, controlling all devices I need and everything local.

Alexa controlled Node-Red nodes supporting latest Amazon Echo devices

NO Alexa Skills required.

NO cloud dependencies.

What I don’t like about that one is that when you say ‘Turn on X light at Y%’, if the light was turned off previously, or something of the like, it’ll send two consecutive messages, one with the previous brightness % and another with the new brightness%. I have 95% of my devices using node-red-contrib-amazon-echo (node) - Node-RED for plain on/off commands

if you work with light transitions, they get crippled… flows are triggered twice and I ended up using a throttle to avoid that

but yeah, it’s great for on/off commands, one less dependency

No need to get defensive about it.

I can’t send you the internal workings of the Alexa app, because it’s proprietary, but I can assure you that you can add devices to groups in the app to group them with a particular echo device. It’s not that complicated a concept and it works really well.

The mirror example you gave:

Put the bedroom mirror in a group with the bedroom echo, kitchen mirror with kitchen echo, living room mirror with living room echo.

“Alexa, turn on the mirror” will turn on the mirror in the room that the echo device is in.

I didn’t know that could be done. I believe you can’t put several devices with the exact same name, you can’t put 3 devices with the name ‘mirror’. What you are saying is that if you set 3 different devices to ‘mirror A’, ‘mirror B’ and ‘mirror C’ in different groups,by saying ‘turn on the mirror’, Alexa will turn the mirror of the group containing both the echo device and the mirror X. I didn’t know that. Are you 100% positive about it? I believed that if you put Mirror A, B and C and said ‘turn on the mirror’, Alexa would complain: ‘You have several devices called mirror, which one do you want to turn on?’. At least that’s my experience.

By code I meant, how do you get your device to turn on according to some HA conditions?

It works fine. I use it for multiple lights in rooms, heaters, all sorts.

It seems to work on a sort of hierarchy, so if you have a mirror in the room and you say ‘turn on mirror’ it will turn that one on. If you don’t, but have 3 in other rooms of the house it will ask you which one.

As for the homeassistant conditions, you just trigger on the device changing state and then perform the action, same as any other automation.

how do you get your device to turn on according to some HA conditions?

Lights to come on white, unless watching movie (at which point make them blue)

“Alexa, turn the light on”

trigger:
  platform: state 
  entity_id: light.led
  to: 'on'
action:
  service: light.turn_on
  data:
    entity_id: light.led
    color_name: "{{ 'blue' if is_state('binary_sensor.movie', 'on') else 'white' }}" 

Yep, I have a few automations like that one… that’s probably one of the few things where this flow is an advantage over using the Alexa app… At least with lifx, there can be a great delay. It can take up to 15 seconds before HA notices the light has changed its state so… it gets ugly you know

anyways with update_entity polling every second I managed to solve that…

I’ll leave the flow here just in case somebody finds it useful. I actually made it at request of a friend who needed it, but yeah, the Alexa app is powerful enough to avoid the hassle

1 Like

Did you send the flow, I like what you are saying.

There you go, all you need to know is in the first post