Webhooks are a great tool to integrate smart devices and web services with each other. In this article, you will learn the following:
- Get Started with webhooks
- Use MicroBot Push's webhook feature
- Example 1: Integrate MicroBot Push & Apple Watch (incoming hook)
- Example 2: Integrate MicroBot Push & SMS (outgoing hook)
Get Started with Webhooks
A webhook is an HTTP request hook that triggers some specific event or action. Webhooks enable you to integrate two or more web apps or services that have no compatibility to begin with. The idea is to create this compatibility by using webhooks.
With webhooks, you can integrate:
- Physical devices: Microbot Push, MicroBots, Apple Watch, Flic...
- Internet services: PayPal, Twitter, Facebook, WhatsApp, Skype, Slack, Dropbox...
- The device or web service you want to integrate must support webhooks.
- If it does not support webhooks, use IFTTT's Webhooks service (Maker). You will need an IFTTT account.
Principle. Before starting using webhooks, you need to identify which type of hook, Incoming hook or Outgoing hook, you need. This will enable you to determine the correct sensor-event and actor to build your integration successfully.
- An incoming hook is an HTTP request sent by another smart device or web service and received by MicroBot Push. When received, this incoming hook will trigger MicroBot Push.
Ex. When command to turn off the lights from my Apple Watch (incoming hook), MicroBot Push turns off the light.
- An outgoing hook is an HTTP request that MicroBot Push posts to another app or web service when specific conditions are met. When sent, this outgoing hook will trigger an action on another web service or smart device.
Ex. When an event related to MicroBot Push occurs, MicroBot Push posts an HTTP request to xxx (outgoing hook).
Use MicroBot Push's Webhooks
Access webhooks. Tap on the 3 dots [...] at the top right corner to access your Push's settings, find 'Webhook' in the list of features and tap on the 'Webhook' icon.
Types of webhooks. MicroBot Push supports both incoming and outgoing hooks. There are 4 different incoming hooks available for MicroBot Push:
- Press: MicroBot Push pushes and released the button
- Push: MicroBot Push pushes the button and stays in 'push' position.
- Release: MicroBot Push releases the button and stays in 'release' position.
- Reveal: MicroBot Push's LED will blink in different colors to enable you to spot it.
Use Incoming hooks. Tap 'Use' to copy the incoming hook URL and paste it in the webhook settings of the smart device or web service you wish to integrate. MicroBot Push will be triggered when a particular event occurs.
Use Outgoing hooks. Find your smart device's or web service's incoming hook URL, paste it in the box and tap 'Set'. An action on your smart device or web service will be triggered when an event related to MicroBot Push occurs.
Note: Refer to a smart device's or web service's API documentation to get your URL and all information you need to use webhooks.
Example 1: Integrate MicroBot Push & Apple Watch (incoming hook)
Objective. Control your MicroBot Push installed on your light switch using your Apple Watch.
Principle. When MicroBot Push receives an HTTP request (webhook) sent from your Apple Watch, your MicroBot Push will turn on/off the light => incoming webhook.
Since MicroBot Push is installed on a light switch, you will need to use two incoming hooks 'Push hook' and 'Release hook' to reproduce the Toggle mode.
Build the integration. In MicroBot Push app, tap 'Use' to copy the 'Push hook' URL. Then, in Apple Watch app, go to ‘Request List’, create a new request as following: set a name (e.g. Turn on room light), choose ‘POST’ as the method and paste the 'Push' URL. Repeat the same process with the 'Release hook' URL.
Use the integration. Tap ‘Request’ on your Apple Watch on the desired webhook to turn on or off your lights!
Example 2: Integrate MicroBot Push & SMS (outgoing hook)
Objective. When your MicroBot Push is pushed, get alerted by SMS.
Principle. When MicroBot Push is pushed, it posts an HTTP request (webhook) to send you an SMS. => outgoing webhook. This hook will be created using IFTTT's Webhooks and SMS services.
Get your outgoing hook. Create an account on IFTTT, search 'Webhooks' and connect. Then, tap on the 'Settings' icon at the top right corner to enter the Webhooks' settings, and copy your webhook URL: https://maker.ifttt.com/trigger/use/yourkey
Create the IFTTT's applet. On IFTTT, create the applet "If Webhooks receive a web request, then send me an SMS":
- Build the IF part: Select 'Webhooks', then 'receive a web request' and set up a name for the event.
- Build the THEN part: Select 'SMS', then 'send me an SMS' and tap 'create the action'. Tap 'Finish' to save the applet.
Set the outgoing hook in Push app. Go to MicroBot Push app, access the webhook feature and find the 'outgoing hook' box. Then, paste the URL obtained on IFTTT and tap 'Set'. Done!