Voice Monkey Logo

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!

43 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?

    • Mike 7 December 2021

      Hi Tim,

      I was fortunate to start using voice monkey in smartthings webcore before transitioning to HA, and so I’ve worked out a way to trigger voicemonkey from node red.

      It relies on a global variable – which i set up using a one time trigger node on startup. In this example the monkey is “MonkeyStudy”

      Set up global:

      [{“id”:”7f5367d4.74cf38″,”type”:”inject”,”z”:”703f63d.0350c9c”,”name”:”Write Monkey Globals”,”props”:[{“p”:”payload”},{“p”:”topic”,”vt”:”str”}],”repeat”:””,”crontab”:””,”once”:true,”onceDelay”:0.1,”topic”:””,”payload”:””,”payloadType”:”date”,”x”:160,”y”:120,”wires”:[[“61c2340a.ef8dfc”,”e694ad4f.90b63″,”673d9953.8e1438″,”28d3fbf0.7c1914″,”69fcd34d.3c497c”,”a78e046a11e7e242″]]},{“id”:”28d3fbf0.7c1914″,”type”:”change”,”z”:”703f63d.0350c9c”,”name”:””,”rules”:[{“t”:”set”,”p”:”MonkeyStudy”,”pt”:”global”,”to”:”https://api.voicemonkey.io/trigger?access_token=MyAccessToken&secret_token=MySecretToken&monkey=monkeystudy&voice=Amy&announcement=”,”tot”:”str”}],”action”:””,”property”:””,”from”:””,”to”:””,”reg”:false,”x”:450,”y”:160,”wires”:[[]]}]

      Flow:

      [{“id”:”c3c027f5.d77ef8″,”type”:”inject”,”z”:”87d9fec5.6a54″,”name”:””,”props”:[{“p”:”payload”},{“p”:”topic”,”vt”:”str”}],”repeat”:””,”crontab”:””,”once”:false,”onceDelay”:0.1,”topic”:””,”payload”:”You’re in business”,”payloadType”:”str”,”x”:130,”y”:100,”wires”:[[“f3880245.22356”]]},{“id”:”f3880245.22356″,”type”:”template”,”z”:”87d9fec5.6a54″,”name”:””,”field”:”payload”,”fieldType”:”msg”,”format”:”handlebars”,”syntax”:”mustache”,”template”:”{{{global.MonkeyStudy}}}{{{payload}}}”,”output”:”str”,”x”:300,”y”:100,”wires”:[[“5cfbd6da.0adb08″,”ea24c08a.c462b”]]},{“id”:”5cfbd6da.0adb08″,”type”:”debug”,”z”:”87d9fec5.6a54″,”name”:”After Request”,”active”:false,”tosidebar”:true,”console”:false,”tostatus”:false,”complete”:”payload”,”targetType”:”msg”,”statusVal”:””,”statusType”:”auto”,”x”:550,”y”:40,”wires”:[]},{“id”:”ea24c08a.c462b”,”type”:”www-request”,”z”:”87d9fec5.6a54″,”name”:”Voicemonkey Rq”,”method”:”GET”,”ret”:”txt”,”url”:”{{{payload}}}”,”follow-redirects”:true,”persistent-http”:true,”tls”:””,”credentials”:{},”x”:580,”y”:120,”wires”:[[]]},{“id”:”f76feac7.d5a67″,”type”:”comment”,”z”:”87d9fec5.6a54″,”name”:”Working voicemonkey webhook”,”info”:””,”x”:160,”y”:40,”wires”:[]}]

      Regards

      • Chris 23 October 2022

        I had difficulty importing @mikes Node Red example.

        I created my own example for anyone who is looking to do this in the future. I have kept it simple (not storing the api secrets in global context, just setting them in the example) and used the built in http-request node to do the API call.

        I am not sure if the formatting of this message board was the issue with mikes post. so I have also included a link to the code in pastebin which wont effect the formatting https://pastebin.com/sqdEqd1w

        [{“id”:”66a31b5874350685″,”type”:”template”,”z”:”ea42b334.b6a77″,”name”:”Voice Monkey – Create API URL”,”field”:”url”,”fieldType”:”msg”,”format”:”handlebars”,”syntax”:”mustache”,”template”:”https://api.voicemonkey.io/trigger?access_token={{{access_token}}}&secret_token={{{secret_token}}}&monkey={{{monkey}}}”,”output”:”str”,”x”:750,”y”:4620,”wires”:[[“b9c082d2dc01d3ee”]]},{“id”:”b9c082d2dc01d3ee”,”type”:”http request”,”z”:”ea42b334.b6a77″,”name”:””,”method”:”GET”,”ret”:”txt”,”paytoqs”:”ignore”,”url”:””,”tls”:””,”persist”:false,”proxy”:””,”insecureHTTPParser”:false,”authType”:””,”senderr”:false,”headers”:[],”x”:990,”y”:4620,”wires”:[[“240015988728938a”,”ce8a2c08d5bdbb27″]]},{“id”:”240015988728938a”,”type”:”debug”,”z”:”ea42b334.b6a77″,”name”:”Complete msg object”,”active”:true,”tosidebar”:true,”console”:false,”tostatus”:false,”complete”:”true”,”targetType”:”full”,”statusVal”:””,”statusType”:”auto”,”x”:1220,”y”:4580,”wires”:[]},{“id”:”ce8a2c08d5bdbb27″,”type”:”debug”,”z”:”ea42b334.b6a77″,”name”:”Sucess? “,”active”:false,”tosidebar”:true,”console”:false,”tostatus”:true,”complete”:”payload”,”targetType”:”msg”,”statusVal”:”headers.nel”,”statusType”:”auto”,”x”:1180,”y”:4620,”wires”:[]},{“id”:”53c98bf8ccb4609c”,”type”:”change”,”z”:”ea42b334.b6a77″,”name”:”Set Voice Monkey Paramenters”,”rules”:[{“t”:”set”,”p”:”monkey”,”pt”:”msg”,”to”:”monkey”,”tot”:”str”},{“t”:”set”,”p”:”access_token”,”pt”:”msg”,”to”:”ACCESS_TOKEN”,”tot”:”str”},{“t”:”set”,”p”:”secret_token”,”pt”:”msg”,”to”:”SECRET_TOKEN”,”tot”:”str”}],”action”:””,”property”:””,”from”:””,”to”:””,”reg”:false,”x”:450,”y”:4620,”wires”:[[“66a31b5874350685”]]},{“id”:”bb61d96767a608cd”,”type”:”inject”,”z”:”ea42b334.b6a77″,”name”:”trigger”,”props”:[{“p”:”payload”},{“p”:”topic”,”vt”:”str”}],”repeat”:””,”crontab”:””,”once”:false,”onceDelay”:0.1,”topic”:””,”payload”:””,”payloadType”:”date”,”x”:230,”y”:4620,”wires”:[[“53c98bf8ccb4609c”]]}]

        • Chris 23 October 2022

          It is the formatting of this message board that has corrupted the node red export. Please you this pastebin link to grab the node red example

          https://pastebin.com/sqdEqd1w

  • 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

    • Cronje 18 January 2023

      What wasn’t clear to me was that

      1. MONKEY_ID just equals the name of the routine configured.
      2. Spaces are allowed in the name of the monkey but doesn’t work, and the underscore on MONKEY_ID in these docs is misleading, as underscores aren’t allowed in monkey names.

  • 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.

  • Paulo 19 December 2021

    There is a way to make a annoucement for more than one monkey at the time?
    Something like “all home” in Alexa App (I tried, but with no sucess)?

  • Randy King 30 December 2021

    Is there a way to use the REST API to retrieve a list of Monkeys by name and ID that have been setup in an account? This would be used in a home automation controller to present a list of “devices” that could be used in programs and scenes.

  • Mike 2 January 2022

    Hi Christian,

    Trying to use SSML from home assistant/webcore and I’m getting a message saying that alexa can’t access the webmonkey skill (IE, voicemonkey virtual doorbell triggers the skill, which runs the voicemonkey skill, but instead of speaking the required text, alexa says it’s having trouble accessing the voicemonkey skill

    The URL i’m testing is

    https://api.voicemonkey.io/trigger?access_token=xxx&secret_token=xxx&monkey=monkeystudy&voice=Amy&announcement=%3Cspeak%3Etest+%3Cpause%3D%220.5s%22%2F%3E+test%3Cspeak%2F%3E

    Any ideas?

    Thanks

  • Ali 17 February 2022

    Total took me like 5 minutes to configure everything and it works flawlessly. What a brilliant piece of work.

  • Richard Miles 29 April 2022

    I can get it to work from the playground and have used VM for quite a while with Homeseer but now that I am setting it up in Home-Assistant I’m running into an issue.

    Have tried with this specific monkey on the playground and it makes the sound and then speaks what I want but when I use the {“monkey”:”MONKEY_ID”,”announcement”:”YOUR TEXT HERE”} in developer tools the echo I am sending it to tells me “No announcement text specified, please use the api or dashboard to generate an announcement which will replace this message”

    Anyone have any ideas? What I am wanting to do is trigger a repeating announcement and alarm from all of my echo’s when my security trigger is tripped.

  • Adrian 30 May 2022

    Is this still a workable solution? I have posted exactly what is listed here and when I test from HA I get the following

    01:57:01 HomeAssistant/2022.5.5 aiohttp/3.8.1 Python/3.9 Monkey not found.

    My service call looks like the following

    service: rest_command.trigger_monkey
    data: {monkey:monkeyfoyershadeopen}

    From Monkey Dashboard onward to Alexa it works fine. The problem is with this API call from HA to Monkey.

  • Mario 30 July 2022

    I followed exactly the instructions given but cannot make the announcements to work from home assistant, unfortunately. Everything works well from the VM webpage. But when I use the rest command from home assistant, the call service turns green as it run the instructions, however nothing gets announced. Is it working for you guys? I cannot figure out why is not working for me…

    • Mario 30 July 2022

      I have figure out why it was not working… Some how this symbol ‘ got added wrong when I copied the text to past… The right one should be ‘ which is a straight line and not ‘ which is a curved line… Now is working great! I also can trigger it very easily in Nodered using the call service, with domain=Rest_command, Service=trigger_monkey1 and adding the data the same way as for is added in services (described in the original post).

      • Mario 30 July 2022

        One more observation… If you speak another language than English, or if you want to change the used voice you can edit the payload on the config.yaml to contain the voice parameter: ‘{“access_token”:”ACCESS_TOKEN”,”secret_token”:”SECRET_TOKEN”,”monkey”:”{{monkey}}”,”announcement”:”{{announcement}}”, “voice”:”{{voice}}”}’
        And then, when you trigger the command you can indicate the voice (and language) that you want to use, picking one from the playground: {“monkey”:”MONKEY_ID”,”announcement”:”YOUR TEXT HERE”, “voice”:”PUT the voice that you PICKed here”}

  • Korny 6 November 2022

    I’m having trouble getting this to trigger from within Home Assistant. I have the monkey working within alexa, and I can do a service call successfully to Voice Monkey in HA. But, I cannot get the monkey to activate in the service call successfully.

    It looks like the syntax changes, unless I am not understanding how to input this in the correct way. I enter:

    service: rest_command.trigger_monkey
    data: {“monkey”:”echo-dot-monkey”}

    But afterward, its changed to:
    action:
    – service
    data:
    monkey: echo-dot-monkey

    Anything I am doing wrong?

  • Eric 27 November 2022

    This is working for me, but only when I include the ACCESS_TOKEN and SECRET_TOKEN in the configuration.yaml. I clearly am not understanding what the syntax is to use the secrets.yaml capability. I put two variables in my secrets.yaml:

    voice_monkey_access_token
    voice_monkey_secret_token

    But how do I include them in the payload?

    Thanks!

Leave a Reply

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