Unlock the Magic of connecting Buttons to the Internet — Amazon Dash Button Style, but better
But I have found that with Gravio.com, there is a great alternative, that allows you to connect low energy consumption buttons (up to 2 years on one button battery) to any API you would wish to. It’s not a free service, but at £3.99 a month for 4 sensors of your choice, it’s quite affordable.
Unfortunately Amazon does not have an open API to trigger purchases/orders, however, you could use a service like Zinc to do so. But I don’t want to pay Zinc’s $100/month minimum fee, therefore let’s connect the button to other cool stuff, shall we?
Basically, with Gravio, you can trigger any HTTP request from the button. But Gravio also has some off-the-shelf integrations such as Slack, Twilio or LINE, which allows you to easily connect using a simple module.
So for the sake of this tutorial, let’s go through two examples:
Example 1 (simple): upon the press of a Aqara button, let’s simply trigger a text message to a specific number using Twilio. The text message will be pre-defined in Gravio.
Example 2 (advanced): upon the press of an Aqara button, let’s trigger an HTTP API call over the local network to a local LaMetric.
First, you need to get the Buttons. For this, simply download the free Gravio Studio app from either the iOS, macOS or Windows App Store. If Gravio is available in your country, sign up for the basic subscription (around £3.99/month) which will give you 4 sensors of your choice (button, temperature, magnet, vibration or occupancy sensors are available).
Once you have an account and you are signed up to the subscription, you can go to Gravio.com, log in with your details at the top right, and order the 4 sensors of your choice. The team at Gravio will then send you the sensors plus a USB dongle that you can plug into your Windows, Mac or Linux computer to connect the sensors to your computer. The sensors use the Zigbee protocol, which supports low energy protocols. That means a sensor can work for up to 2 years without having to change the batteries.
Once you have received the package from Gravio, you can follow the instructions on doc.gravio.com to pair the sensors with the dongle/computer to start receiving data. Incoming data can then be processed in Gravio directly.
Example 1: Let’s trigger some Text Messages (simple)
In order to send text messages, you need a Twilio account. They offer free trials. Sign up to a free trial and create a new Twilio Project at the top right.
Choose “Projects” and then “Programmable SMS”
Give it a name
Skip the team-mate if you want. And once the project is set up, you get an Account SID and an Auth Token:
Then click on the “Get Started” button on the Programmable SMS card and then on “Get a Number”. You will need it as an originator to send messages out:
In Gravio Studio, you connect to your Gravio HubKit using the IP address, and then click on the “Actions” button at the bottom:
Click on the + sign at the top to create a new Action and double-click it:
Give it a reasonable name at the top and click on the + in the gray box:
Here you can click on “TwilioSMS” and then confirm using the “add” button:
If you now click on the Twilio SMS box, you can put your settings in:
You can either set your Account SID and Token herein this step, OR you can put it in the “base property profile” so if you use it in multiple places you don’t have to put it in multiple places. The base property profile can be found on the HubKit Settings in the main view (see left).
For testing’s sake, let’s use the Account SID and Token right in the step. Therefore untick the checkbox “Use Base Property Profile” and copy-paste the info from your Twilio account:
In the trial account you can only send to specific numbers and you need to pick the “from” number as the number you chose when setting up the project.
Now you can test the action by clicking the “play” button on the top right.
You should immediately get a message to your phone:
The next step is to connect the button press with the Twilio action. For this, leave the action editor in Gravio and enter the configuration area by double-clicking on the card related to your HubKit (the one that has your dongle plugged in). Assuming you have paired your sensor according to the instructions, you should see something like this:
Now you click on Trigger and add a new trigger by clicking on the + sign on the top right.
You set up the trigger according to the below and chose the Gravio Action you have set up earlier.
Make sure you choose the “classic” trigger, because that will trigger the action not only if the value changes but if it actually gets triggered:
Make sure the trigger is enabled and off you go. Whenever you press the button now, the text message will be sent.
Example 2: Trigger an HTTP Request (advanced)
You can, of course, trigger any HTTP request using the HTTP Post component inside Gravio:
For this, it’s good to have some basic understanding of networking and the HTT protocol.
In our example, we want to trigger a text on the LaMetriv LED screen. LaMetric is a LED device that you can connect to the wifi and that supports various ways of displaying text, icons and even audio. It’s actually quite a cool device, check it out:
LaMetric has a simple API available here. In our case, we want to control the LaMetric via the local network API rather than the online Cloud API. This way we can keep the communication at the edge of the network. For this, we need this specific API.
For the purpose of this demo, let’s send a notification and an icon to the LaMetric. Let’s call it “Beer Time! “
- Log into your LaMetric Account and pick up the API key of the device you want to control via Gravio:
2. Find out the IP address of your LaMetric device using your mobile App, where you can find the IP in the Settings > Wifi
3. Start Gravio and create a new Action with a HTTP Post Step. Put the IP followed by the port 8080 and then /api/v2/device/notifications . Select POST for Method and application/json for Content-Type:
4. Add the body, for this example, we used:
5. And for the Authorization Type, we used Basic and the Authorization Value is dev followed by a colon and the API key:
You can also Gravio to save input and output in a file, which it will do in your Gravio Server’s file structure under <Gravio Directory>/action/data/httppostdump
You can test the script by pressing the small “play” button at the top right of the window.
6. Now let’s create a trigger in Gravio the same way we did it further up and select the appropriate Gravio Action: