【Node-RED】鸿雁排插-曲线救国接入HA
众所周知,鸿雁排插是博联代工,故此可以使用博联的插件接入 Home-assistant,但官方的Home-Assistant MP1插件响应缓慢,而且博联也经常在 Home-Assistant 中坑爹,而本坛C大之前写的插件,在7开头版本中已经无法使用,目前没有大佬修复的话估计就要寿终正寝。
后来萝卜提醒我,他正使用 Node-RED 的博联插件,所以我就萌生将博联通过 Node-RED 接入 HA的想法。
接入方法分析
通过 Node-RED 的博联插件控制并获得博联插座状态,然后使用 mqtt 传递 Home-Assistant 和 Node-RED 之间的控制命令与状态。
前置需求
- 安装好 Node-RED,并安装以下依赖(博联插件,必须大于 1.0.3,1.0.2之前的在状态显示上有bug,这个bug我查了好久,其实很简单就是多了个&符号囧。)
node-red-contrib-broadlink-control
- 已配置好 mqtt 服务器并正常使用
配置 Node-RED
1. 导入 Flow
将以下json文件导入Node-RED
2. 配置 Flow
为了简化大家的配置,我已经将 Flow 改了好几版,最终这版是我比较满意的,大部分都复用,用户只需要根据自己的排插数量增加 mqtt in,和编写排插信息就好了。
- 双击一个mqtt节点(也就是紫色最前面或者最后面的节点随便一个),加入MQTT服务端。
- 编写 mqtt主题(topic),例子
broadlink/dating_switchs/cmd
,我定义的是前面是broadlink固定的,然后中间插座位置表述,最后是控制或者是状态/state
or /cmd
.
- 双击排查信息 function 节点,按照以下方式输入你的排插信息。
注意,中间的博联不需要添加节点,你只需要编辑下面的switchs 对象,流程会自动根据你要控制的节点去控制相应的插座。
// ---
// 请按以下要求填写排插信息
// mqtt 命名规则
// broadlink/排插名称/cmd 此为控制 topic
// broadlink/排插名称/state 此为状态显示 topic
// 根据以下范例填写 switchs 对象内容
// "排插名称(和mqtt中的排插名称必须一致)":{
// "name":"排插名称",
// "host":"排插IP地址(建议在路由设置静态dhcp分配)",
// "mac":"排插mac地址"
//}
//
//对象遵循 json 格式.
// ---
var switchs={
"dating_switchs":{
"name":"dating_switchs",
"host":"10.88.10.3",
"mac":"FF:FF:FF:FF:FF:1F"
},
"bookroom_switchs":{
"name":"bookroom_switchs",
"host":"10.88.10.1",
"mac":"FF:FF:FF:FF:FF:2F"
}
}
Home-assistant 配置
switch:
###
# dating_switchs
###
- platform: mqtt
name: drive1
state_topic: "broadlink/dating_switchs/state"
value_template: "{{ value_json['s1'] }}"
command_topic: "broadlink/dating_switchs/cmd"
payload_on: '{"key":"s1","action":"on"}'
payload_off: '{"key":"s1","action":"off"}'
state_on: true
state_off: false
- platform: mqtt
name: drive2
state_topic: "broadlink/dating_switchs/state"
value_template: "{{ value_json['s2'] }}"
command_topic: "broadlink/dating_switchs/cmd"
payload_on: '{"key":"s2","action":"on"}'
payload_off: '{"key":"s2","action":"off"}'
state_on: true
state_off: false
- platform: mqtt
name: drive3
state_topic: "broadlink/dating_switchs/state"
value_template: "{{ value_json['s3'] }}"
command_topic: "broadlink/dating_switchs/cmd"
payload_on: '{"key":"s3","action":"on"}'
payload_off: '{"key":"s3","action":"off"}'
state_on: true
state_off: false
- platform: mqtt
name: drive4
state_topic: "broadlink/dating_switchs/state"
value_template: "{{ value_json['s4'] }}"
command_topic: "broadlink/dating_switchs/cmd"
payload_on: '{"key":"s4","action":"on"}'
payload_off: '{"key":"s4","action":"off"}'
state_on: true
state_off: false
###
# bookroom_switchs
###
- platform: mqtt
name: bookroom_switch_1
state_topic: "broadlink/bookroom_switchs/state"
value_template: "{{ value_json['s1'] }}"
command_topic: "broadlink/bookroom_switchs/cmd"
payload_on: '{"key":"s1","action":"on"}'
payload_off: '{"key":"s1","action":"off"}'
state_on: true
state_off: false
- platform: mqtt
name: bookroom_switch_2
state_topic: "broadlink/bookroom_switchs/state"
value_template: "{{ value_json['s2'] }}"
command_topic: "broadlink/bookroom_switchs/cmd"
payload_on: '{"key":"s2","action":"on"}'
payload_off: '{"key":"s2","action":"off"}'
state_on: true
state_off: false
- platform: mqtt
name: bookroom_switch_3
state_topic: "broadlink/bookroom_switchs/state"
value_template: "{{ value_json['s3'] }}"
command_topic: "broadlink/bookroom_switchs/cmd"
payload_on: '{"key":"s3","action":"on"}'
payload_off: '{"key":"s3","action":"off"}'
state_on: true
state_off: false
- platform: mqtt
name: bookroom_switch_4
state_topic: "broadlink/bookroom_switchs/state"
value_template: "{{ value_json['s4'] }}"
command_topic: "broadlink/bookroom_switchs/cmd"
payload_on: '{"key":"s4","action":"on"}'
payload_off: '{"key":"s4","action":"off"}'
state_on: true
state_off: false
Enjoy~!