in this videos, 2 channel RS485 Modbus relay connected with NodeMCU. These setup interfaced with Home Assistant through ESPHome.
These module has TTL output so it will be connected with NodeMCU.
RX pin - GPIO5, TX Pin - GPIO4 connected together.
Configuration.yaml file:
esphome:
name: modbus-uart
friendly_name: Modbus-uart
esp8266:
board: esp01_1m
Enable logging
logger:
Enable Home Assistant API
api:
encryption:
key: "sfT5EnZykJ2g0ht7TTcBIo1m66tZ4Z6is/izNsJr1Ps="
ota:
password: "0829f47ee08fcf4a5ed9d5ce38e338cc"
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: "Modbus-Uart Fallback Hotspot"
password: "l1p6CEIfMPRo"
captive_portal:
uart:
id: mbus
tx_pin: GPIO4
rx_pin: GPIO5
baud_rate: 9600
modbus:
id: modbus1
uart_id: mbus
send_wait_time: 200ms
modbus_controller:
id: a6
address: 1
modbus_id: modbus1
update_interval: 1s
switch:
platform: modbus_controller
name: 'modbus-switch1'
address: 0 # 0:relay1 1:relay2 ......
register_type: coil
bitmask: 1
platform: modbus_controller
name: 'modbus-switch2'
address: 1 # 0:relay1 1:relay2 ......
register_type: coil
bitmask: 1