Home Assistant 2022 does not recognize Modbus sensors

I have been using Modbus RS-485 with XRUSB adapter for reading data from solar charge controller with Home Assistant 0.107.4. Now I am trying to build the new version of this setup using the new Raspberry PI OS and Home Assistant 2022. The configuration is not working with this version. I don’t see any error messages in the home assistant log. I only see one message in the log file “modbus communication open”. There are no messages about the sensors.

Here is the modbus definition in the configuration.yaml

====================

# configuration.yaml
modbus:
  - name: epeverxtra
    type: serial
    baudrate: 115200
    bytesize: 8
    method: rtu
    parity: N
    port: /dev/ttyXRUSB0
    stopbits: 1
sensor: !include sensors.yaml

====================

Here is the sensors.yaml.
I have tried “sensors” / “registers”
I have tried “register” / “address”
None of these options work.

====================

# sensors.yaml
  - platform: modbus
    scan_interval: 5
    sensors:
      - name: Bat_Voltage
        hub: epeverxtra
        unit_of_measurement: V
        slave: 1
        address: 0x3104
        register_type: input
        scan_interval: 1
        scale: 0.01

      - name: Bat_Rated_Voltage
        hub: epeverxtra
        unit_of_measurement: V
        slave: 1
        address: 0x311D
        register_type: input
        scan_interval: 1
        scale: 0.01

====================

I have tested the setup with the minimal modbus python code below and it works.
python readRegister.py 0x3104

======================

# readRegister.py
import sys
import minimalmodbus

def readRegister(register):
    try:
            instrument = minimalmodbus.Instrument('/dev/ttyXRUSB0', 1)
    except minimalmodbus.serial.SerialException:
            return 0

    instrument.serial.baudrate = 115200
    instrument.serial.bytesize = 8
    instrument.serial.parity   = minimalmodbus.serial.PARITY_NONE
    instrument.serial.stopbits = 1
    instrument.serial.timeout  = 1.2
    instrument.mode = minimalmodbus.MODE_RTU

    try:
            reading = instrument.read_register(int(register, 16), 2, 4)
            return reading
    except IOError:
            return 0

if len(sys.argv) == 1:
    print(0)
else :
    register = sys.argv[1]
    print (readRegister(register))

====================

Thank you for your help,
Naren

1 Like

There is no sensor modbus platform now

Just as example:

modbus:

  - name: edpbox3
    type: tcp
    host: 10.1.0.47
    port: 9502
    delay: 1
    timeout: 3
    retries: 3
    retry_on_empty: true
    message_wait_milliseconds: 750

    sensors:

### ### ###

      - name: "EB3 T1 Vazio" # 0x0026
        slave: 1
        address: 38
        input_type: input
        count: 1
        data_type: uint32
        precision: 1
        scale: 0.001
        unit_of_measurement: kWh
        device_class: energy
        state_class: total_increasing
        scan_interval: 91

      - name: "EB3 T2 Ponta" # 0x0027
        slave: 1
        address: 39
        input_type: input
        count: 1
        data_type: uint32
        precision: 1
        scale: 0.001
        unit_of_measurement: kWh
        device_class: energy
        state_class: total_increasing
        scan_interval: 92

And you need decimal address, I think

Thank you so much for the help. I made the change to the sensor definition. Yes, in the past versions, I used to have all modbus sensors including other sensors defined in sensors.yaml. Defining the sensors like that is not working anymore. I am wondering if this is due to a major architecture change in the configuration files across the board, not just Modbus. I separated the whole Modbus definition to a separate file called modbus.yaml and added the include for the Modbus file.
Additionally, I had to change “register” to “address” and “register_type” to “input_type” and add input_type for all sensors. On my charge controller, the holding registers start with 0x9… and the input registers start with 0x3…

I changed from:

        register: 0x3104
        register_type: input

to:

        address: 0x3104
        input_type: input

configuration.yaml

modbus: !include modbus.yaml

modbus.yaml

  - name: modbusdevice
    type: serial
    baudrate: 115200
    bytesize: 8
    method: rtu
    parity: N
    port: /dev/ttyXRUSB0
    stopbits: 1
    message_wait_milliseconds: 5000  
    retries: 20
    retry_on_empty: true
    close_comm_on_error: false

    sensors:

      - name: Battery Voltage
        unit_of_measurement: V
        slave: 1
        address: 0x3104
        input_type: input
        precision: 2
        scale: 0.01
        scan_interval: 30


      - name: PV Power
        unit_of_measurement: W
        slave: 1
        address: 0x3102
        input_type: input
        precision: 2
        scale: 0.01
        scan_interval: 30

      - name: Load Power
        unit_of_measurement: W
        slave: 1
        address: 0x310E
        input_type: input
        precision: 2
        scale: 0.01
        scan_interval: 30
1 Like

Hi :slight_smile:

I’m playing with modbus right now, and I cannot see the sensor, therefore I cannot add any cards in my dashboard.

Here’s my code for modbus:

modbus:
  - name: modbus_hub
    type: serial
    port: /dev/ttyUSB0
    baudrate: 19200
    bytesize: 8
    method: rtu
    parity: E
    stopbits: 2
    close_comm_on_error: true
    delay: 0
    message_wait_milliseconds: 30
    retries: 3
    retry_on_empty: false
    timeout: 5
    
    sensors:
    
    - name: Active Power Total
      unit_of_measurement: W
      slave: 1
      address: 0x30140
      input_type: input
      precision: 2
      scale: 0.1
      data_type: float32
      device_class: energy
      state_class: total_increasing
      scan_interval: 30

Am I doing something wrong?

hi @emi_d

what do you use as an energy sensor? Have you managed to make progress in your project?
THANKS

I’m trying to interface with an EM112 on my side.