Need help with modbus

Hi,

I’m trying to write to a modbus register but cannot get it to work.
The documentation of the modbus device can be found here: http://www.pluggit.com/fileserver/files/1413/609560454939420/21_10_2013_modbus_addresses.pdf

Home Assistant OS 6.2
Home Assistant Version: core-2021.8.8

This is the register I try to write to:

I use a Lovelace UI Button-Card with the following code:

type: button
show_state: true
tap_action:
  action: call-service
  service: modbus.write_register
  service_data:
    address: 325
    unit: 1
    value: 2
  target: {}
show_icon: true
show_name: true
name: Pluggit Fan Level 2

I can read the register fine with the current sensor:

- name: Fan-Level
        slave: 1
        address: 324
        count: 1
        data_type: int

to write to it I used unit: 1 which in the official documentation says that unit it the slave address (Modbus - Home Assistant).
Although the slider for the Address in the button card only goes to 255 I can manually enter 325 which is the correct register as my sensor can read from it fine.

When pressing the button I get this error in the botom left in my browser window:
Error calling the modbus / write_register service. 'modbus_hub''

My logs show only this entry:

2021-09-11 12:36:16 DEBUG (SyncWorker_0) [pymodbus.client.sync] New Transaction state 'SENDING'

Any idea what I’m doing wrong?

so from the button-output i would guess the config lacks the hub-name i.e. the name you gave the modbus-connection in configuration.yaml

from the modbus-documentation:

service: modbus.write_register
data:
  address: <target register address>
  unit: <target slave address>
  hub: <hub name>
  value: [0x4120, 0x0000]

in your modbus-config in configuration.yaml you might have a

modbus:
  - type: rtuovertcp
    name: "Solar2EP"

the name ist the <hub name> you need to fill in

that is a good though, thanks.

my configuration.yaml for modbus starts like this:

modbus:
   name: pluggit
   type: tcp

I altered the button to match and the code now looks like this:

type: button
show_state: true
tap_action:
  action: call-service
  service: modbus.write_register
  service_data:
    address: 325
    unit: 1
    value: 1
    hub: pluggit
  target: {}
show_icon: true
show_name: true
name: Pluggit Fan 2

Cheking the log I find this error message after pressing the button.

image

Why it says illegalFunctions I dont understand but ok^^ Any idea what’s the issue now?

“illegal function” ist the modbus reply given for a register that is read-only.

i looked into the document an there i found the following:

The Ventilation unit supports the following commands of Modbus protocol:
– Read holding registers (0x03);
– Write multiple Holding registers (0x10).

so you chose the right function

maybe what is described in this post helps:

that means you would have to write to 324 instead of 325,
because the adress 40325 starting from 40000 translates to the 324th register …

modbus documentation often is like that…

type: button
show_state: true
tap_action:
  action: call-service
  service: modbus.write_register
  service_data:
    address: 324
    unit: 255
    value: [1,0]
    hub: pluggit
  target: {}
show_icon: true
show_name: true
name: Pluggit Fan 1

type: button
show_state: true
tap_action:
  action: call-service
  service: modbus.write_register
  service_data:
    address: 324
    unit: 255
    value: [2,0]
    hub: pluggit
  target: {}
show_icon: true
show_name: true
name: Pluggit Fan 2

etc....