ホーム » コンピュータ » Linux » rust 版 switchbot-cli のインストール

rust 版 switchbot-cli のインストール

switchbot を扱っていて、調べてみると rust 版があるらしい。以前 nodejs 版も入れたけど、monit からの google-home-player (nodejs版)の呼び出しで、色々トラブルで動かないので、rust 版を試したい。

“cargo install switchbot-cli” でインストールができるというが、エラーがデコンパイルに失敗。rust の最新版が必要みたい。

((( rustc-1.88 などのインストール )))
$ sudo apt install rustc-1.88 cargo-1.88 rustup

((( rustup に 1.88 使用を明言 )))
$ sudo rustup override set 1.88

((( root 権限で switchbot-cli をインストール )))
$ sudo cargo install switchbot-cli --root /usr/lib/cargo
$ cd /usr/local/bin
$ sudo ln -sf /usr/lib/cargo/bin/switchbot .

switchbot コマンドを使ってみる。

((( switchbot-cli に TOKEN, SECRET を登録 )))
$ switchbot
Token> xxxxxx
Secret> xxxx
: 学習リモコン (remote with screen, ID:xxxxx)
2: CO2センサー (MeterPro(CO2), ID:xxxxx)
3: CO2センサー・子供部屋 (MeterPro(CO2), ID:xxxxx)
4: switchbot-hub3 (Hub 3, ID:xxxxx)
     :
18: リビングの照明 (Light, ID:xx-xxxxxxxxxxx-xxxxxxxx)

((( 使ってみる )))
$ switchbot xx-xxxxxxxxxxx-xxxxxxxx turnOff # デバイスID で操作。
$ switchbot 18 turnOn                       # 前述のデバイスの連番 18 でもいいみたい
$ switchbot 18 help
turnOn
every home appliance can be turned on by default
turnOff
every home appliance can be turned off by default
customize/{user-defined button name}
all user-defined buttons must be configured with commandType=customize
brightnessUp
brightness up
brightnessDown
brightness down
customize/{user-defined button name}
all user-defined buttons must be configured with commandType=customize

$ switchbot --alias リビングの照明=xx-xxxxxxxxxxx-xxxxxxxx
$ switchbot リビングの照明 turnOn