n9yty / FroniusSmartMeterEmu_Pro3EM

Shelly Pro3EM Fronius Smart Meter emulation
0 stars 0 forks source link

Breaking API change in pymodbus>3.7.0 #1

Open avyeegaztd opened 1 month ago

avyeegaztd commented 1 month ago

The script will not work with pymodbus > 3.7.0. See: https://pymodbus.readthedocs.io/en/latest/source/api_changes.html#api-changes-3-7-0

To migitate this either change the Dockerfile to build to use a version lower than 3.7.0, e.g.

RUN pip3 install pymodbus==3.6.9

or change these lines.

#from pymodbus.transaction import ModbusSocketFramer, ModbusAsciiFramer
from pymodbus.transaction import FramerSocket, FramerAscii
from pymodbus.framer import FramerType

and

#        framer=ModbusSocketFramer,
        framer=FramerType.SOCKET,

and rebuild the image and run docker compose up.

I didn't want to do a do a fork and pull request for such a simple change.

It also randomly give me an error message in the docker logs. Exception response Exception Response(131, 3, IllegalAddress) But i can't figure out which register is wrong. I tried debugging it with the import logging function, but the message never appears in my debug logs.

The script still works flawless with me new GEN24 inverter. So thanks for the script!

n9yty commented 1 month ago

Thank you! I was working based on prior work, so this is a huge help as I am not really familiar with pymodbus. :)

I'll have a look and get your suggestions incorporated.

avyeegaztd commented 1 month ago

No problem. I don't really know pymodbus myself, TBF. I just went on debugging it by tryout.

Just one thing i saw in the code, too: You have a comment on line 113-115 about the correction factor. The correction factor is needed for energy data, which is in kWh. Shelly provides Wh data. This is a remainder of the MQTT code which others used from other energy meters. Most comments on german speaking forums say they need to subtract 1000, because the Fronius Inverter calculates the correct value internally with Wh.

n9yty commented 1 month ago

It is interesting in that right now it is set to 1 because I didn't know what to do. As far as I can tell, everything is working properly here with that value, the Fronius inverter's internal web page for meter configuration shows the Meter value correction, right now about 890W. In my Emporia app I see 0.890kW which lines up. Also comparing my uploaded data to PVOutput.org and the solarweb.com data are all in line. So it seems that the values returned by the Shelly Pro3EM are scaled correctly already?

It would be nice to know that the data is good. I just built on existing projects, although I tried to fill in gaps and populate as many of the modbus registers with data as the Shelly provided data for so I think this one gives more feedback whereas the others largely just had the bare minimum energy/power usage.