Modbus


Modbus is a serial communication protocol to control PLCs (Programmable logic controller). It currently supports sensors and switches which can be controlled over serial, TCP, and UDP connections.

Configuration

The configuration for adding modbus to your installation depends on the connection type, either a network or serial connection.

Network connection

For a network connection, add the following to your configuration.yaml file:

# Example configuration.yaml entry for a TCP connection
modbus:
  type: tcp
  host: IP_ADDRESS
  port: 2020

Configuration Variables

type

(string)(Required)Type of the connection to Modbus. Possible values are tcp (Modbus TCP protocol according to “MODBUS Messaging Implementation Guide version 1.0b” provided by Schneider Automation.), udp(Modbus TCP form, but using UDP for transport. It removes the overheads required for TCP.) and rtuovertcp (Modbus RTU message transmitted with a TCP/IP wrapper and sent over a network instead of serial lines.).

host

(string)(Required)The IP address of your Modbus device, e.g., 192.168.1.1.

port

(integer)(Required)The network port for the communication.

timeout

(integer)(Optional)Timeout for slave response in seconds.

Default value: 3

Serial connection

For a serial connection, add the following to your configuration.yaml file:

# Example configuration.yaml entry for a serial connection
modbus:
  type: serial
  method: rtu
  port: /dev/ttyUSB0
  baudrate: 9600
  stopbits: 1
  bytesize: 8
  parity: N

Configuration Variables

type

(string)(Required)Type of the connection to Modbus, needs to be serial for this setup.

method

(string)(Required)Method of the connection to Modbus, either rtu or ascii.

port

(string)(Required)The port where your Modbus device is connected to your Home Assistant host.

baudrate

(integer)(Required)The speed for the serial connection.

stopbits

(integer)(Required)The stopbits for the serial connection, either 1 or 2.

bytesize

(integer)(Required)The bytesize for the serial connection; can be 5, 6, 7 or 8.

parity

(string)(Required)The parity for the serial connection; can be E, O or N.

timeout

(integer)(Optional)Timeout for slave response in seconds.

Default value: 3

Services

Service Description
write_register Write register. Requires unit, address and value fields. value can be either single value or an array

Building on top of Modbus