本帖最后由 adamjensen 于 2023-11-8 11:32 编辑
之前买了一个4路Modbus继电器,用hass自带的modbus集成接入过,能控制,但是状态反馈不同步,就吃灰了好久,现在想起来试试用esphome接入。
买的这种样子的,4路继电器,4路输入,12V供电。因为继电器开关状态反馈和输入状态都是按位读取的,hass自带的modbus集成不支持,而esphome是支持的。
用的模块是esp32-c3,板子用的liwei19920307大佬的ESP485项目 https://github.com/liwei19920307/ESP485
我发现esphome 2023.10.0的版本默认编译的esp32-c3 factory固件是qio模式的,刷入以后会不停重启,所以指定了board_build.flash_mode为dio
组合起来的样子,接了一个开关测试
esphome配置如下:
substitutions:
devicename: ESP485-01
MB_interval: 300ms
esphome:
name: esp485-01
platformio_options:
board_build.flash_mode: dio
esp32:
board: esp32-c3-devkitm-1
framework:
type: esp-idf
wifi:
ssid: "xxx"
password: "xxx"
fast_connect: true
logger:
api:
encryption:
key: xxx
ota:
password: "xxx"
uart:
id: esp485_uart
tx_pin: 19
rx_pin: 18
baud_rate: 9600
data_bits: 8
stop_bits: 1
modbus:
id: esp485_modbus
send_wait_time: 200ms
modbus_controller:
- id: esp485_modbus_controller
modbus_id: esp485_modbus
address: 0x2
command_throttle: 50ms
setup_priority: -10
update_interval: $MB_interval
switch:
- platform: modbus_controller
modbus_controller_id: esp485_modbus_controller
id: dam404_switch1
register_type: coil
address: 0
bitmask: 0
name: "dam404 switch1"
skip_updates: 2
- platform: modbus_controller
modbus_controller_id: esp485_modbus_controller
id: dam404_switch2
register_type: coil
address: 1
bitmask: 1
name: "dam404 switch2"
skip_updates: 2
- platform: modbus_controller
modbus_controller_id: esp485_modbus_controller
id: dam404_switch3
register_type: coil
address: 2
bitmask: 2
name: "dam404 switch3"
skip_updates: 2
- platform: modbus_controller
modbus_controller_id: esp485_modbus_controller
id: dam404_switch4
register_type: coil
address: 3
bitmask: 3
name: "dam404 switch4"
skip_updates: 2
binary_sensor:
- platform: modbus_controller
modbus_controller_id: esp485_modbus_controller
id: dam404_input1
register_type: discrete_input
address: 0
bitmask: 0
name: "dam404 input1"
on_press:
then:
- switch.toggle: dam404_switch1 #输入联动控制继电器
- platform: modbus_controller
modbus_controller_id: esp485_modbus_controller
id: dam404_input2
register_type: discrete_input
address: 1
bitmask: 1
name: "dam404 input2"
on_press:
then:
- switch.toggle: dam404_switch2
- platform: modbus_controller
modbus_controller_id: esp485_modbus_controller
id: dam404_input3
register_type: discrete_input
address: 2
bitmask: 2
name: "dam404 input3"
on_press:
then:
- switch.toggle: dam404_switch3
- platform: modbus_controller
modbus_controller_id: esp485_modbus_controller
id: dam404_input4
register_type: discrete_input
address: 3
bitmask: 3
name: "dam404 input4"
on_press:
then:
- switch.toggle: dam404_switch4
|