Modbus Sensor

The modbus sensor allows you to gather data from Modbus registers.


To use your Modbus sensors in your installation, add the following to your configuration.yaml file:

# Example configuration.yaml entry
  platform: modbus
    - name: Sensor1
      hub: hub1
      unit_of_measurement: °C
      slave: 1
      register: 100
    - name: Sensor2
      hub: hub1
      unit_of_measurement: mg
      slave: 1
      register: 110
      count: 2
    - name: Sensor3
      hub: hub1
      unit_of_measurement: °C
      slave: 1
      register: 120
      register_type: input
      data_type: float
      scale: 0.01
      offset: -273.16
      precision: 2

Configuration Variables

registers map Required

The array contains a list of relevant registers to read from.

name string Required

Name of the sensor.

hub string (Optional, default: default)

The name of the hub.

slave integer Required

The number of the slave (Optional for tcp and upd Modbus).

register integer Required

Register number.

register_type string (Optional)

Modbus register type (holding, input), default holding.

unit_of_measurement integer (Optional)

Unit to attach to value.

device_class device_class (Optional, default: None)

The type/class of the sensor to set the icon in the frontend.

count integer (Optional, default: 1)

Number of registers to read.

reverse_order boolean (Optional, default: false)

Reverse the order of registers when count >1.

scale float (Optional, default: 1)

Scale factor (output = scale * value + offset).

offset float (Optional, default: 0)

Final offset (output = scale * value + offset).

precision integer (Optional, default: 0)

Number of valid decimals.

data_type string (Optional, default: int)

Response representation (int, uint, float, string, custom). If float selected, value will be converted to IEEE 754 floating point format.

structure string (Optional)

If data_type is custom specified a double-quoted Python struct is expected here, to format the string to unpack the value. See Python documentation for details. Example: >i.

It’s possible to change the default 30 seconds scan interval for the sensor updates as shown in the Platform options documentation.

If you specify scale or offset as floating point values, double precision floating point arithmetic will be used to calculate final value. This can cause loss of precision for values that are larger than 2^53.

Full example

Example a temperature sensor with a 10 seconds scan interval:

- platform: modbus
  scan_interval: 10
    - name: Room_1
      hub: hub1
      slave: 10
      register: 0
      register_type: holding
      unit_of_measurement: °C
      count: 1
      scale: 0.1
      offset: 0
      precision: 1
      data_type: integer