In this project, You use SwitchBot API to get parameters from your SwitchBot devices.
- Python 3
- python-dotenv
- SwitchBot API v1.1
check How to obtain a Token? from SwitchBot official site.
You need device id to get parameters from your SwitchBot.
- Install python-dotenv
pip install python-dotenv
- Create .env file
you can use .env.example
cp .env.example .env
- Edit .env file
set your secret key and token you got from the previous step
vi .env
- Run
python3 get_device_id.py
{'body': {'deviceList': [{'deviceId': 'XXXXXXXXXXXXXXXX',
'deviceName': 'XXXXXXXXXXXXXXXX',
'deviceType': 'XXXXXXXXXXXXXXXX',
'enableCloudService': True,
'hubDeviceId': ''}],
'message': 'success',
'statusCode': 100}
Use deviceId
in the next step.
You can get the response from your SwitchBot device.
python3 get_response.py $KEY $DEVICE_ID
-
$KEY
the key you want to get from your SwitchBot device. check here.
-
$DEVICE_ID
the device id you got from the previous step.
I want to get the temperature from Hub 2.
python3 get_response.py temperature "my_device_id"
I get below response.
25.5