Modbus writing to a holding register with function call 16 (0x10)

Hey.
I’m working on setting up home assistant to interact with my heatpump/ventilation through modbus.
(usb dongle into the pi)
I got the inputs set up, no problem.
However, writing to a holding register provides a challenge.
For example, I’ve set up the main on/off as a switch:

- name: OnOff
  slave: 30
  address: 1001
  device_class: switch
  write_type: holding
  verify:

This works fine for reading the register, but I can’t seem to write to that register, using this entity.
The documentation states that writing is done with “function call 16”, and looking through the HA documentation, it seems that I have to write an array then…
However, I’m don’t know how to do that for the entity card.

I did manage to use a button to call a service using this code:

type: button
tap_action:
  action: call-service
  service: modbus.write_register
  service_data:
    address: 1001
    unit: 30
    hub: Nilan
    value:
      - 1
  target: {}
entity: switch.onoff

But this means I would have to use TWO buttons, instead of a switch…
Is there a way to make the switch entity send an array instead of a single value?

Hi Anders,

Have you been able to solve this issue, to send a single value with function code 16?

I have a similar issue

1 Like

No, I haven’t solved it.
I’m not that deep into function calls.
Can you post how your code ended up looking exactly?

My final code is described here:

https://gathering.tweakers.net/forum/list_message/74055204#74055204

1 Like