Send Commands to Alexa

building on @e1miran and @KayXi2014 I made a rest_command that accepts a messge, that message is then converted to voice and sent to alexa as though you spoke it!

It uses the bespoken.io server to set up a “virtual echo”, you can then send strings of text to this virtual echo and it behaves as if it was an Echo device on your account. For example… I can send it “Play The Beatles in the bedroom” and my bedroom Echo starts playing The Beatles.

Here’s how you set it up:

  1. Go to https://read.bespoken.io/end-to-end/setup/ and follow the 4 steps under Creating a Virtual Device -> Virtual Devices for Alexa.
  2. The important thing here is that you need the get validation token
  3. in Home Assistant set up a rest_command like so:
rest_command:
  ask_alexa:
    url: https://virtual-device.bespoken.io/process?message="{{ message }}"&user_id=<your-validation-token>'

Simply replace <your-validation-token> with the one you received in step 2 above. Note: you will not include the angle-brackets < >

That’s it! Now you can send alexa any command you would normall speak from, say, an automation like so:

  trigger:
    - platform: time
      at: "06:00:00"
  action:
    - service: rest_command.ask_alexa
      data:
        message: "Play my wake up playlist in the bedroom"

You can also change the language and the voice that will be used to “speak” to Alexa (defaults are US English and ‘Joey’). You can find out how to put those parameters in the URL here:

https://read.bespoken.io/end-to-end/api/#http-api

7 Likes

thats certainly easy.

but i am still more comfortable to do more work and reach the same goals without giving away my amazon account to strangers.

allthough this has 1 advantage: you can start (custom) skills by sending a command, and thats about the only thing i still miss in routines.
but ill wait untill they add that to alexa.

1 Like

That won’t take long since BeSpoken is an Amazon partner.
August 16, 2018, Bespoken Selected by Amazon to Add Automated Testing to the Alexa Skills Kit

thats not really what i want them to add, but well see how things develope :wink:

Cant this be done with tts? I use tts with speech from amazon polly to f.ex tell me when someone trigger the motion detector outside the front entrance

This is not anything like TTS. You’re not getting Alexa to talk to you… it’s the exact opposite: You’re able to “speak” to alexa (look at my example). You are not giving Alexa things to say, you’re actually sending commands.

For example, If you want to make Alexa start playing music from home assistant (my use case), this is the only way to do it.

no thats not true.

you can start music on 2 other ways.

  1. with the (custom) alexa mediaplayer component
  2. with a sh script thats also on the forum (thats what i use)

with that script you also can

  1. start routines created in alexa
  2. ask for the weather
  3. ask for traffic
  4. ask for daily updates
  5. let her speak (TTS)
  6. create groups
  7. delete groups
  8. find out which alexa was used last
  9. change volume
    or anything else that can be done from the alexa app.

You can’t select the media you want to play with Media Player - it will display what is playing and allow you to skip fwd/back, pause, etc. But you can’t pick a song and start to play it.

Please point me to this, as i would be interested as well…

I think you misunderstand. I have a trigger in HA that fire when my wife turn in to our driveway. Now my BLT speaker tells me that Y is on the driveway, but if I had Alexa and the voice said Alexa turn on the front porch light instead I am sure that Alexa would do that. Or what is it I dont understand?

you can use services to play music.
so you can create scripts or an input select with an automation.

the script you can find in this topic

as well as lots of info how to use it and set it up.

@Yuran why do you want to tell alexa to turn on the front porch light? just turn it on in the script or automation.

I guess it might be a little confusing… there is no audio involved at all. You send a text string to the Alexa service. Alexa processes that string of text as though you spoke it. It’s a way to send commands to Alexa by text rather than speech.

That was just an example. If I had Alexa I could tell it to do whatever you want using TTS. That was what I meant. I dont use it, I just use TTS to tell me when f.ex dishwaher is ready wife comes home garage door is open 22.03 etc. And all local. no need to leave your credentials to third person

OK point taken. But to me it seems a unnecessary long way to go

Alexa to play some music, how do you do it? You use a TTS and get a speaker to play it out loud so Alexa can hear it?

thanks for sharing!
the rest_command didn’t work for me, so i made it a shell_command which works great:

shell_command:
  ask_alexa: >-
      /usr/bin/curl -X PUT -G 'https://virtual-device.bespoken.io/process' --data-urlencode 'message={{message}}' --data-urlencode user_id=<your-validation-token> --data-urlencode language_code=de-DE -H 'content-length: 0' -o /Users/ix/.homeassistant/scripts/alexa_response.json

i use it mainly to manage my bring shopping list via snips. since bring does not care to publish a public API, i can emulate an API using their alexa skill. actually by using this it’s possible to use almost any alexa skill out there with snips (if you don’t mind the lag).

Thanks for this - I took a look and set it up - I run in docker, so I need to use the *_plain.sh variant of the script, but it works. It’s certainly way more involved. It will be interesting to see how it holds up long-term as it seems pretty fragile (needing to export cookies, store them in the /tmp dir, etc.). Could be lots of care-and-feeding to keep it operational.

However, as you mentioned, it does cut out the middleman, so there’s that. And it has TTS capability, which I don’t think you can do with Bespoken

To get the tts I use the tts component and POLLY platform.
I used this tutorial

All texts I need is created ones on the Polly cloud änd then reused

its nice to use TTS in that way. i used something simular.
but it has 1 disadvantage, its on 1 place only.

i already got 7(and it will grow up to 16) times alexa around the house. so with alexa TTS i get to use TTS on 7 different locations.

@ha_steve yeah it is a hack, so its always the question how long it holds. but i got it working without a problem for a long time now.

you can do the TTS with bespoken too. its actually nothing more then the simon says functionality.
even if you cant do it directly you could do it by creating a routine and start the routine with bespoken.

but this is way more direct. and indeed without a middleman (and i have a hard time trusting someone, when i cant find name, place, location, etc. etc. and they use an io website)

Its one sentence yeas but I have 3 BLT speakers paired so I hear the same speech in 3 different places in the house. And as I said I have no interest in Alexa or GA, I need the exercise as retired.Just had a look at the script and because each speaker has an entity ID it would probably be possible to control where the speech is sent out. But it is the wrong day to day to investigate

Hey, i am all new at this home assistant , so my question , with the above would i be able to create a switch button on hadassboard to be enable to control a switch wich works with alexa , but not yet with hassio?
I have these livolo switches wich are connected with their on zigbee gateway and their own app , but i would like to build a dashboard with all my stuff in it , so i don’t need to switch between apps. Now livolo isn’t supported by hassio yet but it is by Alexa… So maybe this could be my solution?