Skip to content

hiskaNG/switchbot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 

Repository files navigation

switchbot

A linux command line example based on https://github.com/OpenWonderLabs/SwitchBotAPI

token=''
secret=''

switchbot_get(){
  nonce=$(uuidgen -r)
  t=$(date +%s)000
  data=${token}${t}${nonce}
  sign=$(echo -n "$data" | openssl dgst -sha256 -hmac "$secret" -binary | base64 -w0)
  curl -s -X GET -H "Content-Type:application/json" -H "Authorization:$token" -H "sign:$sign" -H "nonce:$nonce" -H "t:$t" $@
}

switchbot_get https://api.switch-bot.com/v1.1/devices | jq -r .body.deviceList[].deviceId | \
while read deviceId; do \
  switchbot_get https://api.switch-bot.com/v1.1/devices/$deviceId/status | \
  jq -r '.body | [ .deviceId, .deviceType, .hubDeviceId, .power, .voltage, .weight, .electricityOfDay, .electricCurrent, .version ] | @tsv'
done

output:

34XXXXXXXX    Plug Mini (JP)  34XXXXXXXX    on      101.8   38.7    247     5.37    V1.5-1.5

About

A linux command line example based on https://github.com/OpenWonderLabs/SwitchBotAPI

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published