logo elektroda
logo elektroda
X
logo elektroda

Sofar Solar KTL-X Inverter: RS485 MODBUS Integration with Domoticz - Setup & Tips [90]

starob 100533 318
ADVERTISEMENT
Treść została przetłumaczona polish » english Zobacz oryginalną wersję tematu
  • #91 19617624
    starob
    Level 29  
    Michalux wrote:
    you can easily adapt its solution to almost every inverter that communicates with the world via LSW-3

    I'll check myself, but I'm afraid not.
    Col. you just got lucky that your S/N is 17xxxxxxx and is in V4. You can check it?
    I have S/N 21xxxxxx and Fw: ME_08_2701_2.05
    starob wrote:
    Finally someone figured out the V5 protocol!

    I guess I got excited too early, but thanks anyway for being active.
  • ADVERTISEMENT
  • #92 19617665
    zygzak
    Level 12  
    Michalux wrote:
    No trick with DNS :)
    The solution polls the inverter directly via the LSW-3.
    Tested on LSW-3 version: LSW3_15_FFFF_1.0.57
    Sofcik is written in python3 for linux (tested on raspberry), download here: https://github.com/MichaluxPL/Sofar_LSW3


    It also works under windows :lol:
    There is only a tiny problem with Polish characters:
    Quote:
    0x0000 - Status: "Normal"
    0x0001 - Error code 1: 0
    0x0002 - Error code 2: 0
    0x0003 - Error code 3: 0
    0x0004 - Error code 4: 0
    0x0005 - Error code 5: 0
    0x0006 - PV1 voltage: 472.8V
    0x0007 - PV1 current: 1.74A
    0x0008 - PV2 voltage: 80.8V
    0x0009 - PV2 current: 0.0A
  • ADVERTISEMENT
  • #93 19617678
    Michalux
    Level 10  
    starob wrote:
    Michalux wrote:
    you can easily adapt its solution to almost every inverter that communicates with the world via LSW-3

    I'll check myself, but I'm afraid not.
    Col. you just got lucky that your S/N is 17xxxxxxx and is in V4. You can check it?
    I have S/N 21xxxxxx and Fw: ME_08_2701_2.05
    starob wrote:
    Finally someone figured out the V5 protocol!

    I guess I got excited too early, but thanks anyway for being active.


    Yes, my LSW-3 is S/N 17xxxxxx, while reading several materials on the net, I conclude that it works in the V5 protocol, not V4.

    Added after 3 [minutes]:

    Quote:

    It also works under windows :lol:
    There is only a tiny problem with Polish characters:
    0x0000 - Status: "Normal"
    0x0001 - Error code 1: 0
    0x0002 - Error code 2: 0
    0x0003 - Error code 3: 0
    0x0004 - Error code 4: 0
    0x0005 - Error code 5: 0
    0x0006 - PV1 voltage: 472.8V
    0x0007 - PV1 current: 1.74A
    0x0008 - PV2 voltage: 80.8V
    0x0009 - PV2 current: 0.0A

    It is probably enough to edit the .xml file and change the Polish names under the elevator so that the fonts are correct.
    If that doesn't help, I'd suggest playing around with the last line of code:
    print(json.dumps(jsonoutput, indent=4, sort_keys=False, ensure_ascii=False))

    specifically with the ensure_ascii=False option
  • #94 19617852
    starob
    Level 29  
    Michalux wrote:
    It also works under windows

    Doesn't work :)
    I added under parse response - print(data) and it answered me.
    I don't know what, but not enough? Sofar Solar KTL-X Inverter: RS485 MODBUS Integration with Domoticz - Setup & Tips [90]
  • #95 19617857
    zygzak
    Level 12  
    starob wrote:
    Michalux wrote:
    It also works under windows

    Doesn't work :)
    I added under parse response - print(data) and it answered me.
    I don't know what, but not enough? Sofar Solar KTL-X Inverter: RS485 MODBUS Integration with Domoticz - Setup & Tips [90]


    Add .\ before the name of the script file
    The second error is related to Polish characters, find the text ERROR in the XML file and remove the Polish characters.
  • ADVERTISEMENT
  • Helpful post
    #96 19617869
    Michalux
    Level 10  
    starob wrote:
    Michalux wrote:
    It also works under windows

    Doesn't work :)
    I added under parse response - print(data) and it answered me.
    I don't know what, but not enough? Sofar Solar KTL-X Inverter: RS485 MODBUS Integration with Domoticz - Setup & Tips [90]

    Typing print(data) rather did not make sense at all, because the data variable contains a binary response from the inverter ;)
    I haven't tested it on windows, but as I can see from the posts above, it probably works (with the accuracy of Polish letters) - you can always set lang=EN in the config and after the problem :)
    However, judging by the amount of data in the data variable, you're probably not getting the required data.
    So either the script doesn't get along with your module or your inverter has different register addresses.
  • Helpful post
    #97 19617898
    zygzak
    Level 12  
    Michalux wrote:
    starob wrote:
    Michalux wrote:
    It also works under Windows

    Doesn't work :)
    I added under parse response - print(data) and it answered me.
    I don't know what, but not enough? Sofar Solar KTL-X Inverter: RS485 MODBUS Integration with Domoticz - Setup & Tips [90]

    Typing print(data) rather did not make sense at all, because the data variable contains a binary response from the inverter ;)
    I haven't tested it on Windows, but as I can see from the posts above, it probably works (with the accuracy of Polish letters) - you can always set lang=EN in the config and after the problem :)
    However, judging by the amount of data in the data variable, you're probably not getting the required data.
    So either the script doesn't get along with your module or your inverter has different register addresses.


    It's ok. In Notepad it was enough to set the encoding to windows-1250 and edit:
    Sofar Solar KTL-X Inverter: RS485 MODBUS Integration with Domoticz - Setup & Tips [90]
  • #98 19617928
    starob
    Level 29  
    Apart from the problem with MQTT, this worked (not a problem at the moment):
    Sofar Solar KTL-X Inverter: RS485 MODBUS Integration with Domoticz - Setup & Tips [90]
    Michalux wrote:
    Generally, having a list of MODBUS registers for a given inverter, you can easily adapt its solution to probably every inverter,

    Do you have a list of what is in these frames (send/response) and how can you change the range of read registers?
    As I wrote earlier - I want to do it in Node-Red and it would be easier for me than analyzing python code.
    Thanks for contributing to the topic. :spoko:

    Added after 6 [minutes]:

    Michalux wrote:
    Typing print(data) didn't make much sense at all

    .. maybe anyway - I just re-rendered Toje #print("Received: ", data) just to check if it matches anything at all.
    He works remotely on a not fully prepared machine. I did something quickly because I was impatient to get home :)
  • #99 19617954
    Michalux
    Level 10  
    starob wrote:
    Apart from the problem with MQTT, this worked (not a problem at the moment):
    Sofar Solar KTL-X Inverter: RS485 MODBUS Integration with Domoticz - Setup & Tips [90]
    Michalux wrote:
    Generally, having a list of MODBUS registers for a given inverter, you can easily adapt its solution to probably every inverter,

    Do you have a list of what is in these frames (send/response) and how can you change the range of read registers?
    As I wrote earlier - I want to do it in Node-Red and it would be easier for me than analyzing python code.
    Thanks for contributing to the topic. :spoko:

    Added after 6 [minutes]:

    Michalux wrote:
    Typing print(data) didn't make much sense at all

    .. maybe anyway - I just re-rendered Toje #print("Received: ", data) just to check if it matches anything at all.
    He works remotely on a not fully prepared machine. I did something quickly because I was impatient to get home :)

    What is in "send" is generally very nice to see at the beginning of the code - I don't have a dedicated schedule.
    As for the response, in general, apart from the communication frame, there are register numbers with values - you have this data in the .xml file.
    I don't have any experience with Node-Red (I don't know the software), so tell me exactly what you need, I can help. help.
    And to be honest, I haven't tested MQTT so far, so I don't even know if it works properly :)
  • #100 19618027
    starob
    Level 29  
    @Michalux Thanks, I saved both frames to the file and things are slowly coming together for me.
    Maybe the need for an additional RS485 converter is finally over. It was known that there was a modbus in LSW, but it was not known how to get to it. I have a module via the eth cable (programmatically the same).
  • #101 19620438
    starob
    Level 29  
    @Michalux Looks like you have a miscalculation

    if hexpos=='0x0015': totalpower+=response*ratio;
    if hexpos=='0x0016': totalpower+=response*ratio
    Should:
    if hexpos=='0x0015': totalpower+=response*ratio*65535;
    if hexpos=='0x0016': totalpower+=response*ratio

    0x0015 is Hi totalpower - until =0 the results are correct
    0x0016 is Lo totalpower

    Similarly, addresses 0017,0018 for time

    Dress it up in python and fix it
    Sofar Solar KTL-X Inverter: RS485 MODBUS Integration with Domoticz - Setup & Tips [90]
  • #102 19620676
    Michalux
    Level 10  
    Yes I know about it :)
    I even wrote it in the notes on GitHub.
    It will be corrected in the next version. For now, I'm working on exporting data in Prometheus format ;)
  • #103 19621250
    starob
    Level 29  
    The first version for testing data reading from the Sofar inverter - directly via the network.
    Import sofar.json to Node-Red.
    A subflow will be created - "Sofar inverter", which contains functions that return copies of the inverter registers, in the order and format compliant with the modbus specification.
    Sofar Solar KTL-X Inverter: RS485 MODBUS Integration with Domoticz - Setup & Tips [90]
    In the properties, complete the inverter's IP, logger serial number and the range of the block of modbus registers for reading.
    Sofar Solar KTL-X Inverter: RS485 MODBUS Integration with Domoticz - Setup & Tips [90]
    The output buffer should alternately match node-red-contrib-modbus - if someone has used it before.
    Attachments:
  • #104 19623468
    Michalux
    Level 10  
    New version 1.1 has been released on github.
    Added support for Prometheus Grafana, verbose mode and fixed bug with 4-byte total (power/time) calculation.
    This is what it looks like in the end:
    Sofar Solar KTL-X Inverter: RS485 MODBUS Integration with Domoticz - Setup & Tips [90]
    enjoy :)
  • #105 19623641
    starob
    Level 29  
    I advised you wrong - not *65535, but 65536.
    Best check it out :)
  • #106 19623674
    Michalux
    Level 10  
    starob wrote:
    I advised you wrong - not *65535, but 65536.
    Best check it out :)

    Well, definitely 65536 ;)
    I don't know why I typed it 65535 :?:
    Fixed.
  • #108 19627233
    FrankAB
    Level 20  
    starob wrote:
    ...Read data from the Sofar inverter - directly via the network...
    Works with S/N 17xxxxxxxx.
  • ADVERTISEMENT
  • #109 19627781
    starob
    Level 29  
    Thanks @FrankAB, I was hoping for more testers. All in all, it works for me and that should be enough for me ;)
    Maybe I should move the topic to "Home Automation"?
  • #110 19630012
    iborkim
    Level 12  
    starob wrote:
    Extended Node-Red version from the previous post
    Data reading from the Sofar inverter - directly via the network.
    I added parsing to MQTT.


    Works with S/N 05xxxxxxxx

    Sofar Solar KTL-X Inverter: RS485 MODBUS Integration with Domoticz - Setup & Tips [90] .
  • #111 19637909
    pirzol
    Level 12  
    Hello

    I have Inverter Deye SUN-3.2K-G03, with LSW3 logger
    Device serial number 175xxxxxxx
    Firmware version LSW3_15_FFFF_1.0.65

    The same logger is used by Sofar, unfortunately the registers are probably different.

    I ran the script under python 3.9.7 on windows, it gets responses as below:

    ======================= RESTART: C:DeyeInverterData.py ================= ======
    Chunk no: 0
    Sent data: bytearray(b'xa5x17x00x10Ex00x00xa6x8exdewx02x00x00x00x00x00x00x00x00x00x00x00 x00x00x00x01x03x00x00x00(Exd4x00x15')
    Received data: b'xa5x10x00x10x15x00IxdcrZhx02x01sxddnx00x8bx1fx00x00x14xa2Nax06x00x9b x15'
    Traceback (most recent call last):
    File "C:DeyeInverterData.py", line 156, in
    parameters=json.loads(txtfile.read())
    File "C:UsersxntyAppDataLocalProgramsPythonPython39libencodingscp1250.py", line 23, in decode
    return codecs.charmap_decode(input,self.errors,decoding_table)[0]
    UnicodeDecodeError: 'charmap' codec can't decode byte 0x81 in position 7950: character maps to



    Regards
    P
  • #112 19637976
    starob
    Level 29  
    zygzak wrote:
    Michalux wrote:
    starob wrote:
    Michalux wrote:
    It also works under windows

    Doesn't work :)
    I added under parse response - print(data) and it answered me.
    I don't know what, but not enough? Sofar Solar KTL-X Inverter: RS485 MODBUS Integration with Domoticz - Setup & Tips [90]

    Typing print(data) rather did not make sense at all, because the data variable contains a binary response from the inverter ;)
    I haven't tested it on windows, but as I can see from the posts above, it probably works (with the accuracy of Polish letters) - you can always set lang=EN in the config and after the problem :)
    However, judging by the amount of data in the data variable, you're probably not getting the required data.
    So either the script doesn't get along with your module or your inverter has different register addresses.


    It's ok. In notepad++ it was enough to set the encoding to windows-1250 and edit:
    Sofar Solar KTL-X Inverter: RS485 MODBUS Integration with Domoticz - Setup & Tips [90]


    You received the data, because of the different inverter you would have some stupid results ... but you did.
    Remove Polish characters
  • #113 19638869
    Michalux
    Level 10  
    pirzol wrote:
    I have Inverter Deye SUN-3.2K-G03, with LSW3 logger
    Device serial number 175xxxxxxx
    Firmware version LSW3_15_FFFF_1.0.65

    There are other register addresses for Deye. I recommend taking a look at this project: https://github.com/jlopez77/DeyeInverter.
    You can get the address from it :)
    In addition to addressing, you also need to change the values of the pini and pfin variables (everything to read from the above).
    Or just use the script from the project above and it should work.
  • #114 19640465
    pirzol
    Level 12  
    Michalux wrote:
    pirzol wrote:
    I have Inverter Deye SUN-3.2K-G03, with LSW3 logger
    Device serial number 175xxxxxxx
    Firmware version LSW3_15_FFFF_1.0.65

    There are other register addresses for Deye. I recommend taking a look at this project: https://github.com/jlopez77/DeyeInverter.
    You can get the address from it :)
    In addition to addressing, you also need to change the values of the pini and pfin variables (everything to read from the above).
    Or just use the script from the project above and it should work.


    Thanks for the hint, I used a temporary solution. I have inserted the bemko BM030-L meter and sent the measurements to pvmonitor.pl

    Regards
    P
  • #115 19640589
    Emi_B
    Level 9  
    Michalux wrote:
    Fixed.


    Can you fix the following error?

    Code: Bash
    Log in, to see the code
  • #116 19640967
    starob
    Level 29  
    Emi_B wrote:
    Can you fix the following error?

    Your answer is too short.
    It should look something like this:
    Received: b'\xa5c\x00\x10\x15\x00{]h]}\x02\x01\xfd\xce.\x01\tj\x00\x00\xd2\xad\x19`\x01\x03P\x00\ x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\nI\x00\x8c\n\x10\x00}\x00%\x00 \x00?\x00?\x13\x85\ te\x00}\tQ\x00~\tb\x00~\x00\x00\x19(\x00\x00\x18\x01\x01\xd2\x01\xac\x00\x1b\x00)\x19\x84\n
  • #117 19641407
    Michalux
    Level 10  
    An error in the twosComplement_hex function generally means what starob wrote.
    The function simply gets empty strings that it is unable to convert.
    Either something is wrong in the configuration (e.g. the mentioned SN number of the logger), or the inverter has different register addresses.
  • #118 19647534
    rakmo
    Level 13  
    starob wrote:
    Extended Node-Red version from the previous post
    Data reading from the Sofar inverter - directly via the network.
    I added parsing to MQTT.


    Will this work with other sofara inverters
    I have ktml g2 and 2700tl g3?
  • #119 19647570
    starob
    Level 29  
    If you send me modbus specs for your model, I will answer with certainty.
    I found two documents for Sofar inverters that are different. You have a 50% chance :)
    All I can say is - try and confirm.
  • #120 19651394
    piotr.wloszynski
    Level 11  
    starob wrote:

    I have an inverter and an additional two-way counter SDM630 connected to the modbusWifi Elfin EW11 converter.

    Hello
    how did you set up EW11 and how do you communicate with it in python?

