I’m fairly new to Python and even worse with Modbus (didn’t used it until yesterday) so don’t be to hard on me.
The usecase I got, I run openHAB with the Modbus binding, I’m able to read some addresses from my solar inverter (SolarEdge) where the documentation describes exactly which addresses to use for the different objects: [https://knowledge-center.solaredge.com/sites/kc/files/sunspec-implementation-technical-note.pdf][1]
The next step is to also control some settings on the inverter, most important one is the “Active Power Control”, this number value 0-100 is a percentage type and if you set it to 10 for example, and the max capacity is 2200watt, you throttle it to not return more then 220watt, if 0, it is shut down completely.
And that’s what I want because some times the return kWh turns negative and I’ll have to pay for it. openHAB knows when it turns negative by reading a API, now I only need to find a way to control the inverted over modbus TCP.
SolarEdge also has documentation about controlling the inverter, but in this case, they don’t use the regular address register number, but they use hexidecimal, manual here: [https://www.photovoltaikforum.com/core/attachment/88445-power-control-open-protocol-for-solaredge-inverters-pdf/][2]
So for example, I like to control address 0xF001. From what I have read, I need to convert this hex to decimal, then 0xF001 = 61441.
From this point it turns a bit tricky for me, but from what I’ve read, 6 would be the regular write register and 1441 + 1 = 1442 would be the address (correct me if I’m wrong). For this register I should use FC21 but openHAB doesn’t support this (at the moment) so I would like to do this with a python script.
I read that there is support for FC21 on pymodbus but I don’t quite understand how to use it.
The 0xF001 address would be R/W with type uint16.
Now, I saw the minimal example for modbusTCP:
from pymodbus.client import ModbusTcpClient
client = ModbusTcpClient('MyDevice.lan') # Create client object
client.connect() # connect to device, reconnect automatically
client.write_coil(1, True, slave=1) # set information in device
result = client.read_coils(2, 3, slave=1) # get information from device
print(result.bits[0]) # use information
client.close()
Please guide me in the right direction how to adjust this so I can read and write to this 0xF001 address.