logo elektroda
logo elektroda
X
logo elektroda

PV InverterBroker, a Linux-based programme for communicating with Sofar's KTL and KTL-X family of in

michal.zd 1683 56
Best answers

Why does the Sofar inverter’s ActivePowerOutputTotal register sometimes show values like 65531 instead of a small power value, and why isn’t it the sum of the three phase powers?

On HYD inverters, ActivePower_Output_Total is a signed 16-bit register, so values like 65531 must be interpreted as negative two’s-complement numbers; 65531 is 0xFFFB, i.e. -5 decawatts, or about -50 W [#21408458][#21408717] This signed behavior applies to HYD 5...20K-3PH and HYD3...6K-EP models; for on-grid inverters the value is unsigned [#21408458] The register does not represent the sum of the three phase currents/powers; the later testing showed it matches the inverter’s AC output/production power, while the household consumption is a separate value [#21408773][#21409303] In the night-time data, the phase U×I calculation matched the inverter’s reported total consumption, which helped confirm that the “missing” power was consumption rather than PV output [#21408773][#21409342] The thread also identified other possible registers for load/consumption, such as ActivePower_Load_Total and ActivePower_Load_Sys, for cases where you need the house consumption value explicitly [#21409803]
Generated by the language model.
ADVERTISEMENT
Treść została przetłumaczona polish » english Zobacz oryginalną wersję tematu
  • #31 21420447
    Daro1003
    Level 34  
    Posts: 2711
    Help: 295
    Rate: 604
    It looks like this:

    Screenshot showing terminal output of an inverter with information on voltage, state, and time. .

    Time, tensions
  • ADVERTISEMENT
  • #32 21420450
    michal.zd
    Level 31  
    Posts: 1646
    Help: 83
    Rate: 271
    Aa after removing this slash in the config file you still have to stop and start the broker again.
    It still has two // so....

    Added after 1 [minute]: .

    You can already basically run the broker without the --d parameter, it will then not provide information on the screen.
  • ADVERTISEMENT
  • #33 21420459
    Daro1003
    Level 34  
    Posts: 2711
    Help: 295
    Rate: 604
    in screen ctrl and c
    and I fired back

    after which :

    Screenshot of a terminal with MQTT subscription results containing inverter data. .

    in NodeRed no change.
  • #34 21420465
    michal.zd
    Level 31  
    Posts: 1646
    Help: 83
    Rate: 271
    😄 space removed from there too. See the inf from mosquitto, there can be no spaces in the topic
    Between the word inverter and /state and /json
    Simply in the etc/ime file you have an unnecessary space after the topic name.
    I have not immunized the program against this.
  • #35 21420478
    Daro1003
    Level 34  
    Posts: 2711
    Help: 295
    Rate: 604
    That's what I thought I saw that there was a space between the / / I removed one it looks like this:

    Screenshot of a terminal displaying JSON messages from an inverter.

    But in the node still nothing:

    Data flow diagram in Node-RED with MQTT and debug nodes. .
  • #36 21420505
    michal.zd
    Level 31  
    Posts: 1646
    Help: 83
    Rate: 271
    Deploy you have to press. The red button and the dots above the node indicate that you have not saved this flow to the server. Press the red Deploy button.
  • #37 21420512
    Daro1003
    Level 34  
    Posts: 2711
    Help: 295
    Rate: 604
    I still did a reboot of RBPi in the meantime and restarted but it did nothing.

    As you wrote deploy and it flies:

    View of Node-RED tool with connected blocks MQTT Inverter and debug 1, and a debug panel on the right. .
  • ADVERTISEMENT
  • #38 21420528
    michal.zd
    Level 31  
    Posts: 1646
    Help: 83
    Rate: 271
    Well, at last 😉 .
    I'll apply a few corrections to the program tomorrow, including that minus sign instead of the 65tys value.
    I couldn't do it in the evening because my inverter isn't working at the time.
  • ADVERTISEMENT
  • Helpful post
    #39 21420551
    Daro1003
    Level 34  
    Posts: 2711
    Help: 295
    Rate: 604
    I don't know if you've noticed, but the G parameter also blows some number out of the water when there's not too much production as you can see in the screenshots today.
  • #40 21420604
    michal.zd
    Level 31  
    Posts: 1646
    Help: 83
    Rate: 271
    Because Grid also has negative values when it draws from the grid.

    Added after 2 [minutes]:

    Anyway, in the uploaded data from the broker, I specifically left the raw data from the inverter to see exactly what is there. Now after your tests you can give plus/minus accordingly.
    The data for mosquitto also had such high values, I will correct all of this tomorrow and give it for testing.
    On the minus it goes down in the evening, when there is already a lack of energy from the pv, also you can do the test right then.
  • #41 21453475
    michal.zd
    Level 31  
    Posts: 1646
    Help: 83
    Rate: 271
    The next version of the programme got the possibility to send mqtt messages immediately in a format understood by domoticz.
    Also, there is no need for a node-red intermediary.
  • #42 21453527
    Daro1003
    Level 34  
    Posts: 2711
    Help: 295
    Rate: 604
    I am already using.

    Integrating the Sofar inverter into Domoticz is actually now a few steps.
    1. we copy the corresponding three files from @michal.zd to the raspberry.
    2. we assign permissions to the file.
    3) We fill in the IP and SN details of Sofar's wi-fi module and IDXs in Domoticz.
    4. run the program ./inverterbroker -d

    The data flies in Domoticz.
  • #43 21453569
    michal.zd
    Level 31  
    Posts: 1646
    Help: 83
    Rate: 271
    5. something needs to be added in domoticz, here hints @Daro1003

    Re.4. it is possible to run the broker like a service, I will upload the service configuration file for Debian. RpiOs is the Debian version specifically.
    Running 'manual' with param --d is for debugging.
  • #44 21453586
    Daro1003
    Level 34  
    Posts: 2711
    Help: 295
    Rate: 604
    michal.zd wrote:
    5. In domoticz you need to add something, here hints @Daro1003
    .

    Yes Domoticz users will certainly know you need to create a virtual sensor in domoticz.

    Added after 11 [hours] 6 [minutes]:

    The topic is still alive colleague @michal.zd agreed at my urging as well as request to expand the program with more data from the inverter.
    I suggested to extract the voltage and power data on the individual strings of the inverter so that the data can be viewed from the panels.

    Unfortunately I don't have the energy storage I am planning to make so if I manage to do this I will still ask the author of the program to update with data from the energy storage.
  • #45 21480795
    michal.zd
    Level 31  
    Posts: 1646
    Help: 83
    Rate: 271
    I have added information about the voltage and current of strings PV1 and PV2. The voltage and current will be shown in one message for one string in the svalue "voltage;current".

    NOTE there has been a change to the domoticz parmetisation. details below. .

    programme downloadable on Git.
    https://github.com/michalzd/pvInverterBroker/...mqtt/dist/Release/GNU-Linux/RaspberryPi/ARM11
    there is also a sample configuration file: https://github.com/michalzd/pvInverterBroker/tree/mqtt/dist/etc
    which must be located in the /etc/ime directory
  • #46 21482451
    Daro1003
    Level 34  
    Posts: 2711
    Help: 295
    Rate: 604
    It is a bit of a problem how to fly current and voltage data in one because there is no block in Domoticz to have these two indications together.
    You can make a current block and a voltage block but that's two blocks and two different IDYs.


    Screenshot of the Domoticz virtual sensor creation interface with a dropdown list of sensor types. .

    This is the case for temperature and humidity but unfortunately current and voltage are separate.
  • #47 21482458
    michal.zd
    Level 31  
    Posts: 1646
    Help: 83
    Rate: 271
    Aa, so domoticz has some of its default sensors. It doesn't have voltage and current together?
    And does it make any difference? If you set temp and humidity it will receive data?
  • #48 21482465
    Daro1003
    Level 34  
    Posts: 2711
    Help: 295
    Rate: 604
    michal.zd wrote:
    Aa, so domoticz has some of its default sensors. Isn't there voltage and current together?
    .

    Yes exactly this is part of the list I have uploaded I create a voltage sensor and have the voltage block and the IDX given. And the same with current I create such a sensor I have another block and IDX.

    michal.zd wrote:
    And does it make any difference? If you set temp and humidity it will receive data?
    .

    I haven't tested but even if it does it will be data in degrees and so strange in appearance rather - something I've tried to send like that before and it didn't work very well.
  • #49 21482487
    michal.zd
    Level 31  
    Posts: 1646
    Help: 83
    Rate: 271
    Strange restrictions. The domoticz documentation allows sending several values in one mqtt message at the same time there is no way to receive this.
    As you define the sensor, there is no way to specify how many and what data?
    What is in that list in the picture?

    Ps.can be done as single values.
  • #50 21482756
    Daro1003
    Level 34  
    Posts: 2711
    Help: 295
    Rate: 604
    michal.zd wrote:
    What's on that list in the picture?


    This is the menu for creating a sensor and we have what is on the list to choose from:


    Virtual sensor creation interface with a dropdown list of types. Virtual sensor creation interface with a dropdown menu for selecting sensor type. .

    And that's it, once the name is selected and entered, the finished sensor-block with IDX appears:

    View of a sensor panel named Panel String 1 with a lightning symbol, showing 0 V. .

    You can go into the edit options and that's it altogether name icon description:

    Sensor editing menu with settings and options. .
  • #51 21482795
    michal.zd
    Level 31  
    Posts: 1646
    Help: 83
    Rate: 271
    And are these idx indexes, can they be given their own, or is that not to be changed?
    The question is whether you need to give further parameters to enter this idx, or can you just use another value.
  • #52 21482912
    Daro1003
    Level 34  
    Posts: 2711
    Help: 295
    Rate: 604
    IDX - is assigned by Domoticz automatically once a sensor or switch has been created it cannot be changed.
    There are, for example, sensors that I have created in the past and deleted and will not return to them again new numbers are added.

    There is no way to influence this. I can ask around on the Domoticz forum but I'm pretty sure there's no way to edit IDX because in so much time I think I'd have come across it.

    Added after 2 [minutes]: .

    Rather, it must be so in your program that it can be completed:
    PV1 current - xxx IDX
    PV2 current - xxx IDX
    PV1 voltage - xxx IDX
    PV2 voltage - xxx IDX

    Then it will be ok.

    From this list you can see that you can have temperature and humidity in one block and something else and that's about it.
  • #53 21483027
    michal.zd
    Level 31  
    Posts: 1646
    Help: 83
    Rate: 271
    Daro1003 wrote:
    From this list you can see that temperature and humidity can be had in one block and something else and that's it in total.
    .
    That is, the list is imposed by the program.
    Daro1003 wrote:
    Then it will be ok.
    .
    Indeed, in such a situation there is no other way.
    This is what I will do.
  • #54 21483112
    Daro1003
    Level 34  
    Posts: 2711
    Help: 295
    Rate: 604
    As with these three power data what IDX I enter is what it shows me at in Domoticz and that's cool.
    If you do that with voltage and current from the PV it's elegant.
  • #55 21483283
    michal.zd
    Level 31  
    Posts: 1646
    Help: 83
    Rate: 271
    I have added the voltage and current information of strings PV1 and PV2 as four mqtt messages.
    The voltage and current will be shown in two messages, as agreed with @Daro1003

    into the configuration file in etc/time/inverterbroker
    specify idx according to domoticz.
    
    #domoticz
    domoticz_topic       domoticz/in
    domoticz_inverter_state    1020
    domoticz_pvpower_idx    1026
    domoticz_gridpower_idx    1027
    domoticz_consumption_idx 1028
    # informacja o napieciach i pradach stringów PV
    domoticz_pv1_voltage_idx  1030
    domoticz_pv1_current_idx  1031
    domoticz_pv2_voltage_idx  1032
    domoticz_pv2_current_idx  1033
    
    
    .

    The program as usual can be downloaded on Git.
    https://github.com/michalzd/pvInverterBroker/...mqtt/dist/Release/GNU-Linux/RaspberryPi/ARM11
    There is also a sample configuration file: https://github.com/michalzd/pvInverterBroker/tree/mqtt/dist/etc
    which must be located in the /etc/ime directory
    In addition, there is also a configuration file for the service run by system.d : https://github.com/michalzd/pvInverterBroker/tree/mqtt/dist/service_config/lib_systemd_system
    this file must be in the directory: /lib/systemd/system/
  • #56 21483603
    Daro1003
    Level 34  
    Posts: 2711
    Help: 295
    Rate: 604
    It is already working for me:


    Control panel displaying data on energy production and consumption. .

    Thanks @michal.zd you are GREAT.
  • #57 21483631
    michal.zd
    Level 31  
    Posts: 1646
    Help: 83
    Rate: 271
    Well, that's great.

