IT

Operate SwitchBot devices using SwitchBot’s API

Operate SwitchBot devices using SwitchBot’s API

This time, I would like to use the SwitchBot API to operate the SwitchBot device at home!

This time I will try to operate the power plug!
With this power plug, you can turn on/off the outlet via the network, so for example

  • Turn off lights from Google Home or Alex
  • Control the fan with your smartphone

You can do something like this!

Here is the API reference!

First, prepare the Token required to execute the API!

  1. Tap the application version on the SwitchBot application setting screen repeatedly
  2. You can copy the token by tapping developer options!

This Token must be set in the Header when executing SwitchBot’s API!

Authorization: ${SWITCHBOT_API_TOKEN}

Next, get the deviceId of the device you want to operate

By executing the API at (GET)https://api.switch-bot.com/v1.0/devices, you can obtain a list of devices registered with SwitchBot and detailed information about each device.
There is a deviceId in it, so get the one for the device you want to operate

Then run the Post APIs that actually manipulate the device state
The URL is (POST)https://api.switch-bot.com/v1.0/devices/${DeviceId}/commands.

The JSON to be posted depends on the device and what you want to do, so check the API reference for details.
In the case of a power tap, you can turn on the power tap by Posting the JSON below!

{
    "command": "turnOn", // if will turn off、”turnOff”
    "parameter": "default",
    "commandType": "command"
}
+1

COMMENT

Your email address will not be published.

CAPTCHA