Modbus register & address mapping trouble

Hello community!
I’ve managed to set up home assistant and a modbus interface to monitor and control a Swecon Casa R120 ventilation / heat recovery unit.
Modbus seems to work, but I’m having trouble mapping the documented register values to correct coil: and register: values in my home assistant configuration.

The documentation lists e.g.:
3x6201 = Fresh air temperature
How do I map the register values, starting with 3x, 4x etc to correct values in the home assistant modbus configuration?

Hi there, super late reply, but I guess this should work:

modbus:
- name: my-hvac-unit
  type: tcp
  host: 192.168.0.10
  port: 502

sensor:
- platform: modbus
  registers:
    - name: Fresh air temperature
      hub: my-hvac-unit
      register_type: input
      register: 6200
      slave: 1
      scale: 0.1
      precision: 1
      unit_of_measurement: °C
      device_class: temperature

3 means “input register” in modbus lingo, i.e. a 16 bit storage unit containing data input into the modbus controller unit (typically sensor values).

4 is “holding register”, i.e. a 16 bit storage unit containing data originating in the modbus controller unit (typically configuration values).

I don’t see any in the docs for your unit, but for completeness modbus also allows binary storage units:
0 = “discrete output”, the binary version of “holding register”
1 = “discrete input”, the binary version of “input register”

PS: The modbus implementation in Home Assistant uses what’s called “PDU Addressing”, which means you will get an off-by-one error compared to the documentation of most modbus controllers. That’s why I’ve put “register: 6200” in my config example instead of “register: 6201”, which would be correct if I was to directly translate from the Swegon documentation.

Also notice that Swegon by my experience requires you to specify “slave: 1”, even though this is normally not mandatory for modbus over TCP.

1 Like

Thanks for the advice! Meanwhile, I got things working but forgot to update this topic. Here are some tips for those who try to work with Swegon modbus in the future:

  • There are different kind of modbus adapters for Swegon units: The “premium” line needs a modbus premium gw, and the “smart” line needs a smart modbus gw. If you connect a “smart gw” to a Swegon “premium” unit, you’ll get a connection but the modbus values will not make any sense.

  • For some writable registers, you’ll have to “authenticate” first by writing the value of your device’s admin PIN to the correct register. In an automation I do this before any actual commands:

  action:
  - data:
      address: 3999
      hub: hub1
      unit: 2
      value: 4321
    service: modbus.write_register

  • The configuration is really simple to get working. The baud rate, parity and data bits settings must match the dip switches on the modbus gw device. My USB-to-rs485 adapter is named usb-1a86_USB2.0-Serial-if00-port0 and so:
modbus:
  name: hub1
  type: serial
  method: rtu
  port: /dev/serial/by-id/usb-1a86_USB2.0-Serial-if00-port0
  baudrate: 38400
  stopbits: 1
  bytesize: 8
  parity: N

# example for the Swegon Casa R120
# https://www1.swegon.com/Global/PDFs/Home%20ventilation/Air%20handling%20units/Swegon%20CASA%20R-series/_en/CASA_modbus.pdf
# (note the value: 335, 3x0336 in Swegon docs minus offset )
sensor:
  - platform: modbus
    registers:
    - name: Supply air temperature
      hub: hub1
      unit_of_measurement: °C
      slave: 2
      register: 335
      register_type: input
      scale: 0.1
      precision: 1
    - name: Fan speed Mode
      hub: hub1
      slave: 2
      register: 4099
      register_type: holding



The modbus connection has been really reliable.
For debugging, the mbpoll utility program is really handy. Eg. to get the supply air temperature reading, I would do: (note the value: 336, 3x0336 in Swegon docs)

# mbpoll  /dev/serial/by-id/usb-1a86_USB2.0-Serial-if00-port0 -a 2 -b 38400 -P none  -t 3 -r 336
1 Like

Hi! Does this work for you? That you register the sensor under the sensor platform with registers? When I tried this I didn’t get any sensors created for me.

In the modbus documentation they say you should register the sensor under the modbus registration. Do you know what the difference is? This is the example they have here:

Hi! I guess the advice I gave above is outdated, as the modbus configration changed with home assistant release 2021.7 ( 2021.7: A new entity, trigger IDs and script debugging - Home Assistant )

Now I have a separate modbus.yaml that I include from the main configuration. It starts like this:

  - name: hub1
    type: serial
    method: rtu
    port: /dev/serial/by-id/usb-1a86_USB2.0-Serial-if00-port0
    baudrate: 38400
    stopbits: 1
    bytesize: 8
    parity: N
    sensors:
      - name: Outside air temperature
        unit_of_measurement: °C
        slave: 2
        address: 332
        input_type: input
        scale: 0.1
        precision: 1
        scan_interval: 60
 ....

Hope this helps!

2 Likes

Hi!

I see, now I understand why I see people mentioning the setup like that, thanks!

I also really liked you explaining the difference between the “input register” / “holding register” and so forth. I have those as well in my manual but wasn’t sure what to make of it.