Topic summary

✨ The discussion centers on the development and testing of "PV InverterBroker," a Linux-based program designed to communicate with Sofar's KTL and KTL-X series inverters. The software runs on various Linux platforms including OpenWrt routers, Debian laptops, and Raspberry Pi devices. It collects data from Sofar inverters via the WiFi logger LSW-3 and publishes it to an MQTT server (Mosquitto), enabling integration with automation tools like Node-RED and Domoticz. Key functionalities include accurate reading and conversion of inverter registers such as ActivePower_Output_Total, handling signed values for power flow (positive for feed-in, negative for consumption or battery charging), and providing detailed phase voltage and current measurements. The program supports sending data in Domoticz-compatible MQTT formats, facilitating direct integration without intermediaries. Users discussed calibration and validation of power measurements against PZEM-004T energy meters, confirming data accuracy within 1-2%. Challenges addressed include Domoticz sensor limitations requiring separate IDX assignments for voltage and current, and handling MQTT topic formatting issues. The software is open-source with source code and binaries available on GitHub, and includes configuration files for service deployment on Debian-based systems. Ongoing enhancements involve expanding data extraction to include individual PV string voltages and currents, and potential future support for energy storage data. The project aims to provide a comprehensive, real-time monitoring and control solution for Sofar inverters in home energy management systems.
Generated by the language model.

