Aqara Developer Platform is an open cooperation platform of Lumi United Technology Co.,Ltd for IoT software and hardware products.
Sure, to sign up on the developer platform and obtain keys: APPID, APPKEY, KEYID
# create venv
mkdir project
cd project
python -m venv venv
source venv/bin/activate
mkdir myapp
cd myapp
# pip install
pip install git+https://github.com/sotoedu/aqara_api_sdk.git
# create a sample app
nano app.py
def auth()
# app.py
from aqara import AqaraClient
import traceback
import json
APPID = 'data1'
APPKEY = 'data2'
KEYID = 'data3'
def auth(email):
try:
client = AqaraClient(api_key='iloveiot!')
print('auth payload : ' , request)
# email = 'data4'
payload = {
'appid': APPID,
'appkey': APPKEY ,
'keyid': KEYID ,
'email': email
}
response_data = client.get_auth(payload)
response = {
'message': 'success',
'result': response_data
}
return jsonify(response)
except Exception as error:
print('[error] : ' , error)
print("[auth] traceback : ", traceback.format_exc())
def token()
# app.py
from aqara import AqaraClient
import traceback
import json
APPID = 'data1'
APPKEY = 'data2'
KEYID = 'data3'
def token(authCode, email):
try:
client = AqaraClient(api_key='iloveiot!')
# authCode = 'data4'
# email = 'data5'
# POST 요청
payload = {
'authCode': authCode,
'appid': APPID,
'appkey': APPKEY ,
'keyid': KEYID ,
'email': email
}
response_data , response_msg = client.get_token(payload)
response = {
'message': 'success',
'token': response_data,
'response' : response_msg
}
return jsonify(response)
except Exception as error:
print('error : ' , error)
def position()
# app.py
from aqara import AqaraClient
import traceback
import json
APPID = 'data1'
APPKEY = 'data2'
KEYID = 'data3'
def position(token):
try:
client = AqaraClient(api_key='iloveiot!')
# token = 'data4'
# POST 요청
payload = {
'token': token,
'appid': APPID,
'appkey': APPKEY ,
'keyid': KEYID
}
all_position_value, positionResponse, all_device_list = client.get_position(payload)
print('[position] all_device_list : ' , all_device_list)
response = {
'message': 'success',
'postion': all_position_value,
'roomList': positionResponse,
'deviceList': all_device_list
}
return jsonify(response)
except Exception as error:
print('[position] error : ' , error)
def status()
# app.py
from aqara import AqaraClient
import traceback
import json
APPID = 'data1'
APPKEY = 'data2'
KEYID = 'data3'
def status(model, token):
try:
client = AqaraClient(api_key='iloveiot!')
# model = 'data4'
# token = 'data5'
# POST 요청
payload = {
'model': model,
'token': token,
'appid': APPID,
'appkey': APPKEY ,
'keyid': KEYID
}
response_data , response_msg = client.get_resource(payload)
response = {
'message': 'success',
'result': response_data,
'response' : response_msg
}
return jsonify(response)
except Exception as error:
print('error : ' , error)
def write()
# app.py
from aqara import AqaraClient
import traceback
import json
APPID = 'data1'
APPKEY = 'data2'
KEYID = 'data3'
def write(did, resid, control, token):
try:
client = AqaraClient(api_key='iloveiot!')
# did = 'data4'
# resid = 'data5'
# control = 'data6' # 'on' or 'off'
# token = 'data7'
# POST 요청
payload = {
'appid': APPID,
'appkey': APPKEY ,
'keyid': KEYID ,
'did': did,
'resid': resid,
'control': control,
'token': token
}
response_msg = client.write_resource(payload)
response = {
'message': 'success',
'response' : response_msg
}
return jsonify(response)
except Exception as error:
print('error : ' , error)
def read()
# app.py
from aqara import AqaraClient
import traceback
import json
APPID = 'data1'
APPKEY = 'data2'
KEYID = 'data3'
def read(did, resid, token):
try:
client = AqaraClient(api_key='iloveiot!')
# did = 'data4'
# resid = 'data5'
# token = 'data6'
# POST 요청
payload = {
'appid': APPID,
'appkey': APPKEY ,
'keyid': KEYID ,
'did': did,
'resid': resid,
'token': token
}
response_msg = client.read_resource(payload)
response = {
'message': 'success',
# 'result': response_data,
'response' : response_msg
}
return jsonify(response)
except Exception as error:
print('error : ' , error)
def history()
# app.py
from aqara import AqaraClient
import traceback
import json
APPID = 'data1'
APPKEY = 'data2'
KEYID = 'data3'
def history(did, resid, token):
try:
client = AqaraClient(api_key='iloveiot!')
# did = 'data4'
# resid = 'data5'
# token = 'data6'
# POST 요청
payload = {
'appid': APPID,
'appkey': APPKEY ,
'keyid': KEYID ,
'did': did,
'resid': resid,
'token': token
}
response_msg = client.get_history(payload)
response = {
'message': 'success',
# 'result': response_data,
'response' : response_msg
}
return jsonify(response)
except Exception as error:
print('error : ' , error)
def main()
# app.py
if __name__ == '__main__':
auth = auth('[email protected]')
token = token('auth_code','[email protected]')
position = position('token')
status = status('your_device_model','token')
write = write('device_id','resource_value','on','token')
read = read('device_id','resource_value','token')
history = history('device_id','resource_value','token')
You've successfully run and modified your Project. 🥳
- If you want to add ... , check out the Developer guide.
If you can't get this to work, see the Troubleshooting page.
To learn more about Developer Platform, take a look at the following resources:
- Developer API Website - learn more about Aqara API.
- Getting Started - Getting Started.
- Learn the Basics - Learn the Basics.