Topic summary

The discussion focuses on integrating the Sofar Solar KTL-X inverter with Domoticz via RS485 Modbus communication due to instability issues with the WiFi logger. Key technical details include the RS485 connection using RJ45 connectors with pins 2,3,4 shorted as A+ and pins 1,5,6 shorted as B-, and a communication speed of 9600 baud, 8 data bits, no parity, 1 stop bit (9600/8/N/1). Users shared experiences reversing RS485 wires to establish connection and scanning registers with various tools. The Sofar inverter’s Modbus register map is partially undocumented and varies by firmware and model, complicating integration. Solutions involve using ESP-based loggers (e.g., sofarsolar_esp_rs485_logger) that send data via MQTT to Domoticz or Node-RED, with some users developing Python plugins and Node-RED subflows for data parsing and visualization. Additional hardware like SDM72D-M or MEW-01 meters are used for accurate energy measurement and self-consumption calculation. Some users employ LAN controllers (e.g., TinyControl LK3.8) to aggregate Modbus data and forward via MQTT or HTTP. Challenges include handling different firmware versions (V4, V5 protocols), register addressing differences, and reading real-time inverter clock data, which appears unavailable. The community also discusses integrating other devices like Tauron meters and heat pumps, using MQTT brokers (e.g., Mosquitto), and visualization tools like Grafana and InfluxDB. The overall approach emphasizes custom, local data acquisition and processing to overcome limitations of official cloud services and proprietary protocols.
Summary generated by the language model.
ADVERTISEMENT