I am trying to write to a R32 Modbus value (Kostal Plenticore solar inverter). I’ve succeeded using the modbus.write_register service, e.g. with value: [0x0000, 0x42a0] I can write the value 80.0:
Now I am struggling to come up with a value_template that can actually take a sensor/input reading and convert that into the proper hex form. Any ideas?
Continuing my monologue: Looks like the unpack filter/function only returns the first value in a list. hence the above example returns 0. If I swap the endianness, I get the expected lower bytes:
I’ve done a small change ‘>h’ => ‘>H’.
It supports now negative values.
The unpack needs to read the packed bytes as unsigned for a native byte stream.
Jonas, thank you very much for this excellent solution! I made myself simple automation to control my wallbox (I have Compleo/Innogy eBox Professional) to use for charging only excess power from PV panels. I was able to set it only to few predefined levels as I was not able to compute this values for two words representation of float32 numbers. After few months of searching and trying I was today very close to open feature request in home assistant modbus integration to enable us writing float32 automatically, not like an array of 16bit numbers - then I found this treasure. THANK YOU again very much!
Thank you very much for this template, I have searched for a long time and here I found the solution.
I am communicating with an ESP8266 with a custom modbus rtu and I had to reverse the order of the two 16-bit registers so that it would read the float correctly.