logo elektroda
logo elektroda
X
logo elektroda

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

starob 98025 318
ADVERTISEMENT
Treść została przetłumaczona polish » english Zobacz oryginalną wersję tematu
  • #121 19651493
    starob
    Level 29  
    piotr.wloszynski wrote:
    how did you setup EW11 and how do you communicate with it in python?

    EW11 as a TCP server
    local port -502 (default)
    route - UART !!!

    Series:
    transmission parameters - 9600,8,1,N (as needed)
    protocol - Modbus
    Cli - disable

    IP - as needed, the rest by default.
    It's enough for a start.

    I haven't tried in python but I would use pyModbus as ModbusTCP.
    You have to look for examples on your own.
  • ADVERTISEMENT
  • #122 19652020
    piotr.wloszynski
    Level 11  
    thanks, it works.
  • #123 19656597
    Emi_B
    Level 9  
    starob wrote:
    Emi_B wrote:
    Can you fix the following error?

    Your answer is too short.
    It should look something like this:
    Received: b'xa5cx00x10x15x00{]h]}x02x01xfdxce.x01tjx00x00xd2xadx19`x01x03Px00 x02x00x00x00x00x00x00x00x00x00x00nIx00x8cnx10x00}x00%x00 x00?x00?x13x85 tex00}tQx00~tbx00~x00x00x19(x00x00x18x01x01xd2x01xacx00x1bx00)x19x84n
  • #124 19656756
    starob
    Level 29  
    Emi_B wrote:
    Does it matter that it's not LSW (wifi) but LSE (ethernet)?

    Doesn't matter.
    Maybe it's a network problem if it doesn't read the whole frame?
    In solarman do you get good readings?

    Added after 10 [hours] 30 [minutes]:

    @Michalux check if you have any strange readings around the inverter state transition around "Wait" to "Normal".
    For me, when production starts, I have a registered power and production peak. It wasn't there before, maybe it has to do with the season and the weather.
    You need to make extra data validation, which neither you nor I have.
    The case is difficult because it is one shot and it is difficult to capture and it spoils the statistics.
  • #125 19657797
    Emi_B
    Level 9  
    starob wrote:
    Emi_B wrote:
    Does it matter that it's not LSW (wifi) but LSE (ethernet)?

    Doesn't matter.
    Maybe it's a network problem if it doesn't read the whole frame?
    In solarman do you get good readings?


    The problem with the network (range) would be on LSW, because the installation is far from the building. Hence the change to a twisted-pair version of the logger.
    So no, there are no network problems:

    11 packets transmitted, 11 packets received, 0.0% packet loss
    round-trip min/avg/max/stddev = 2.362/3.044/4.197/0.499ms

    In solarman all readings are OK:
    Sofar Solar KTL-X Inverter: RS485 MODBUS Integration with Domoticz - Setup & Tips [90]
    And yet it shows an error:
    Code: Bash
    Log in, to see the code
  • #126 19670339
    mariopoz
    Level 11  
    Good morning
    For a few days I am also a happy owner of Sofara (and panels on the roof) and I wanted to integrate it with my "smart" house built on a raspberry tree with Domoticz. I have an MQTT server installed there, but this script (from my friend Michalux) has some problems connecting to the MQTT server.

    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]
    .

    Have you managed to solve this problem?
    I have a similar message. Sofar Solar KTL-X Inverter: RS485 MODBUS Integration with Domoticz - Setup & Tips [90]
  • #127 19673845
    mariopoz
    Level 11  
    Michalux wrote:
    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 :)


    Hey! I’ve got a question.
    How did you solve the "problem" of calling the InverterData.py script?
    So far I managed to run it via crontab, but there I can usually set it every 1 minute.
    I still have a problem with a plugin in Grafana, I can't find one like you used timeseries anywhere.
  • ADVERTISEMENT
  • Helpful post
    #128 19678140
    Michalux
    Level 10  
    starob wrote:
    @Michalux check if you have any strange readings around the inverter state transition around "Wait" to "Normal".
    For me, when production starts, I have a registered power and production peak. It wasn't there before, maybe it has to do with the season and the weather.
    You need to make extra data validation, which neither you nor I have.
    The case is difficult because it is one shot and it is difficult to capture and it spoils the statistics.

    In general, it is not a peak of power and production, but before the inverter goes into the Normal state, it briefly returns the last value from the previous day. In one of the last versions I added a protection not to send data to InfluxDB/Prometheus/MQTT when the status of the inverter is different than Normal (variable invstatus).
    Data in JSON format is dumped on the console at each status (e.g. to see errors in case of emergency).
    I also added a new script that reads all data regarding serial numbers, versions, etc/etc :) (unfortunately, embracing it with the same script would require a lot of modifications, because the command no. 4 works a bit differently than no. 3).
    I also introduced all the error statuses from the documentation so that the codes would be converted to names nicely.

    Added after 7 [minutes]:

    mariopoz wrote:
    Hey! I've got a question.
    How did you solve the "problem" of calling the InverterData.py script?
    So far I managed to run it via crontab, but there I can usually set it every 1 minute.
    I still have a problem with a plugin in Grafana, I can't find one like you used timeseries anywhere.

    I'm on crontab. I don't really need to read more than once a minute.
    But I don't see a problem to write a simple shell script that runs InverterData.py in an interval of min 1s (I don't recommend it, because the logger inverter may not work), e.g.
    while true; do
    python3 InverterData.py
    sleep 1
    done
    You run the script in the background (./skrypt.sh &) and you're done. It can also be thrown into the crontab, so that it runs, for example, once every 10 minutes (then the loop must be limited so that it does not last > 10 minutes). This is in case the script dies/was killed (e.g. due to OS restart).

    As for Grafana, it's a plugin available with Grafana (standard installation - I didn't add anything).
    Maybe you have too old version of Grafana? I'm on 8.2.1 at the moment.

    Added after 10 [minutes]:

    mariopoz wrote:
    Have you managed to solve this problem?
    I have a similar message.

    I don't use MQTT, so I didn't mess with the original code and didn't check it.
    However, look in the forks of my project on GitHub - in one of them someone corrected this piece of code.

    Added after 13 [minutes]:

    By the way (while I'm already producing :) ), then I found yet another version of the Sofar/MODBUS documentation. The ranges of registers for reading production data are not suitable for my inverter, but it is greatly extended in relation to the documentation that I found on the forum (but registers containing SN, versions, etc. are OK). It shows that it is also possible to manage the inverter in a similar way, including switching on/off, changing the configuration, etc. (generally writing support, not only reading).
    I am attaching the document for those interested.
  • #129 19678185
    Michalux
    Level 10  
    Emi_B wrote:
    starob wrote:
    Emi_B wrote:
    Does it matter that it's not LSW (wifi) but LSE (ethernet)?

    Doesn't matter.
    Maybe it's a network problem if it doesn't read the whole frame?
    In solarman do you get good readings?


    The problem with the network (range) would be on LSW, because the installation is far from the building. Hence the change to a twisted-pair version of the logger.
    So no, there are no network problems:

    11 packets transmitted, 11 packets received, 0.0% packet loss
    round-trip min/avg/max/stddev = 2.362/3.044/4.197/0.499ms

    In solarman all readings are OK:
    Sofar Solar KTL-X Inverter: RS485 MODBUS Integration with Domoticz - Setup & Tips [90]
    And yet it shows an error:
    Code: Bash
    Log in, to see the code

    This is generally the most common effect of incorrect register numbers that we are trying to read.
    Try to change them based on, for example, the documentation I attached today (if you don't know how, write to priv).
    To do this, you need to change the numbers in SOFARMap.xml and modify the pini and pfin variables in the script (to the range of registers - after conversion from hex to dec) (initially, just change pini/pfin to see if the response from the logger/inverter is extended or not).
  • ADVERTISEMENT
  • #130 19679772
    Michalux
    Level 10  
    I released a new version of the software: 1.4 :)
    Added the ability to define a range of registers at the level of the configuration file (you no longer need to mess with the script to experiment with the range of registers).
    The script will also throw an appropriate message if the values in the response from the logger are empty (usually the effect of an incorrect range of registers).
  • #131 19679913
    starob
    Level 29  
    Michalux wrote:
    Added the ability to define the range of registers at the level of the configuration file

    You can only read two register banks anyway, so in my opinion it's better to read all possible ones anyway.
    Due to the transmission overhead, it is more profitable to read everything than in bits and pieces.
    I would add the "parse" flag in the XML for the registry and return only values marked this way.
  • #132 19679988
    Michalux
    Level 10  
    starob wrote:
    Michalux wrote:
    Added the ability to define the range of registers at the level of the configuration file

    You can only read two register banks anyway, so in my opinion it's better to read all possible ones anyway.
    Due to the transmission overhead, it is more profitable to read everything than in bits and pieces.
    I would add the "parse" flag in the XML for the registry and return only values marked this way.

    After all, you can't specify a range, e.g. 0x0000-0xFFFF and wait what the inverter will spit out, because it won't spit anything out. These parameters are so that you can freely define the range of their addresses within these two banks - different inverters have these data under different ranges. So if the addresses I gave someone do not return the required data, they can easily mess with others, without interfering with the main script.
    And as for reading everything at once, it's not like that in every case, because from what I've read, some inverters have a problem with throwing all the data at once. That's why it was split up in the original script. There, de facto, it was even done so that the given range of addresses was divided into even more subsets.
  • #133 19686651
    Michalux
    Level 10  
    If anyone is interested, I uploaded a new version 1.5 on github (https://github.com/MichaluxPL/Sofar_LSW3/releases/tag/1.5)
    Since a lot of people asked about it, I sat down to MQTT - it was reworked, added TLS support and tested with the Mosquitto server :)
  • #134 19690083
    GrzegorzSzkiela
    Level 6  
    Hello,

    I just wanted to ask if it could somehow be integrated with Home Assistant? I don't have the skills to do that, but it would be nice.

    Regards.
  • #135 19690128
    Michalux
    Level 10  
    Look for my project in the forks - in which someone added integration with Home Assistant.
  • #136 19690135
    starob
    Level 29  
    GrzegorzSzkiela wrote:
    I just wanted to ask if it could somehow be integrated with Home Assistant? I don't have the skills to do that, but it would be nice.
    Michalux wrote:
    Since a lot of people asked about it, I sat down to MQTT - it was reworked, added TLS support and tested with the Mosquitto server


    You add to HA as MQTT sensors .. that's all the integration.
  • #137 19690158
    GrzegorzSzkiela
    Level 6  
    starob wrote:
    You add to HA as MQTT sensors .. that's all the integration.


    Well, my knowledge is really minimal, but I will look and try. So far, I've used Node-RED from this topic and I see that it peaks my data and sends it to MQTT. Now I need to figure out how to make this sensor.

    Thanks.
  • #138 19690212
    starob
    Level 29  
    GrzegorzSzkiela wrote:
    Now I need to figure out how to make this sensor.

    You edit configuration.yaml and in the sensor: section you add
    
    ####################sofar-solar###############
      - platform: mqtt
        state_topic: "Sofar/DayEnergy"
        name: "Pordukcja dzienna"
        unit_of_measurement: 'kWh'
        device_class: energy
        icon: mdi:counter
    
      - platform: mqtt
        state_topic: "Sofar/TotalEnergy"
        name: "Pordukcja total"
        unit_of_measurement: 'kWh'
        device_class: energy
        icon: mdi:counter
    
      - platform: mqtt
        state_topic: "Sofar/Power_P"
        name: "Moc inw."
        unit_of_measurement: 'Watt'
        device_class: power
    #    icon: mdi:counter
    
    
      - platform: mqtt
        state_topic: "Sofar/V1"
        name: "Napięcie PV1"
        unit_of_measurement: 'V'
        device_class: voltage
    #    icon: mdi:counter
    


    .. etc, customizing state_topic: for your needs
  • #139 19690614
    GrzegorzSzkiela
    Level 6  
    starob wrote:
    You edit configuration.yaml and in the sensor: section you add


    Great, thanks a lot, now I can see everything in HA!
    Now I'm wondering if and how this can be used with the Energy module in HA?. These sensors are not visible for selection there.
  • #141 19690768
    r65
    Level 15  
    Try with the state_class: measurement or state_class: total_increasing sensor attributes in the sensor itself or customization.
    I think the energy module needs it.
  • #142 19755462
    krawietz
    Level 16  
    Quote:

    By the way (while I'm already producing :) ), then I found yet another version of the Sofar/MODBUS documentation. The ranges of registers for reading production data are not suitable for my inverter, but it is greatly extended in relation to the documentation I found on the forum (but registers containing SN, versions, etc. are OK). It shows that it is also possible to manage the inverter in a similar way, including switching on/off, changing the configuration, etc. (generally writing support, not only reading).
    I am attaching the document for those interested.


    As the installation on the Sofar 8.8LTL-X has just started for me, I started "digging" in it to get as much useful information as possible directly from the inverter, and basically from the logger via WiFi.
    At first glance, it seems that the registers described in this version of the documentation do not match the version of the inverter/logger that I have.
    While some of the basic data is the same, the registers marked as "Inverter inner message" are completely different.
    The previous version from this thread (Word) mostly fits, but for example, the 0x001F register does not show the current on the PV1 string measured by the "slave CPU" only the voltage of the PV2 string measured by this processor. The PDF version at this address has the temperature of the inverter.

    It looks as if the version from Word was for inverters with 1 string (DC input) and the one from PDF with 2 strings but 3 DC inputs (because there are registers described there that refer to PV3)

    The question remains, has anyone seen any other versions of the documentation anywhere?

    In addition, it seems to me that the logger itself has at least two bugs in the software.
    I am unable to turn off the built-in AP - despite selecting it in the "wizard" from the configuration, it still advertises its WiFi network.
    The second error is the way of presenting the daily production. With small production values of 0.01 to 0.09, the logger on the website shows 0.1 to 0.9. Then, when it actually jumps above 0.1 kWh per day, it already shows well.

    Krawietz
  • #143 19759599
    Michalux
    Level 10  
    krawietz wrote:
    In addition, it seems to me that the logger itself has at least two bugs in the software.

    Regarding the AP bug, I will not say, because I have not checked, but the issue of incorrect reporting of the 0.01-0.09Wh value is most likely to occur (only in the logger GUI - the inverter itself reports correctly, also via logger). I even wrote to the manufacturer about this :) They asked for the logger's SN and ... didn't hear back :P
  • #144 19775360
    kofec
    Level 11  
    First of all, many thanks for the script and the corrections made to the original.
    I took the liberty of doing a "fork" - https://github.com/kofec/Sofar_LSW3
    because I wanted it to work on OpenWrt (NetGear R6220) and add additional reporting to PVOutput (https://pvoutput.org/)
    For example: https://pvoutput.org/list.jsp?id=99666&sid=87759

    And I have a question. It seems that the inverter is powered by panels or has some "safe / idle mode"? You can't get to it if it's not producing.
    Do you have that too? Is this an option that can be turned off somehow?
    Thanks
  • ADVERTISEMENT
  • #145 19775383
    Michalux
    Level 10  
    kofec wrote:
    And I have a question. It seems that the inverter is powered by panels or has some "safe / idle mode"? You can't get to it if it's not producing.
    Do you have that too? Is this an option that can be turned off somehow?
    Thanks

    This is normal - the inverter will turn off after some time when the panels are not producing.
  • #146 19797689
    GP007
    Level 8  
    Hello,

    The script works fine for me, it reads the parameters, but I have a problem with the integration with Domoticz. It seems that mosquitto only accepts the first parameter sent by the script (no matter what it is) and then nothing from the following lines.

    According to the record from mosquitto.log, it looks like this:

    1641201602: New connection from 192.168.1.16 on port 1883.
    1641201602: New client connected from 192.168.1.16 as inverter (p2, c1, k60, u'mosquitto2').
    1641201602: No will message specified.
    1641201602: Sending CONNACK to inverter (0, 0)
    1641201602: Received PUBLISH from inverter (d0, q0, r0, m0, 'domoticz/in', ... (32 bytes))
    1641201602: Sending PUBLISH to Domoticz608855fa-954b-41f7-a6ac-7b0852822cf1 (d0, q0, r0, m0, 'domoticz/in', ... (32 bytes))
    1641201602: Socket error on client inverter, disconnecting.

    Other things on this mosquitto/domoticz type sonoff on tasmota work fine...
  • #147 19801042
    GP007
    Level 8  
    Answering myself, it helped to put time.wait(1) in the script at the client connection and after each client.publish in the loop. Probably temporarily my mosquitto did not knead. Now domoticz gets all the data.
  • #148 19807527
    sq7krj
    Level 2  
    GP007 could you please share your solution? Unfortunately I have the same problem with my Mosquitto. And from programming I have a total leg.
  • #150 19807692
    sq7krj
    Level 2  
    Revelation :) . Finally all data in Domoticz. Thank you very much.

Topic summary

The discussion revolves around integrating the Sofar Solar KTL-X inverter with Domoticz via RS485 Modbus, addressing issues related to communication, configuration, and data retrieval. Users share experiences with various setups, including the use of Ethernet-to-RS485 converters and the LSW-3 logger. Key points include the need for correct transmission parameters (9600 baud, 8 data bits, no parity, 1 stop bit), the importance of proper wiring, and the challenges faced when using different firmware versions. Participants also discuss the mapping of Modbus registers for accurate data reading and the potential for using Node-RED for automation. Solutions for common problems, such as timeouts and data retrieval errors, are provided, along with suggestions for configuring Home Assistant for monitoring.
Summary generated by the language model.
ADVERTISEMENT