创作立场声明:自购自用
之前也晒单过了,最近入手了DYD-E12A3这款除湿机。现在我购买家电首选是可以联网控制的,再就是看能不能整合到HomeAssistant。网上搜了下,发现有大佬成功的接入了,特地去学习了。
所以这篇文章主要是记录下过程。方法不是我原创的,我只是按照大佬的方法试了一遍。
原文如上,感谢yongman
1.模拟登陆获取token
接下来要做的是从登陆认证接口开始查看,并模拟登陆过程。下载postman这个软件或者chrome的插件。
登陆地址https://api.deye.com.cn/v3/enduser/login/
添加键值,然后Send
loginname APP的登陆名
password APP的密码
appid 按图片填v2.16吧,其实随意
pushtype Ali
extend {"cid":"111111122223333","type":"0"}
结果返回:
{
"meta": {
"code": 0,
"message": "signup ok."
},
"data": {
"token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"clientid": "xxxxxxxxxxxxxxxxxxxxxx"
}
}
返回的结果可以用txt存下来备用
2.获取设备列表
登陆地址https://api.deye.com.cn/v3/enduser/deviceList/
添加键值,然后Send
Authorization JWT 刚才获取的token
结果返回:
{
"meta": {
"code": 0,
"message": "device list by user."
},
"data": [
{
"online": true,
"product_icon": "https://deye-cloud.oss-cn-shanghai.aliyuncs.com/profile/1597889707825.png",
"product_id": "xxxxxxxxxxxxxxxxxxxxxx",
"product_name": "DYD-E12A3",
"device_id": "xxxxxxxxxxxxxxxxxxxxxx",
"mac": "xxxxxxxxxxx",
"payload": "xxxxxxx00001E000000000000000000xxxxx000000000",
"role": 1,
"gatewaytype": 0,
"device_name": "客厅加湿器",
"product_type": "dehumidifier",
"is_combo": false
}
]
}
上面的信息中的product_id、device_id记好,后面会用到。
3.mqtt的信息
上面是访问服务端接口获取一些基本信息,控制设备并没有相关的api接口。看了下源码中的对应的按钮绑定的事件,找到对应的命令发送接口调用。mqtt的信息是在服务端接口请求来的。
登陆地址https://api.deye.com.cn/v3/enduser/mqttInfo/
添加键值,然后Send
Authorization JWT 刚才获取的token
结果返回:
{
"meta": {
"code": 0,
"message": "mqtt info"
},
"data": {
"loginname": "xxxxxxxxxx/xxxxxxxxxxxxxxx",
"clientid": "xxxxxxxxxxx",
"endpoint": "xxxxxxxxxxxxxxxx",
"password": "xxxxxxxxxx",
"mqtthost": "xxxxxxxxxxxxxxxxxxx.mqtt.iot.gz.baidubce.com",
"mqttport": 1883,
"sslport": 1884
}
集成到homeassistant
下载mqtt插件,复制mqtt模块到custom_components,系统启动时会优先在custom_components中加载mqtt模块,覆盖系统自带的mqtt集成模块。
增加配置,修改configuration.yaml
增加mqtt配置
# DEYE除湿机
mqtt:
broker: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.mqtt.iot.gz.baidubce.com
port: 1883
client_id: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
username: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
password: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
说明这里的内容对应填写上面mqtt info的返回结果值
增加switch配置
switch:
- platform: mqtt
name: deye
state_topic: xxxxxxxxx/xxxxxxxxxxxxx/xxxxxxxxxxxxxxxx/status/hex
command_topic: xxxxxxxxx/xxxxxxxxxxxxx/xxxxxxxxxxxxxxxx/command/hex
payload_on: deye_on
payload_off: deye_off
说明这里的
state_topic是mqtt_endpoint/productid/deviceid/status/hex
command_topic是mqtt_endpoint/productid/deviceid/command/hex
mqtt_endpoint在mqtt info的返回结果
productid在deviceList的返回结果
deviceid在deviceList的返回结果
重启HA 配置MQTT集成
进入HA后,打开配置--集成---MQTT配置
点击RE-CONFIGURE MQTT开始配置
这里已经按照configuration.yaml里的自动填写好了,不用理会。点击提交
关键点,要取消这两个的勾选,我也是误打误撞。后来得到了yongman的回复验证。如果不在这里设置,这个switch是一直不可用的状态,这个我也折腾了好几天才误打误撞搞好了。
好了,现在德业加湿器已经添加到HA了,也可以通过HA再添加到homekit里了。也可以配合温湿度传感器做自动化的设定,这就不再啰嗦了。
到这里就收工完成了。
不明觉厉,总之先点个赞![高兴]