Voice Monkey Logo Small

The EASY Way To Trigger Alexa Routines From Home Assistant

Alexa Routines from Home Assistant

UPDATE – Fixed some bugs with some of the code below. Thanks for all your feedback.

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 TTS 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:

Home Assistant Voice Monkey configuration

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; charset=utf-8'
    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 the following 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 as above.

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 HASS 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; charset=utf-8'
    payload: '{"access_token":"ACCESS_TOKEN","secret_token":"SECRET_TOKEN","monkey":"{{monkey}}","announcement":"{{announcement}}"}'

Now when your testing, you must also send an ‘announcement’ parameter along with the monkey ID in the Service Data field e.g.
{"monkey":"MONKEY_ID","announcement":"YOUR TEXT HERE"}

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!

26 Comments

  • Tim Grimley 27 March 2021

    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?

  • Christian 29 March 2021

    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

  • James Inge 5 April 2021

    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.

    • Christian 7 April 2021

      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!

  • Mark Jeffreys 14 April 2021

    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

    • Mark Jeffreys 14 April 2021

      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

      • Christian 14 April 2021

        Nice!

        Glad you got it working Mark!

        Enjoy!

        • Juan Manuel Lopez Molina 21 April 2021

          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}’

          • Juan Manuel Lopez Molina 21 April 2021

            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

          • Juan Manuel Lopez Molina 21 April 2021

            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

      • Mark 7 May 2021

        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.

      • Yves Paul 21 May 2021

        What was the Problem?

      • Santosh 14 July 2021

        I’m still unable to get it to work after trying all that is mentioned. Please help.

  • Juan Manuel Lopez Molina 21 April 2021

    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

    • Juan Manuel Lopez Molina 21 April 2021

      solved, i saw christian github page and was really clarifying, thanks for all

  • Yves Paul 21 May 2021

    I have same problems then Marc Jeffreys. It doesn’t work

  • Adrien 24 May 2021

    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?

  • Adrien 26 May 2021

    seems there is no support.. too bad, seemed interesting but if it does not work…

  • John 11 June 2021

    Same problem as Mark, but I don’t know what he did.

  • Rich Nuzzi 21 June 2021

    If I want to create several rest commands for several automations/monkeys, should I just change the “trigger_monkey” to “trigger_monkey1” to differentiate between the two different monkeys? If not, how would I have several different money codes in the config file. Thanks!

  • cory 29 June 2021

    this works in configuration.yaml, and shows how to make 2 separate commands

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

  • Christian 4 August 2021

    Hi all…

    I did finally find some bugs with the code and so I’ve updated this article and it should now work.

    Thanks for your patience!

    Christian

  • Gavin 5 August 2021

    I don’t know where the problem is, but this simply doesn’t work on my version of Home Assistant (Core running in Docker).

    The url generated at Voice Monkey does seem to work fine, as does triggering it from the VM website. Adding the complete url directly as a rest_command in HA works fine too, so it’s some issue with the template coding given here, which I don’t have the time or patience to work out at the moment.

    If I can get it working it might be the perfect solution to avoiding IFTTT to trigger certain Alexa routines when I leave home (since the great gods of Amazon haven’t seen fit to reward the UK with location based routines yet…)

  • Gina S 25 August 2021

    I tried following the post and comments to make home assistant work with voice monkey, but it was not that straightforward, so for those that are still unable to configure it, here is how I did it:
    1.on the secrets.yaml (just remember that ATOKEN and STOKEN need to be replaced with the ones provided by voice monkey)
    monkey_payload_1: ‘{“access_token”:”ATOKEN”,”secret_token”:”STOKEN”,”monkey”:”echo-dot-monkey”}’
    2. on the configuration.yaml
    rest_command:
    trigger_monkey1:
    url: https://api.voicemonkey.io/trigger
    method: POST
    verify_ssl: true
    content_type: ‘application/json; charset=utf-8’
    payload: !secret monkey_payload_1
    3. on an automation,script or service call (I just selected the option Edit in YAML so it was easier to add the data):
    service: rest_command.trigger_monkey1
    data:
    echo-dot-monkey: echo-dot-monkey
    4. on the alexa app I created different routines where the trigger is Smart Home echo-dot-monkey.
    5. All my routines work when the monkey is triggered.

    I’m just having trouble adding an image to display on my echo show, other than that it works like a charm. If you were able to attach an image, please let me know.

  • ichrispod 31 August 2021

    This works great! But how do I call this service from the LoveLaceUI?

    I would like to create a button that would then trigger the action.

  • Sean Fritz 25 October 2021

    When I copy the code in and go to test it in the Dev UI. There is no Service data filed after selecting the rest command service.

Leave a Reply

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