家里的新风接入已经好久了,通讯用的是标准MODBUS协议,厂家发给我的通讯地址如下
用支持TCP的485模块接入到两台设备的AB端,分别把设备地址设为1和2(我负二楼的新风设备地址2,负一楼的设备地址为1)
接入后的HA中的显示如下:
配置文件如下(水平有限,配置文件写的一般,望论坛内的高手指点):
modbus:
#新风机 -1楼为1号机 -2楼为2号机
- type: tcp
host: 192.168.1.2
port: 9999
name: hub2
#新风数据
sensor:
- platform: modbus
# scan_floaterval: 10 #0.88版以后这个语句失效
registers:
#负1楼新风系统读参数
- name: fresh_air_f1_power
hub: hub2
unit_of_measurement: 1开0关
slave: 1
register: 8704
- name: fresh_air_f1_temperature
hub: hub2
unit_of_measurement: °C
slave: 1
register: 8706
- name: fresh_air_f1_humidity
hub: hub2
unit_of_measurement: "%RH"
slave: 1
register: 8707
- name: fresh_air_f1_PM2.5
hub: hub2
unit_of_measurement: μg/m³
slave: 1
register: 8712
- name: fresh_air_f1_mode
hub: hub2
unit_of_measurement: 0除湿1通风2净化
slave: 1
register: 8713
- name: fresh_air_f1_speed
hub: hub2
unit_of_measurement: 0低档1中档2高档
slave: 1
register: 8714
#负2楼新风系统读参数
- name: fresh_air_f2_power
hub: hub2
unit_of_measurement: 1开0关
slave: 2
register: 8704
- name: fresh_air_f2_temperature
hub: hub2
unit_of_measurement: °C
slave: 2
register: 8706
- name: fresh_air_f2_humidity
hub: hub2
unit_of_measurement: "%RH"
slave: 2
register: 8707
- name: fresh_air_f2_PM2.5
hub: hub2
unit_of_measurement: μg/m³
slave: 2
register: 8712
- name: fresh_air_f2_mode
hub: hub2
unit_of_measurement: 0除湿1通风2净化
slave: 2
register: 8713
- name: fresh_air_f2_speed
hub: hub2
unit_of_measurement: 0低档1中档2高档
slave: 2
register: 8714
input_select:
#负1楼新风系统选择
fresh_air_f1_power:
name: 电源开关
icon: mdi:fan
options:
- "打开新风"
- "关闭新风"
fresh_air_f1_mode:
name: 模式
icon: mdi:fan
options:
- "除湿"
- "通风"
fresh_air_f1_speed:
name: 风速
icon: mdi:fan
options:
- "低档"
- "中档"
- "高档"
#负2楼新风系统选择
fresh_air_f2_power:
name: 电源开关
icon: mdi:fan
options:
- "打开新风"
- "关闭新风"
fresh_air_f2_mode:
name: 模式
icon: mdi:fan
options:
- "除湿"
- "通风"
fresh_air_f2_speed:
name: 风速
icon: mdi:fan
options:
- "低档"
- "中档"
- "高档"
group:
#负1楼新风
fresh_air_f1:
name: 负1楼新风系统
view: no
control: hidden
entities:
- sensor.fresh_air_f1_temperature
- sensor.fresh_air_f1_humidity
- sensor.fresh_air_f1_pm2_5
- input_select.fresh_air_f1_power
- input_select.fresh_air_f1_mode
- input_select.fresh_air_f1_speed
#负2楼新风
fresh_air_f2:
name: 负2楼新风系统
view: no
control: hidden
entities:
- sensor.fresh_air_f2_temperature
- sensor.fresh_air_f2_humidity
- sensor.fresh_air_f2_pm2_5
- input_select.fresh_air_f2_power
- input_select.fresh_air_f2_mode
- input_select.fresh_air_f2_speed
automation:
#******************负一楼欧伦新风(带除湿功能)*********************
#F1新风开关状态读取
#F1新风开关状态写入
- alias: fresh_air_f1_set_power
initial_state: true
trigger:
platform: state
entity_id: sensor.fresh_air_f1_power
action:
service: input_select.select_option
data_template:
entity_id: input_select.fresh_air_f1_power
option: >
{% if states.sensor.fresh_air_f1_power.state == "0" %}关闭新风
{% elif states.sensor.fresh_air_f1_power.state == "1" %}打开新风
{% endif %}
#F1新风开关状态写入寄存器(关->开)
- alias: fresh_air_f1_power_open
trigger:
entity_id: input_select.fresh_air_f1_power
from: 关闭新风
platform: state
to: 打开新风
condition: []
action:
- data:
address: 8960
hub: hub2
unit: 1
value:
- 23041
service: modbus.write_register
#F1新风开关状态写入寄存器(开->关)
- alias: fresh_air_f1_power_close
trigger:
entity_id: input_select.fresh_air_f1_power
from: 打开新风
platform: state
to: 关闭新风
condition: []
action:
- data:
address: 8960
hub: hub2
unit: 1
value:
- 23040
service: modbus.write_register
#F1新风模式读取
- alias: fresh_air_f1_get_mode
initial_state: true
trigger:
platform: time_pattern
seconds: /5
action:
service: input_select.select_option
data_template:
entity_id: input_select.fresh_air_f1_mode
option: >
{% if states.sensor.fresh_air_f1_mode.state == "0" %}除湿
{% elif states.sensor.fresh_air_f1_mode.state == "1" %}通风
{% endif %}
#F1新风模式选择(写入)
- alias: fresh_air_f1_set_mode
initial_state: true
trigger:
platform: state
entity_id: input_select.fresh_air_f1_mode
action:
service: input_select.select_option
data_template:
entity_id: sensor.fresh_air_f1_mode
option: >
{% if states.input_select.fresh_air_f1_mode.state == "除湿" %}0
{% elif states.input_select.fresh_air_f1_mode.state == "通风" %}1
{% endif %}
#F1新风模式写入寄存器(除湿->通风)
- alias: fresh_air_f1_mode_tf
trigger:
entity_id: input_select.fresh_air_f1_mode
from: 除湿
platform: state
to: 通风
condition: []
action:
- data:
address: 8963
hub: hub2
unit: 1
value:
- 1
service: modbus.write_register
- data:
address: 8962
hub: hub2
unit: 1
value:
- 23205
service: modbus.write_register
#F1新风模式写入寄存器(通风->除湿)
- alias: fresh_air_f1_mode_cs
trigger:
entity_id: input_select.fresh_air_f1_mode
from: 通风
platform: state
to: 除湿
condition: []
action:
- data:
address: 8963
hub: hub2
unit: 1
value:
- 0
service: modbus.write_register
- data:
address: 8962
hub: hub2
unit: 1
value:
- 23205
service: modbus.write_register
#F1新风模式风速读取
- alias: fresh_air_f1_get_speed
initial_state: true
trigger:
platform: time_pattern
seconds: /5
action:
service: input_select.select_option
data_template:
entity_id: input_select.fresh_air_f1_speed
option: >
{% if states.sensor.fresh_air_f1_speed.state == "0" %}低档
{% elif states.sensor.fresh_air_f1_speed.state == "1" %}中档
{% elif states.sensor.fresh_air_f1_speed.state == "2" %}高档
{% endif %}
#F1新风速度选择(写入)
- alias: fresh_air_f1_set_speed
initial_state: true
trigger:
platform: state
entity_id: input_select.fresh_air_f1_speed
action:
service: input_select.select_option
data_template:
entity_id: sensor.fresh_air_f1_speed
option: >
{% if states.input_select.fresh_air_f1_speed.state == "低档" %}0
{% elif states.input_select.fresh_air_f1_speed.state == "中档" %}1
{% elif states.input_select.fresh_air_f1_speed.state == "高档" %}2
{% endif %}
#负一楼新风风速选择(写寄存器)
#低速
- alias: fresh_air_f1_speed_low
trigger:
entity_id: input_select.fresh_air_f1_speed
from: 中档
platform: state
to: 低档
entity_id: input_select.fresh_air_f1_speed
from: 高档
platform: state
to: 低档
condition: []
action:
- data:
address: 8965
hub: hub2
unit: 1
value:
- 0
service: modbus.write_register
- data:
address: 8962
hub: hub2
unit: 1
value:
- 23205
service: modbus.write_register
#中速
- alias: fresh_air_f1_speed_ medium
trigger:
entity_id: input_select.fresh_air_f1_speed
from: 低档
platform: state
to: 中档
entity_id: input_select.fresh_air_f1_speed
from: 高档
platform: state
to: 中档
condition: []
action:
- data:
address: 8965
hub: hub2
unit: 1
value:
- 1
service: modbus.write_register
- data:
address: 8962
hub: hub2
unit: 1
value:
- 23205
service: modbus.write_register
#高速
- alias: fresh_air_f1_speed_high
trigger:
entity_id: input_select.fresh_air_f1_speed
from: 低档
platform: state
to: 高档
entity_id: input_select.fresh_air_f1_speed
from: 中档
platform: state
to: 高档
condition: []
action:
- data:
address: 8965
hub: hub2
unit: 1
value:
- 2
service: modbus.write_register
- data:
address: 8962
hub: hub2
unit: 1
value:
- 23205
service: modbus.write_register
#******************负二楼欧伦新风(带除湿功能)*********************
#F2新风开关状态读取
#F2新风开关状态选择(写入)
- alias: fresh_air_f2_set_power
initial_state: true
trigger:
platform: state
entity_id: sensor.fresh_air_f2_power
action:
service: input_select.select_option
data_template:
entity_id: input_select.fresh_air_f2_power
option: >
{% if states.sensor.fresh_air_f2_power.state == "0" %}关闭新风
{% elif states.sensor.fresh_air_f2_power.state == "1" %}打开新风
{% endif %}
#F2新风开关状态写入寄存器(关->开)
- alias: fresh_air_f2_power_open
trigger:
entity_id: input_select.fresh_air_f2_power
from: 关闭新风
platform: state
to: 打开新风
condition: []
action:
- data:
address: 8960
hub: hub2
unit: 1
value:
- 23041
service: modbus.write_register
#F2新风开关状态写入寄存器(开->关)
- alias: fresh_air_f1_power_close
trigger:
entity_id: input_select.fresh_air_f2_power
from: 打开新风
platform: state
to: 关闭新风
condition: []
action:
- data:
address: 8960
hub: hub2
unit: 1
value:
- 23040
service: modbus.write_register
#F2新风模式读取
- alias: fresh_air_f2_get_mode
initial_state: true
trigger:
platform: time_pattern
seconds: /5
action:
service: input_select.select_option
data_template:
entity_id: input_select.fresh_air_f2_mode
option: >
{% if states.sensor.fresh_air_f2_mode.state == "0" %}除湿
{% elif states.sensor.fresh_air_f2_mode.state == "1" %}通风
{% endif %}
#F2新风模式选择(写入)
- alias: fresh_air_f2_get_mode
initial_state: true
trigger:
platform: state
entity_id: input_select.fresh_air_f2_mode
action:
service: input_select.select_option
data_template:
entity_id: sensor.fresh_air_f2_mode
option: >
{% if states.input_select.fresh_air_f2_mode.state == "除湿" %}0
{% elif states.input_select.fresh_air_f2_mode.state == "通风" %}1
{% endif %}
#F2新风模式写入寄存器(除湿->通风)
- alias: fresh_air_f2_mode_tf
trigger:
entity_id: input_select.fresh_air_f2_mode
from: 除湿
platform: state
to: 通风
condition: []
action:
- data:
address: 8963
hub: hub2
unit: 2
value:
- 1
service: modbus.write_register
- data:
address: 8962
hub: hub2
unit: 2
value:
- 23205
service: modbus.write_register
#F2新风模式写入寄存器(通风->除湿)
- alias: fresh_air_f2_mode_cs
trigger:
entity_id: input_select.fresh_air_f2_mode
from: 通风
platform: state
to: 除湿
condition: []
action:
- data:
address: 8963
hub: hub2
unit: 2
value:
- 0
service: modbus.write_register
- data:
address: 8962
hub: hub2
unit: 2
value:
- 23205
service: modbus.write_register
F2新风速度读取
- alias: fresh_air_f2_get_speed
initial_state: true
trigger:
platform: time_pattern
seconds: /5
action:
service: input_select.select_option
data_template:
entity_id: input_select.fresh_air_f2_speed
option: >
{% if states.sensor.fresh_air_f2_speed.state == "0" %}低档
{% elif states.sensor.fresh_air_f2_speed.state == "1" %}中档
{% elif states.sensor.fresh_air_f2_speed.state == "2" %}高档
{% endif %}
#F2新风速度选择(写入)
- alias: fresh_air_f2_set_speed
initial_state: true
trigger:
platform: state
entity_id: input_select.fresh_air_f2_speed
action:
service: input_select.select_option
data_template:
entity_id: sensor.fresh_air_f2_speed
option: >
{% if states.input_select.fresh_air_f2_speed.state == "低档" %}0
{% elif states.input_select.fresh_air_f2_speed.state == "中档" %}1
{% elif states.input_select.fresh_air_f2_speed.state == "高档" %}2
{% endif %}
#负二楼新风风速选择(写寄存器)
#低速
- alias: fresh_air_f2_speed_low
trigger:
entity_id: input_select.fresh_air_f2_speed
from: 中档
platform: state
to: 低档
entity_id: input_select.fresh_air_f2_speed
from: 高档
platform: state
to: 低档
condition: []
action:
- data:
address: 8965
hub: hub2
unit: 2
value:
- 0
service: modbus.write_register
- data:
address: 8962
hub: hub2
unit: 2
value:
- 23205
service: modbus.write_register
#中速
- alias: fresh_air_f2_speed_ medium
trigger:
entity_id: input_select.fresh_air_f2_speed
from: 低档
platform: state
to: 中档
entity_id: input_select.fresh_air_f2_speed
from: 高档
platform: state
to: 中档
condition: []
action:
- data:
address: 8965
hub: hub2
unit: 2
value:
- 1
service: modbus.write_register
- data:
address: 8962
hub: hub2
unit: 2
value:
- 23205
service: modbus.write_register
#高速
- alias: fresh_air_f2_speed_high
trigger:
entity_id: input_select.fresh_air_f2_speed
from: 低档
platform: state
to: 高档
entity_id: input_select.fresh_air_f2_speed
from: 中档
platform: state
to: 高档
condition: []
action:
- data:
address: 8965
hub: hub2
unit: 2
value:
- 2
service: modbus.write_register
- data:
address: 8962
hub: hub2
unit: 2
value:
- 23205
service: modbus.write_register
附上配置文件下载(放到packages目录下)
fresh_air.rar
(1.71 KB, 下载次数: 145)
|