Modbus Sensor


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

Configuration

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

# Example configuration.yaml entry
sensor:
  platform: modbus
  registers:
    - 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)

The name of the hub.

Default value:

default

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.

count

(integer)(Optional)

Number of registers to read.

Default value:

1

reverse_order

(boolean)(Optional)

Reverse the order of registers when count >1.

Default value:

false

scale

(float)(Optional)

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

Default value:

1

offset

(float)(Optional)

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

Default value:

0

precision

(integer)(Optional)

Number of valid decimals.

Default value:

0

data_type

(string)(Optional)

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

Default value:

int

structure

(string)(Optional)

If data_type is custom specify here a double quoted python struct format string to unpack the value. See python documentation for details. Ex: >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:

sensor:
- platform: modbus
  scan_interval: 10
  registers:
    - 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