Webhooks with Animus Heart
In this post you will learn how to use Webhooks in Automations to trigger actions on external services. To demonstrate with an example I will use Zapier and Slack. You can use this as a guideline for your own projects.
My goal will be to send a specific message to myself on Slack and I will do this through Zapier (an external service that can automate all sorts of online services). Slack has their own webhook support, but currently only with POST requests and since Animus Heart supports GET requests only for now, I will go around it by using Zapier.
What are Webhooks?
A webhook (also web callback or HTTP push API) is an API concept that is very useful to implement event reactions. It’s growing in popularity due to web advancing and more and more of what we do can be described by events. Webhooks are a way for an app to provide other applications with real-time information. Data is delivered by a webhook to other applications as it happens, meaning you get data immediately. Unlike typical APIs where you would need to poll frequently in order to get real-time data, then this makes webhooks much more efficient for both provider and consumer. Very convenient for automating events with your smart home!
For this example you will need:
- Zapier account (nothing you need to be using actively, creating a new account is easy)
- Slack account
- Animus Heart (The automations function is built in and is found under the page “Automations”)
Step 1 (Setup on Zapier)
Start by connecting the Zap you want, in this example Webhook + Slack.
Step 2 (Setup on Zapier)
When you click on “Use this Zap”, you will be directed to the setup window.
Step 3 (Setup on Zapier)
The first part of the setup is to get the webhook right and start by choosing webhook type. For our example we will choose “Catch Raw Hook”.
Note: Animus Heart supports GET requests (POST is under development), have this in consideration when playing around with other projects.
Step 4 (Setup on Zapier)
In the next step you will be given a unique link for your webhook to Zapier. Copy this link and save it temporarily in notes or somewhere else (you’ll need this later when setting up the Automation)
Step 5 (Setup on Zapier)
The last step in Zapier is testing the webhook. The test will run for a few seconds and when showing “Test Successful”, you can move on to setting up your Slack action.
Troubleshoot: If nothing happens after around 30 seconds, paste the link that you copied earlier on to a new tab in your web browser and get back to the Zapier page after that.
Step 6 (Setup on Zapier)
The second part is to set up Slack. Choose what type of action you want to happen. I chose to send a direct message to a user (myself).
Step 7 (Setup on Zapier)
Now it’s time to connect your Slack account. Zapier will guide you here.
Step 8 (Setup on Zapier)
The last step in Zapier is to write who you want to send the message to and what type of message you want to have.
Step 9 (Setup on Animus Heart)
Now enter your Animus Heart app and go to the Automations page. Create a new automation and continue by choosing a trigger (“WHEN”). For my example I have chosen a power socket that is connected to my electric heater. The automation is triggered when the power is turned on.
Step 10 (Setup on Animus Heart)
On the actions column (“THEN”), you will choose “Webhook” in the alternatives.
Step 11 (Setup on Animus Heart)
Lastly take the unique link that you copied in Step 4 and simply paste it inside the input-area.
Step 12 (Setup on Animus Heart)
Congratulations, you are now done! Click “Test” in your automation and check your Slack for the message. Have fun!
Here are some other ideas to try
- Create a new row in a Google Spreadsheet when something is triggered. Later you could use this data to get very specific statistics on something.
- If you are a super awesome developer and you wish to trigger a new build with a push of a button (physical button) using your CI system (Travis, Jenkins or other), go ahead and try.
Want to do more with the Automations tool?
Read these blog posts to get a great start with Automations.
- Useful automations to use every day with Animus Heart
- How to work with Automations on the Animus Heart
Continue to follow our blog and social media to gain new wisdom in the smart home. But also to receive new inspiration on how your smart home can become even better with the Animus Heart.
Subscribe to our newsletter for news and announcements!