switchbot-cli 0.1.0

A command-line interface for controlling SwitchBot devices.
Documentation

CI-badge crate-badge docs-badge

switchbot-cli

A command-line interface for controlling SwitchBot devices using the SwitchBot API.

Install

Prerequisites

From crates.io

cargo install switchbot-cli

Usages

Authentication

On the first run, the switchbot command prompts to enter the authentication.

$ switchbot
Token>

Please refer to the SwitchBot documentation about how to obtain the token and secret key.

They are saved in your configuration directory to save you from entering them each time. The --clear option clears the saved authentication, and the switchbot command will prompt for the authentication again. The --token and the --secret options are available to specify them explicitly.

Interactive Mode

Once the authentication is done, the interactive mode starts.

$ switchbot
1: My Bedroom Light (DIY Light, ID:111222333)
2: Hub Mini AF (Hub Mini, ID:444555666)
...
Device>

All your devices are listed with a number, the device name you set in the SwitchBot app, the device type, and the device ID.

Select Device

To select the device to interact with, enter either the number or the device ID.

1: Hub Mini AF (Hub Mini, ID:111222333)
2: My Bedroom Light (DIY Light, ID:444555666)
...
Device> 2
Name: My Bedroom Light
ID: 444555666
Type: DIY Light
Command>

Command

To control your devices, you can send commands. The available commands depend on the device type. please find the command you want to send to your devices from the SwitchBot documentation about device control commands.

The following example sends the turnOn command to the DIY Light.

Device> 2
Name: My Bedroom Light
ID: 444555666
Type: DIY Light
Command> turnOn

Parameters

If the command you want to send has "command parameters" other than default, append a : (colon) and the command parameters.

Command> setMode:101

Command Type

If the command has a "commandType" other than command, prepend it with a / (slash) as the separator.

Command> customize/button1

Quit

Hit the Enter key twice, or enter q to quit the switchbot command.

Non-interactive Mode

It is also possible to run the switchbot command in non-interactive mode by specifying the device number or the device ID and the command as arguments.

This is useful to create your own batch files, or to use with launcher applications such as Elgato Stream Deck.

$ switchbot 1 turnOn

You can also specify multiple devices and commands.

$ switchbot 1 turnOn setMode:101 4 turnOff