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

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

switchbot を使っていて、HomeAssistant などで活用しているけど、スイッチ動作を登録するとき、照明だと、リモコン信号でON/OFFを切り替えるため、点灯状態によっては、ON を押しても照明としては消えたりすることもでてくる。

このため、Homebridge では、電源ボタンではなく、全点灯=ON, 常夜灯=OFF で登録している。

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

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

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

((( 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-cli の使い方

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