|
本帖最后由 BobbyCoon 于 2021-12-1 21:29 编辑
各位大神看见了,别光看分享啊,看看第二点我提的问题吧,跪求帮忙解决。:'(
一、先分享云米零冷水热水器的node-red接入
首先感谢smzdm大神分享的帖子(https://bbs.hassbian.com/thread-9693-1-1.html),这个帖子中,Soloist_lrp大神在39楼分享的插件我能完美接入我的ha-core中,解决了我家中自动热水循环的问题,这个功能也成为了家人使用最为频繁的功能,比如每天起床前自动的热水循环,比如每天晚上洗澡前都习惯的siri一下打开热水循环(或者小爱),但是我最近在尝试迁移到hassos时,发现了问题,我原来在ha中使用的部分三方插件都不能使用了。其中包括我依赖度很高的两个,比如这个云米热水器的第三方插件,ha提示:Platform error device_tracker.linksys_velop - Integration 'yunmi' not found.。我也尝试过用miot_auto插件接入热水器,但是不能实现热水循环的开关。所以,我决定自己折腾了,凭着自己折腾多年的教训(或者说经验),我认真看了smzdm大神分享插件中的代码,虽然看不太懂,但是基本上看出了时通过miio实现的本地接入,而且miio好像在node-red中有。于是我就开始尝试了,今天还让我误打误撞成功了。教程如下: 1.在node-red中安装 node-red-contrib-mi-miio节点,该节点的官方文档https://github.com/YinHangCode/node-red-contrib-mi-miio,大家可以自己看看
这个节点长这样:我们用自定义设备节点,就是最下面那个。
2.在node-red中倒入我给的代码:
[{"id":"5195d2cf43076f80","type":"inject","z":"f3ea0d3851fbb54e","name":"查询热水器状态","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{"cmd":"get"}","payloadType":"json","x":180,"y":140,"wires":[["2ccd143718e78220"]]},{"id":"a1c2dc1161e6d8b6","type":"inject","z":"f3ea0d3851fbb54e","name":"控制水温50度","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{"cmd":"miio","method":"set_temp","value":[50]}","payloadType":"json","x":170,"y":200,"wires":[["2ccd143718e78220"]]},{"id":"ee507146687eb987","type":"inject","z":"f3ea0d3851fbb54e","name":"控制水温40度","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{"cmd":"miio","method":"set_temp","value":[40]}","payloadType":"json","x":170,"y":260,"wires":[["2ccd143718e78220"]]},{"id":"39e05031cab35c85","type":"inject","z":"f3ea0d3851fbb54e","name":"打开热水循环","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{"cmd":"miio","method":"set_preheat_now","value":[1]}","payloadType":"json","x":170,"y":320,"wires":[["2ccd143718e78220"]]},{"id":"4496fb4cf315f08c","type":"inject","z":"f3ea0d3851fbb54e","name":"关闭热水循环","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{"cmd":"miio","method":"set_preheat_now","value":[0]}","payloadType":"json","x":170,"y":360,"wires":[["2ccd143718e78220"]]},{"id":"4e21e34e1aabae8d","type":"debug","z":"f3ea0d3851fbb54e","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload.result","targetType":"msg","statusVal":"","statusType":"auto","x":580,"y":280,"wires":[]},{"id":"c91799c73708792e","type":"debug","z":"f3ea0d3851fbb54e","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload.values","targetType":"msg","statusVal":"","statusType":"auto","x":580,"y":320,"wires":[]},{"id":"2ccd143718e78220","type":"Mi-Other","z":"f3ea0d3851fbb54e","name":"热水器","device":"0fcc65c394ae6b4d","x":330,"y":280,"wires":[["4e21e34e1aabae8d","c91799c73708792e"]]},{"id":"0fcc65c394ae6b4d","type":"Mi-Other-Device","deviceName":"热水器","deviceIP":"192.168.0.5","deviceToken":"55add7b10a4a455632551b7f78d3dc8a","deviceSyncInterval":"0","deviceAttributesArr":[{"attribute":"washStatus","setter":""},{"attribute":"velocity","setter":""},{"attribute":"waterTemp","setter":""},{"attribute":"targetTemp","setter":"set_temp"},{"attribute":"errStatus","setter":""},{"attribute":"isPreHeatNow","setter":"set_preheat_now"}]}]
倒入后应该是这个样子的:
4.双击咖啡色的那个节点,添加新的MI-other-divece节点添加你自己的IP和Token,一定要填对,其他不要改然后部署。
5.我的node-red中示范了5个内容,从上到下分别是1.查询热水器状态,返回包括:washStatus(热水器模式,0是关闭,其他分别是什么儿童洗、老人洗之类的,没啥用,但是注意的是,如果热水器正在运行,washStatus是0,和关闭时一样),velocity(流速),waterTemp(实时水温),targetTemp(设定水温,或者叫目标水温),errStatus(错误状态,具体是数字代表啥我也不知道),isPreHeatNow(热水循坏,1是开启,0是关闭,)。输入2和3分别是调节温度,输入4-5分别是打开和关闭热水循环。 6.值得注意的是,控制参数中"value":值上传的是一个数组,比如:"value": [50],如果直接上传数字会出错。
7.这是flow示范了查询热水器实时状态,调整温度,打开关闭热水循环功能,其实,还能控制热水器开关,但是我觉得没用,谁又会去关热水器呢?有了这个flow,怎么接入ha就看各位自己的喜欢了。
二、分享完再提问,我使用的三方插件linksys_velop,https://github.com/AdamNaj/linksys_velop,系统提示:Platform error device_tracker.linksys_velop - Integration 'linksys_velop' not found.。在我迁移到hassos中,也出现了同样的问题,新系统不支持这个插件,我也读了代码,也寄希望于能折腾出像上面一样的使用node-red的解决方案,但是失败了,主要问题在我自己,完全的不懂代码,下面是我认为和核心代码段,我觉得可能就是一个request,其中的self.username、self.password、self.host应该就是路由器的用户名、密码和地址。代码段如下:
def _make_request(self):
# Weirdly enough, this doesn't seem to require authentication
data = [
{
"request": {"sinceRevision": 0},
"action": "",
}
]
token = b64(bytes(self.username + ":" + self.password, "utf8")).decode("ascii");
headers = {
"X-JNAP-Action": "http://linksys.com/jnap/core/Transaction",
"X-JNAP-Authorization": "Basic " + token
}
return requests.post(
f"http://{self.host}/JNAP/",
timeout=DEFAULT_TIMEOUT,
headers=headers,
json=data,
)
求各位大神指点,兄弟在此跪谢,希望大神能给我一个用node-red的解决方案,三方插件用怕了,尤其是长期无人维护的插件,系统升级升着升着就不能用了。我把文件也放下下面,方便大神指点。
应坛子有要求,上传文件 |
评分
-
查看全部评分
|