FAQ

TL;DR: On a Raspberry Pi 1B+, pvInverterBroker reads Sofar KTL/HYD data through the LSW-3 logger and publishes MQTT; “All clear,” after testing showed PZEM and inverter data differed by only 1–2%. This FAQ helps Sofar users decode 65535-style values, verify power registers, and connect data to Node-RED or Domoticz. [#21420031]

Why it matters: Correctly interpreting Sofar Modbus power registers decides whether your automations react to real PV, grid, battery, and house-consumption data or to misleading raw values.

Option Data path Best use Key limitation
Node-RED + MQTT Inverter → pvInverterBroker → mosquitto → Node-RED Flexible parsing and automation Easy to misconfigure topic, flow, or Deploy
Direct Domoticz MQTT Inverter → pvInverterBroker → Domoticz Fewer steps, faster setup Requires correct IDX mapping
Raw SolarMan graphs Inverter cloud view Quick visual check Data is approximated every few minutes

Key insight: On Sofar HYD models, ActivePower_Output_Total is not simply total three-phase house load. In the tested hybrid case, it behaved like total AC output related to PV and battery flow, while separate grid and consumption values were needed for a complete HEMS/MEMS picture. [#21409368]

Quick Facts

  • pvInverterBroker was tested for over 1 year on a Raspberry Pi 1B+, after earlier runs on OpenWrt and Debian systems. [#21407292]
  • One real installation used the broker to control a DHW heat-pump cylinder and extra heaters when voltage exceeded 252 V, while keeping it below 253 V. [#21407292]
  • In the verified hybrid setup, broker MQTT values and installed PZEM-004T meters matched within about 1–2% over a week of checks. [#21420031]
  • Nighttime raw values such as 65535, 65532, and 65531 were confirmed as signed 16-bit decaWatt values, meaning -10 W, -40 W, and -50 W respectively after conversion. [#21409342]
  • The broker polls more often than SolarMan cloud charts; forum testing noted SolarMan sends cloud data only every few minutes, while the broker checks about every half inverter minute. [#21409303]

How do I set up pvInverterBroker on Raspberry Pi to read data from a Sofar KTL or HYD inverter through the LSW-3 WiFi logger and publish it to MQTT?

You copy the broker files to Raspberry Pi, fill in the Sofar logger details, then start the program. 1. Copy the binaries and required files, including the config file in /etc/ime. 2. Enter the LSW-3 WiFi logger IP, serial data, and MQTT topic settings. 3. Run ./inverterbroker -d for testing, or later as a service on Raspberry Pi OS, which was noted as Debian-based. The broker was built for Linux and was already proven on OpenWrt, Debian, and Raspberry Pi. [#21453569]

Why does a Sofar HYD inverter return values like 65535, 65532, or 65531 in the ActivePower_Output_Total register at night, and how should those be interpreted?

Those values are signed 16-bit numbers shown as unsigned raw data. On the tested HYD inverter, 65535 meant -1 decaWatt, 65532 meant -4 decaWatts, and 65531 meant -5 decaWatts. In watts, that is -10 W, -40 W, and -50 W. The thread explicitly corrected the unit: the raw power field was in decaWatts, not watts. At night, these negative values indicated power flowing the opposite way, such as battery charging or grid draw. [#21409342]

What is the ActivePower_Output_Total register in Sofar Modbus, and how does its meaning differ between KTL on-grid inverters and HYD hybrid models?

ActivePower_Output_Total is a Sofar Modbus power register, but it does not mean the same thing on all models. "ActivePower_Output_Total" is a Modbus power register that reports inverter-side active power, with model-specific sign behavior and interpretation. In the thread, the HYD documentation described it as int_16 with “Charge is positive, Discharge is negative,” valid for HYD models. For online KTL inverters, the same register was described as unsigned, which matched the author’s on-grid 15KTL-X G3 behavior. [#21408458]

Why doesn’t the ActivePower_Output_Total value on a Sofar HYD always match the sum of the three phase powers calculated from voltage times current?

Because on the tested HYD, that register did not always represent simple summed house load. During the investigation, per-phase values such as 241.4 V × 0.02 A = 4.828 W matched tiny standby loads, yet ActivePower_Output_Total could show signed values linked to battery behavior. Later checks showed the sum of phase U×I aligned with total consumption or other screen values, not always with ActivePower_Output_Total. That mismatch was the clue that hybrid models expose PV, battery, grid, and load through separate meanings. [#21409373]

What is PCC active power in Sofar inverter documentation, and how is activePower_PCC_Total different from load power or PV production power?

PCC active power is the grid connection point power, not the same as load power or PV production. "PCC active power" is a grid-interface measurement that shows power exchange at the point of common coupling, using positive values for export and negative values for import. The thread quoted activePower_PCC_Total as “positive to fed into the grid, negative to draw from the grid.” That differs from PV production power and also from candidate load registers such as ActivePower_Load_Total and ActivePower_Load_Sys. [#21409803]

How can I verify pvInverterBroker readings against PZEM-004T measurements and SolarMan data to confirm that the MQTT values are correct?

Compare broker timestamps with PZEM and SolarMan at the same moment, then check sign and unit conversions. The thread used PZEM-004T phase readings, inverter screenshots, and SolarMan graphs. Over about 1 week, the hybrid setup showed broker and PZEM values were “practically the same,” with only 1–2% difference. SolarMan was useful for trend confirmation, but its cloud updates came only every few minutes, so the broker was treated as more time-accurate. [#21420031]

What does a negative Grid or Power value mean in pvInverterBroker, especially when the battery is charging or the inverter is drawing from the grid?

A negative value means power is flowing in the opposite direction from normal production or export. In the thread, Grid was negative when the system drew from the grid, and Power became negative when raw 16-bit values were converted correctly. One worked example linked 65531 to -40 W on the inverter display as “Total AC Output Power:-40.00W.” The author concluded that a negative value could mean the battery was charging while energy came from the grid. [#21409342]

How do I connect pvInverterBroker data to Node-RED using an mqtt in node and debug node so I can see the inverter JSON messages?

Create an mqtt in node for the broker topic, connect it to debug, and deploy the flow. 1. In Node-RED, add mqtt in and point it to your mosquitto server. 2. Subscribe to the ready-made JSON topic, which the thread described as most convenient for Node-RED. 3. Link a debug node to inspect the incoming msg object in the sidebar. The thread specifically recommended the ime/inverter/json topic for this. [#21420031]

Why is Node-RED not receiving any pvInverterBroker MQTT messages even though mosquitto_sub shows data, and what configuration mistakes should I check first?

The first things to check are topic syntax, hidden spaces, broker restart, and the Node-RED Deploy button. In the solved case, mosquitto_sub showed voltage data, but Node-RED received nothing because the topic string contained an extra space before /state and /json, and the flow had not been deployed. The author also reminded the user to restart the broker after editing the config. This was a pure configuration fault, not an inverter fault. [#21420505]

What is HEMS or MEMS in the context of Sofar inverter data, and which power values are needed to build a sensible energy management algorithm?

Here, HEMS/MEMS means an energy-management algorithm that needs PV, grid, and consumption values, not just one output register. "HEMS/MEMS" is an energy-management control approach that decides how a home uses PV, grid, and storage power, using multiple synchronized measurements rather than one inverter register. The thread concluded that ActivePower_Output_Total alone was insufficient. The author wanted at least PV power, grid power, and consumption power to make the logic meaningful, especially on a hybrid system. [#21409368]

Node-RED versus direct Domoticz MQTT integration with pvInverterBroker: which approach makes more sense for Sofar inverter monitoring and automation?

Direct Domoticz MQTT makes more sense if you only want Domoticz sensors, while Node-RED makes more sense for custom logic. By 2025-02-24, the next broker version could send MQTT “immediately in a format understood by domoticz,” so Node-RED was no longer required as an intermediary. The thread still kept Node-RED useful for debugging, message inspection, and flexible automation. Use Node-RED when you need transformations; use direct Domoticz when you want fewer moving parts. [#21453475]

How do I send Sofar inverter data from pvInverterBroker straight into Domoticz without using Node-RED as an intermediary?

Use the newer broker version, configure Domoticz MQTT fields, and map the required IDX values. 1. Copy the updated broker files to Raspberry Pi. 2. Fill in the Sofar Wi-Fi module IP, serial number, and Domoticz IDX values in the config. 3. Run ./inverterbroker -d for testing, then switch to service mode later. The forum described this as “actually now a few steps,” with data appearing directly in Domoticz after setup. [#21453527]

Why did the pvInverterBroker Domoticz configuration change for PV1 and PV2 string data, and how should IDX values be assigned now?

The configuration changed because Domoticz could not present PV string voltage and current together in one usable sensor block. The author first tried sending each string as one voltage;current message, then changed it after testing. The final layout required four separate IDX entries: domoticz_pv1_voltage_idx, domoticz_pv1_current_idx, domoticz_pv2_voltage_idx, and domoticz_pv2_current_idx. IDX values are assigned automatically by Domoticz when each virtual sensor is created. [#21483283]

What is the best way to display Sofar PV string voltage and current in Domoticz when Domoticz does not support both values in one sensor block?

Use two separate sensors per string: one for voltage and one for current. The thread established that Domoticz had no practical combined block for current and voltage, unlike some other paired sensor types. That is why the final broker output exposed four MQTT messages for two strings: PV1 voltage, PV1 current, PV2 voltage, and PV2 current. This approach matched Domoticz’s automatic IDX model and worked immediately in the test setup. [#21483283]

Where should PZEM meters be installed in a hybrid Sofar system to compare house consumption, inverter output, and grid import/export safely and meaningfully?

Place one set on the inverter output side and another on the house side if you want meaningful comparison. In the tested system, one PZEM location was on the wires from the photovoltaic inverter to protection, and the house meters were installed on the house feed before the RCDs. That placement let the users compare inverter-related flow, house consumption, and broker values at nearly the same time. It also helped confirm that some inverter phase currents were only about 0.02 A at night. [#21409389]
Generated by the language model.
ADVERTISEMENT