Understanding Smart Home APIs

How do you control your smart home device?

Well regardless of the wireless technology (Wi-Fi,ZigBee etc) or the application protocol (HTTP or MQTT) it is using, it is controlled via an API (Application Programming Interface).



So What is an API exactly?

What is a API (Application Programming Interface)?

An API is an interface used by programs to access an application.

It allows a program to send commands to another program or application and receive responses back from that application.

Many of the APIs today are Web API’s and are designed to use the HTTP protocol.

However the use of MQTT is growing fast and will,IMO, be the control protocol of the future smart home.

Because of the many existing devices currently using HTTP then HTTP is likely to persist well into the future regardless of the popularity of MQTT.

The Basics

The API provides us with a list of commands and their responses.

Using these commands we can access a resource on another system.

In the case of our smart home, for example, we can turn a light on and off .

API Endpoints

Regardless of the protocol all APIs require Endpoints.

An API Endpoint is defined as the end of a communications channel.

This is where an application sends requests to, and receives responses from.

In HTTP endpoints are provided by urls and in MQTT they are provided by topics.

Open Smart Home APIs

An open API is an API whose structure and commands are available to the public and can be used for controlling applications and devices.

Example Tasmota flashed devices- The API is here

Mystrom provide a range of smart home devices and publish their API here

Google, Amazon and Samsung also provide Open APIs

Advantages of Open APIs

From a device owners perspective open APIs allow you to control your devices using third party Apps and also build your own control systems; using Node-Red for example.

This is what the device manufacturer Mystrom states on their API page.

 

mystrom-api

Proprietary or Closed APIs

Not all devices provide open APIs, and so require that the user uses applications and services provided by the device manufacturer.

As an example the Sonoff switch out of the box is only controllable using the eWelink Smart Phone Application.

Advantages of Closed APIs

Generally devices are easier to setup and use as the work has been done by the device manufacturer, and not a third party.

They are also potentially more secure as the API isn’t published, and so it is more difficult for hackers to learn the commands to control the device.

Smart Home Device API Example

The mystrom API accepts commands using the http protocol using both GET and POST requests.

When using HTTP GET requests are usually used for reading device information, and POST requests are used for setting device parameters.

However the choice is really up to the API designer.

The Mystrom API lets you turn the switch on and off using the GET request as shown below:

mystrom-switch-api-example

Generally the curl command line utility is used for testing HTTP REST APIs but because the GET request is the default request type of a standard web browser then you can use that.

So if the switch was on IP address 192.168.1.60

I would simple type http://192.168.1.60//relay?state=1 into the URL field of a web browser.

mystrom-request-using-browser

As shown in the MYstrom documentation there is no response given to this command.

Video IOT API Basics For Beginners

Summary

Smart Home APIs provide a mechanism for controlling smart home devices using a program or application.

All smart home devices use APIs, but not all APIs are published and available to the user.

These are closed or private APIs, and means that you need to use applications provided by the device manufacturer to control the device.

Would you like a course or detailed Tutorials on Using Smart Home APIs?

View Results

Loading ... Loading ...

Related Tutorials and Resources

Please Let me Know if you found it Useful
[Total: 6 Average: 4.3]

Leave a Reply

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