Trigger Alexa Routines And Make Announcements 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.
Whilst it has support for some Alexa functionality, Voice Monkey provides an alternative for triggering Alexa routines directly from Home Assistant and making Text To Speech (TTS) announcements.
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 🙂
The process is easy.
Firstly, sign up to Voice Monkey and follow the instructions to create your first virtual Trigger device and Routine.
A Voice Monkey Trigger device is simply a virtual doorbell device which can be pressed (or triggered). We can use these virtual devices, as triggers in our Alexa Routines.
But how do we trigger these virtual doorbells from Home Assistant?
In Home Assistant you can make API calls using the REST command.
Simply add the following to Home Assistant’s configuration.yaml file:
# Voice Monkey Alexa Routine API call
rest_command:
trigger_voice_monkey:
url: https://api-v2.voicemonkey.io/trigger
method: POST
verify_ssl: true
content_type: 'application/json; charset=utf-8'
payload: '{"token":"API_TOKEN","device":"{{deviceId}}"}'
# End of Voice Monkey Alexa Routine API call
In the code above you should replace API_TOKEN with your own API token found in the Voice Monkey console (make sure you keep it secret!).
Even better, 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.
Go to developer tools and test it out.
First, restart the server (Configuration ->Server Controls -> RESTART) to apply the new changes:
{"deviceId":"MONKEY_ID"}
You must replace MONKEY_ID with the ID of your Voice Monkey trigger device found in the Devices manager section of the console.
And that’s it!
You can now start triggering Alexa Routines from Home Assistant.
To make announcements using Alexa, you must first create a Speaker device in Voice Monkey.
Go to the Devices section of the console. Create a new Speaker device and follow the instructions for creating the Alexa routine and linking your Echo device.
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 Announcement API call
rest_command:
trigger_voice_monkey:
url: https://api-v2.voicemonkey.io/announcement
method: POST
verify_ssl: true
content_type: 'application/json; charset=utf-8'
payload: '{"token":"API_TOKEN","device":"{{deviceId}}","announcement":"{{announcement}}"}'
# End of Voice Monkey Alexa Announcement API call
Now when your testing, you must also send an ‘announcement’ parameter along with the Voice Monkey device ID in the Service Data field e.g. {"deviceId":"MONKEY_ID","announcement":"YOUR TEXT HERE"}
If you go to the API Playground you can take a look at some of the other parameters available in our API. You can then easily integrate those into your Yaml file.
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!
Get started on our generous free plan (no credit card required).