Multiple Alexas - DeviceID Trigger depending on which Echo sent request (Upstairs Echo, Downstairs Echo)

it cant be done with hue and with a skill you would get:

alexa, ask homeassistant to turn on the tv
instead of
alexa, turn on the bedroom tv.

amazon hast made it possible yet to send commands other then music commands to a specifik device.

@luma, i understand the use you like, but that use isnt there in alexa.(yet)
you cant use “turn on …” to control intents in HA directly.

Hi,

I got this working! You will need to do a little mod in alexa component. Locate alexa/intent.py and add the following lines to the async_handle_intent function right after the line “alexa_response = AlexaResponse(hass, alexa_intent_info)”:

deviceid = message.get('context', {})  \
                  .get('System', {})  \
                  .get('device', {})  \
                  .get('deviceId')

alexa_response.variables['deviceid'] = deviceid

This will add the deviceid as a “slot” so you can use it on templates. To test i did a “launch request” skill (see alexa component docs) and added this to my intents:

amzn1.ask.skill.xxxxxxxxxxx:
  action:
    - service: notify.someone
      data_template:
         message: "I was called by {{ deviceid }}"
    - service: homeassistant.toggle
      data_template:
         entity_id: >
                 {% if deviceid == "amzn1.ask.device.<longstring-device1>" %}
                   light.w1
                 {% elif deviceid == "amzn1.ask.device.<longstring-device2>" %}
                   group.luzes_sala
                 {% elif deviceid == "amzn1.ask.device.<longstring-device3>" %}
                   group.luzes_escritorio
                 {% endif %}
  speech:
    text: OK

I used the notification part as way to test/retrieve the deviceid.

One problem with the launch request skills is that amazon don’t let you use any word as some of them are used by other skills/purposes, so you cannot just say “alexa, lights”. Just for the fun, and lack of imagination of a better word/phrase, I’m using “alexa, banana” and them HA toggle the lights of the room where my dots/echos is located. :slight_smile:

2 Likes

Nice.

i got it working for my Alexa Appdaemon App also.
but thats a custom skill so i need: alexa, ask appdaemon to turn on the lights.

its probably possible to add it to emulated hue as well.

Hi,

emulated hue would be nice but I guess it would require a lot of other changes to the component/protocol. Maybe not :-).

i think it must be possible to let emulated hue update a sensor that has the speaking device as state.

i might look into that at some point.

Hi,

I’m not sure. There seens to exist a strange behaviour when you have multiple echos in which one of them seems to be the “master”, so even if you ask to another echo, the master is the one who talks to the hue bridge.

cant be. (or at least i dont see how)
i have 6 echo’s who all can use hue commands.
which would be the master?
and when i shut that one down, will all others not respond anymore?
no it doesnt matter which one i shut down, there is always response.

i also never connected devices to a single echo, so how is then decides which is the master?
and how does 1 echo send commands to another echo? untill now it is impossible to send a command from 1 device to another, if i am correct.

Well, the first time I notice this behaviour was when I was configuring a echo + HA at my work. This echo was connected to same account as my home echos and I was configuring emulated_hue at my work’s HA so we could control the coffe machine. No matter how many times I asked this echo to “find my devices” it didnt find my emulated_hue. Digging a little further and doing some tcpdumps, I found that my other echo at home was sending packets to broadcast address port 1900 and to my home HA at port 8300.

Btw, while re-testing this now I just saw my echo home trying to send a packet to my work’s echo. Go figure…

running multiple echos in multiple networks.
yeah i can see where that goes wrong.

i just took a look at the emulated hue, and its hard to pinpoint the incoming data from alexa there.
i can try some stuff, but with HA that means restarting HA every time and i dont want to do that now.

but when i look at the Alexa documentation, the device id that is getting the command is always send in the response nowadays.

ill take a look at it when i have created a testing environment.

Awesome work, been waiting so long to get this working. Will really help with my TV automations! :slight_smile:

Since that one was kind easy, I’m also thinking about userid! I dont know if I got it right, but alexa send a userid on the json and it seems that this is based on the voice signature of the user? I thought that the userid is linked to the user account on amazon, but this link sugest that it’s not:

https://hackernoon.com/identifying-users-in-alexa-skills-ff189d03ed1d

Or I got it wrong?

no its not based on the voice. (that would be very nice)
you can read about that here in the docs:
https://developer.amazon.com/docs/custom-skills/link-an-alexa-user-with-a-user-in-your-system.html

i just did a better search and it seems they have implemented voice recognition at the end of last year.
that makes me very happy so ill dive into that.!!

and i did, and its still not alive in germany :frowning:

yes, I was eager to get home and try that. You have to create the so called voice profiles.

yeah i found that they announced it was coming in the end of last year, but its still not in the app here.
and i cant find any news thats its actually released in germany, so i think ill have to wait. :frowning:

Hi,

did you tried “alexa, learn my voice”? (or the equivalent in german?)

she doesnt know the answer to that :wink:

ill just have to be patient.

Same in the UK, just like multiple lists!

The official Android widget is cool though, no need for Reverb.io now and drop in etc all work perfectly through it.

1 Like

Well, it was fun to mess with the code, but just discovered that Amazon has that function already (at least for US), since the end of last year :-(. Thru the app you can associate smart home devices to your echo/alexas and just say “alexa turn on/off lights”:

Of course, using emulated hue you can do a lot more :-).

yeah i knew about that.
but i do want to do at little as possible in the alexa app.
its not a nice environment to maintain.
i also dont group lights or other devices there.
i tried to use routine, to set a channel on my dumb TV.
bad result.
i have switches for the numbers 0 to 9
and channel 1 to 9 go as wished, but if i try channel 16 i get sometimes channel 6 and other times channel 61.
routines doesnt have a delay function. and doesnt keep the order that you set it on, but just gives the commands almost instantly.

so i rather say “alexa tell AD to turn on the lights”
or “alexa turn on the livingroom lights”

i must say i also am not someone that likes to give single word commands.
i rather ask in a polite way :wink:

if it wouldnt confuse her sometimes i would use “turn on the livingroom lights please” or “please turn on the livingroom lights” :wink: