官网文档位于:https://developers.home-assistant.io/docs/api/rest/
需要在configuration.ymal中启用:
然后获取访问API时使用的Token:
然后用curl测试一下:
1 2 3 4 |
curl -X GET \ -H "Authorization: Bearer eyJ*****************************************" \ -H "Content-Type: application/json" \ http://172.16.1.51:8123/api/ |
使用/api/services会Returns an array of service objects. Each object contains the domain and which services it contains:
1 2 3 4 |
curl -X GET \ -H "Authorization: Bearer eyJ*****************************************" \ -H "Content-Type: application/json" \ http://172.16.1.51:8123/api/services |
这是一个很大的Json,我们只关注其中有关开关的:
然后使用/api/states/<entity_id>返回对应开关的状态:
1 2 3 4 |
curl -X GET \ -H "Authorization: Bearer eyJ*****************************************" \ -H "Content-Type: application/json" \ http://172.16.1.51:8123/api/states/switch.xiaomi_plug |
然后使用/api/services/<domain>/<service>操作开关即可:
1 2 3 4 5 |
curl -X POST \ -H "Authorization: Bearer eyJ*****************************************" \ -H "Content-Type: application/json" \ -d '{"entity_id": "switch.xiaomi_plug"}' \ http://172.16.1.51:8123/api/services/switch/turn_on |
转载时请保留出处,违法转载追究到底:进城务工人员小梅 » Home Assistant/Hassos使用API并操作小米米家智能插座