Modbus and PID control

As we discussed last year in my thread on modbus [Modbus challenge], I’d trying to monitor and control a commercial PID Temp controller via modbus.
Well, new year, new controller. With the new controller, I can successfully read the PV, SV and alarm setting and value.

But, I am unable to new SV value to a register.

Per the controller docs SYL-2381 docs, in order to write a floating point value I must use modbus function 10H. As I read the HA modbus docs, in order to use function 10H for a write, I must specify an array. I’m using the following service call to set the temp to 75.

service: modbus.write_register
data:
  value: [00,75]
  hub: modbus_hub
  unit: 2
  address: 00

This results in the setting changing to 0.
I have also tried [75,00] : also changed to 0
[75] - no change plus error:

Logger: homeassistant.helpers.script.websocket_api_script
Source: helpers/script.py:409
First occurred: 4:05:08 PM (1 occurrences)
Last logged: 4:05:08 PM

websocket_api script: Error executing script. Invalid data for call_service at pos 1: expected int @ data['value'][0]

and 75 has no effect.

Apppreciate any assistance. I am on 2023.2.5 running HAOS on a HA Blue.

\\Greg

00 isn’t a number and is being parsed as a string. Use 0 for address

I misread your question. It executes the call when you specify an array, but fails when the array only has one element?

1 Like

Correct regarding the array. And using an array, it only succeeds in setting the SV to 0. But it does at least change it!

(BTW, I have tried several iterations of the address including just 0 which I will stick to now)

There is a way to turn debug on. Described in the docs. May be useful to see it that dump out the bytes sent to the device and see if that 57 even makes it.

I’ve turned on debug settings but I’m not seeing anything in the log. I assume entries wind up in the HA core log, no?

logger:
  default: warning
  logs:
    homeassistant.components.modbus: debug
    pymodbus: debug

And here is some more data.
Passing [0,75] or [0,0] changes the SV value to 0, passing [75,0] has no effect on the SV.

The issue was that I needed to write a floating point value. I changed the value to [0x4296,0x0000] (per the Modbus docs) and successfully wrote the value!

While this works, I have another issue to solve. Per the modbus docs, I have to use a “network order float hexadecimal” when I submit to modbus.write-register. That format is IEEE 754. I’ll need to convert decimal values to this format. Has anyone used a template to do so?