Categories
Smart Home Software & Devices Voice Monkey Tutorials

The EASY Way To Trigger Alexa Routines From Home Assistant

Alexa Routines from Home Assistant

Home Assistant (HA) is a piece of free home automation software for controlling your Smart Home.

People use it as the central hub or command centre for their smart home tech.

With HA you can link all your devices in just one place and build cool automations based on the state of all your devices.

Alexa + Home Assistant

Whilst it has support for some Alexa functionality, it has been very difficult until recently to trigger Alexa routines directly from Home Assistant.

Now, services such as Voice Monkey make it as easy as sending an API request to trigger Routines and make dynamic voice announcements through your Echo speakers.

What Is Voice Monkey?

Voice Monkey extends Alexa’s smart home capabilities.

It offers an API to trigger Alexa Routines remotely from services such as Home Assistant and IFTTT.

It also allows you to make dynamic text to speech announcements via the API. Want to announce to one or multiple Alexa devices that a camera detected motion? You can do that with Voice Monkey 🙂

How To Trigger Alexa Routines from Home Assistant

The process is easy.

Firstly, sign up to Voice Monkey and follow the instructions to create your first Monkey and Routine.

A Monkey is simply a virtual doorbell device which can be pressed (or triggered). We can use these doorbells, or Monkeys, as triggers in our Alexa Routines.

But how do we trigger these virtual doorbells from Home Assistant?

Trigger Your Monkey With The RESTful Command

In Home Assistant you can make API calls using the REST command.

Simply add the following to Home Assistant’s configuration.yaml file:

HA voice monkey config

Here’s the same code so you can copy and paste:

# Voice Monkey Alexa Routine API call

rest_command:
  trigger_monkey:
    url: https://api.voicemonkey.io/trigger 
    method: POST
    verify_ssl: true
    content_type:  'application/json'
    payload: '{"access_token":"ACCESS_TOKEN","secret_token":"SECRET_TOKEN","monkey":{{monkey}}}'

In the code above you should replace ACCESS_TOKEN with your own access code found in the Voice Monkey dashboard and SECRET_TOKEN with your own secret code (make sure you keep it secret!).

Even better, as pointed out by James Inge in the comments below, keep your tokens in the a secrets.yaml file to ensure they don’t accidently get leaked by way of a public Github post etc.

Testing

Go to developer tools and test it out.

First, restart the server (Configuration -> Server Controls -> RESTART) to apply the new changes:

  1. Go to Home Assistant’s Developer Tools -> Services screen
  2. Select “rest_command.trigger_monkey” from the Service menu
  3. Enter this in the Service Data field to trigger your Monkey:
    {“monkey”:”MONKEY_ID”}
  4. Select the CALL SERVICE button

You must replace MONKEY_ID with the ID of your Monkey found in the Monkey manager section of the dashboard.

And that’s it!

You can now start triggering Alexa Routines from Home Assistant.

Making announcements

To make announcements using Alexa, you must first configure an Alexa Routine which is triggered by a Monkey.

The last action in your Routine must be to open the Voice Monkey Skill whilst also selecting which Alexa device to make the announcement from.

In your HA set-up you simply add the ‘announcement’ parameter to your payload object. Here is the same code above but with the ‘announcement’ key + value.

# Voice Monkey Alexa Routine API call

rest_command:
  trigger_monkey:
    url: https://api.voicemonkey.io/trigger 
    method: POST
    verify_ssl: true
    content_type:  'application/json'
    payload: '{"access_token":"ACCESS_TOKEN","secret_token":"SECRET_TOKEN","monkey":{{monkey}},"announcement":{{announcement}}}'

Now whilst your testing, you must send an ‘announcement’ parameter along with the monkey ID in the Service Data field.

I hope that helps get you started creating some awesome automations with HA and Alexa.
Let us know your automation ideas in the comments below!

18 replies on “The EASY Way To Trigger Alexa Routines From Home Assistant”

Definitely some useful info for Home Assistant Integration. Along the lines of Home Assistant have you considered a Node Red palette that can interact with the skill that way?

Hi Tim,

I’m not a Node Red user yet, but I’ve heard how powerful it is, so I’ll definitely investigate further and a palette at some point if I can!

Christian

This is a really handy way of letting Home Assistant make voice announcements. Unfortunately, the example in this blog post took a bit of work before it would function. There’s a missing single quote mark at the start of the payload line, and the “access_code” and “secret_code” parameters should be “access_token” and “secret_token” respectively. The details on the API docs page are OK though!

I also moved the whole payload line into my `secrets.yaml` file, to avoid revealing my tokens if I post my configuration on github, and added a templated announcement message, so HA can control what Alexa says when my monkey is triggered.

Woah big mistakes…thanks James for pointing these out, I have updated the post so it should all be correct now!

Great shout on the secrets.yaml too!

Sorry I’m struggling to get this to trigger a routine? I have followed the directions above adding the following to my Configuration.yaml

# Voice Monkey Alexa Routine API call

rest_command:
trigger_monkey:
url: https://api.voicemonkey.io/trigger
method: POST
verify_ssl: true
content_type: ‘application/json’
payload: ‘{“access_token”:”************”,”secret_token”:”************”,”monkey”:{{monkey}}}’

and this in the developers tools

service: rest_command.trigger_monkey
data: ‘“monkey”:”smoothjazz”’

When I trigger the routine from manage monkey it works.

Any help would be very appreciated

James helped me out with this and it’s now working brilliantly. I am able to call the service from HA and have added to a lovelace page. I call alexa routines to play music genre and have the mini media player in the same screen showing the music that is playing.

Thanks James

hi. i’ve got everything working, but when i try to call rest from HA i’ve got
Error. Url: https://api.voicemonkey.io/trigger. Status code 400. Payload: b'{access_token=xxxx,secret_token=xxx,monkey=echo-cocina,announcement=Hello%20monkey&image=https%3A%2F%2Fxxx%2Flocal%2F1.jpg}’

now i can send rest command but ive got an error from voice monkey in the echo show saying that i have to restart ifftt

if i take out &image=xxxxx, it works, must be something with image=, i test it throug browser and works, i dont know what is the problem

Hey Mark, can you share the fix? I am having the same issue. I can trigger the routine from voiceMonkey portal but not from HA. My configuration is exactly as posted here but nothing is working.

from log in voice monkey.:
Time User Agent Status Response
08:04:56 HomeAssistant/2021.4.6 aiohttp/3.7.4.post0 Python/3.8 ok

hi, I have followed every step of this nice tutorial to try and trigger a routine in Alexa. But when testing the command in the developer tools, nothing happens. The trigger works from the Voice Monkey website, but nothing happens when trying to trigger from Home Assistant.

service: rest_command.trigger_monkey
data: {“monkey”:”projector-on-and-screen-down”}

What is wrong?

Leave a Reply

Your email address will not be published. Required fields are marked *