Getting Start with Autimations
一. 准备
- 下载postman或者使用web端postman
- 通过自己的三星账户创建私人访问令牌
网址:
https://account.smartthings.com/tokens
二. 使用postman向smartthings发送请求,获取自己账户内智能设备的id。
- 在postman中创建一个http request请求,
- 在网址
https://developer-preview.smartthings.com/api/public/#tag/Devices
中获取api网址:
https://api.smartthings.com/v1/devices
![在这里插入图片描述](https://img-blog.csdnimg.cn/a36e44787db74a67a6e87a5a75157501.png)
3.在postman的Authorization中选择Bearer Token,将私人访问令牌填入 ![在这里插入图片描述](https://img-blog.csdnimg.cn/026a800207a342caa39e10c80b8b3bb8.png) 4.点击send按钮
![在这里插入图片描述](https://img-blog.csdnimg.cn/730c57cebefb420d8952a209949b4b7e.png) 5.获得json格式的消息,从消息中获取deviceid
三. 创建rule
- 从api网页中获取创建rules的网址
https://api.smartthings.com/rules?locationId=xxxx
- 访问方式改为POST
- 设置Authorization(与二.3相同)
- 在Body中选择raw,添加需要创建的rule
![在这里插入图片描述](https://img-blog.csdnimg.cn/a64ab375ff3c4d5e977d85ed40b00a76.png?x-oss-process=image/watermark,type_ZHJvaWRzYW5zZmFsbGJhY2s,shadow_50,text_Q1NETiBA5bCP5piO5Zyo5Lic5Y2X,size_20,color_FFFFFF,t_70,g_se,x_16) 以turn on a switch at sunset为例
{
"name": "Turn on a switch at sunset",
"actions": [
{
"every": {
"specific": {
"reference": "Sunset",
"offset": {
"value": {
"integer": 0
},
"unit": "Minute"
}
},
"actions": [
{
"command": {
"devices": ["your-device-id"],
"commands": [ {
"component": "main",
"capability": "switch",
"command": "on"
}]
}
}
]
}
}
]
}
5.点击send 6.得到返回的消息
四.手动触发rule的执行
1.与之前相似的操作 post 网址:https://api.smartthings.com/rules/execute/:ruleId?locationId={your-location-id} 需要设置ruleid: ![在这里插入图片描述](https://img-blog.csdnimg.cn/d5040052be77419baf3127d24418fba3.png?x-oss-process=image/watermark,type_ZHJvaWRzYW5zZmFsbGJhY2s,shadow_50,text_Q1NETiBA5bCP5piO5Zyo5Lic5Y2X,size_17,color_FFFFFF,t_70,g_se,x_16)
设置Authorization
2.获得执行结果:
{
"executionId": "xxx",
"id": "xxx",
"behaviorType": "Rule",
"result": "Success"
}
Final:
虽然显示success,但我的switch并没有打开,但log中能查看到该rule已激活。
|