SofarSolar inverter integration

Hello Pawel,
I can’t really interpret the problem in the logs, i have started with very_verbose wit this output:
[14:11:45][VV][uart.arduino_esp8266:180]: Flushing…
[14:11:45][V][modbus:184]: Modbus write: 01.04.00.00.00.01.31.CA (8)
[14:11:45][D][modbus_controller:029]: Modbus command to device=1 register=0x00 countdown=0 no response received - removed from send queue
Next i enabled the debug and uart debug (direction: BOTH), it looks like nothing is received from the sofarsolar…but why, the receive led is flashing…
[15:06:55][D][uart_debug:158]: >>> “\x01\x03\x00\x00\x00\x1E\xC5\xC2”
[15:06:55][D][uart_debug:158]: >>> “\x01\x03\x00\x00\x00\x1E\xC5\xC2”
[15:06:55][D][uart_debug:158]: >>> “\x01\x03\x00\x00\x00\x1E\xC5\xC2”
[15:06:56][D][uart_debug:158]: >>> “\x01\x03\x00\x00\x00\x1E\xC5\xC2”
[15:06:56][D][uart_debug:158]: >>> “\x01\x03\x00\x00\x00\x1E\xC5\xC2”
[15:06:56][D][modbus_controller:029]: Modbus command to device=1 register=0x00 countdown=0 no response received - removed from send queue

Do you have an idea or recommendation ?
Thanks again !
Rob

Check RX cable or change RX pin/configuration. In logs you see only transfer. Diodes on converter shows RX, but nothing in logs, it looks weird.

checked, kabels are note crossed. I connected a led on the rx line at the wemos it´s flashing simultaneously with the rx on the rs485 interface…i also crossed the tx and rx at the wemos to see if it receiving theit output and yes the debug shows reciving data and the modbus component reports a crc cheksum error…
I would now assume that the rx level from the rs485 interface does not match…

Which RS 485 interface did you use? in the pictures i can see that you connected it to 5 volts right? are the levels (3.3 volts) correct for the esp ?

Yes, I have converter connected to 5v, because this is a voltage provided by inverter. I don’t remember what’s the voltage according spec of module, but I remember that on RX and TX 3v3 signal level is supported and esp8266 operates on this level.

Hey @pawelka, congrats on the really great job! I’m using the ESPHome logger with D1 mini.
I now plan to use it to automate charging my EV from surplus energy.
One question: The enclosure in my inverter is metal, how did you insulate your module?
Also a suggestion: the logger sends huge amounts of data, for us using an SD card it is a little frightening. I guess you also wonder:

[TODO?] all registers or only useful one?

I suggest:

  1. Increase update from 10 to 60 seconds perhaps?
  2. For most of sensors (except power) you can add the following, this way people who need it will just enable it in HA:
disabled_by_default: true

BTW I think we’re from the same country. Thanks again for your contribution!

HI! Great add-on. I do get the following error:
2022-05-21 13:30:44 ERROR (MainThread) [homeassistant.components.hassio] Failed to to call /addons/3a87ddeb_sofarsolar_mqtt/stats - Container addon_3a87ddeb_sofarsolar_mqtt is not running

In MQTT viewer i don’t see the plugin.

What do I wrong?

When I start SofarSolarMQTT receive this error:

Traceback (most recent call last):
  File "/usr/local/lib/python2.7/runpy.py", line 174, in _run_module_as_main
    "__main__", fname, loader, pkg_name)
  File "/usr/local/lib/python2.7/runpy.py", line 72, in _run_code
    exec code in run_globals
  File "/inverter/__main__.py", line 1, in <module>
    import Inverter
  File "/inverter/Inverter.py", line 10, in <module>
    import anyconfig
  File "/usr/local/lib/python2.7/site-packages/anyconfig/__init__.py", line 24, in <module>
    from .api import (
  File "/usr/local/lib/python2.7/site-packages/anyconfig/api/__init__.py", line 124
    def version() -> typing.List[str]:
                  ^
SyntaxError: invalid syntax

How can I resolve?

I have this same problem.

Trying to run rs485 logger on my Sofar Solar 8.8 KTLX-G3 but looks like G3 series has a different registers. How to fix that? Here you can find registers received from Sofar support: docs.google.com/spreadsheets/d/1p6p7n8-V2jlFid3FPPk5L4Sn4-tOWscQwpkahq5jRbs/edit#gid=157762751

Currently I can see just “0” value for every entity

And this is the output from the logs. So looks like modbus communication is established correctly

For example:
“Total Energy” in pawelka’s project has address 0x0015
image

which address should I provide to let my logger reading a correct values?

EDIT:
Just found solution. Registers provided by Sofar support are in DEC. It just need to be converted to HEX.
For example PV_Generation_Total is 0686 (dec) = 0x2AE (hex).
Just changed address from 0x0015 to 0x2AE and finally, the correct data is uploaded into Home Assistant

1 Like

Could you share your config? I’m trying to get my G3 to work and there is not much data about that to work with.

Hi,
Have you managed to create full config file for ESPhome? Would be really great if i could save some time porting it for G3 by myself :slight_smile:

Good day. Please, Is this inverter supported?

Hello,
I would need help. In the case of “8.8 KTLX-3”, where should the TTL converter be connected?
I tried it on “Electric meter RS485A” and “Electric meter RS485B” but without success.
Where should it be plugged in? It doesn’t have an RJ45 shape for me.
I will add a picture from the manual.

Thanks for help
Thomas

Or 7 and 12 ports should I use?
7 to the negative and 12 to the positive?

@sporniak

Just so you know I have started to add in support for Sofar Solar on my SolaX custom_component SolaX Inverter by Modbus (No Pocket WiFi) ( now a custom_component ) if you fancy Beta testing give it ago and let me know. (It will probably fail on the serial number check (only checks first couple of digits to determine model) but that can be easily fixed once we know what it is)

Did you get connected?

I don’t own a Sofar but looking at that Diagram you want Pins 1&3 or 2&4 You might need to connect Ground as well Pin7 but on SolaX Inverters that’s normally not required.

1 Like

witam .
do sofara udało mi się wyciągnąć adresy i mam nadzieję że wszystkie są poprawne poniżej podaję kod z mojego home-esp


substitutions:
  devicename: sofarsolar-logger
  friendly_name: SofarSolar
  hostname: "esp8266-sofar"
  comment: "SofarSolar modbus interface"
  icon: "mdi:solar-power-variant-outline"
  restore_mode: "restore_default_off"
 
wifi:
  ssid: "1231233123"
  password: "22222222222222222222"
  fast_connect: true
  reboot_timeout: 120s
  power_save_mode: none
 
  ap:
    ssid: "Fallback-AP-${devicename}"
    password: ""
    ap_timeout: 300s
 
api:
  password: "TbkEdpMbU5555555552"
 
ota:
  password: "TbkEdpMbU55555552"
  safe_mode: False
 
captive_portal:
 
#mdns:
#  disabled: True
 
#web_server:
#  port: 80
#  ota: false
 
esphome:
  name: $devicename
  platform: ESP8266
 # board: esp01_1m
  board: d1_mini
  board_flash_mode: dout
  comment: SofarSolar Logger (Modbus/RS485)
 
#esp8266:
#  board: d1_mini





logger:
#    level: INFO
#    baud_rate: 0
   
status_led:
  pin:
    number: GPIO2
    inverted: true
 
external_components:
  - source:
      type: git
      url: https://github.com/ssieb/custom_components
    components: [ heapmon ]
 
#uart:
#  id: mod_bus
#  tx_pin: 1
#  rx_pin: 3     # to piny używane do wgrywania i raportu 
#  baud_rate: 9600
#  stop_bits: 1

uart:
  id: mod_bus
  rx_pin: D1
  tx_pin: D2
  baud_rate: 9600
  #baud_rate: 38400      
#  baud_rate: 19200      #9600
  stop_bits: 1
  debug:




 
modbus:
  id: mod_bus_sofar
 
modbus_controller:
  - id: sofarsolar



    address: 0x01
    modbus_id: mod_bus_sofar
    update_interval: 5s
 
text_sensor:
 
  - platform: template
    name: "ESP-Sofar Uptime (human readable)"
    id: uptime_human
    icon: "mdi:clock-start"
    update_interval: 5s
   
  - platform: modbus_controller
    modbus_controller_id: sofarsolar
    name: ${friendly_name} Status
    id: inverter_status
    register_type: holding
    icon: "mdi:information-outline"
    address: 0x0404
    response_size: 2
    lambda: |-
      auto z = "Unknown";
      char d = data[item->offset+1];
      if (d == 0) z = "Czeka";
      else if (d == 1) z = "Check";
      else if (d == 2) z = "Produkuje";
      else if (d == 3) z = "Fault";
      else if (d == 4) z = "Permanent";
      else if (d == 5) z = "główny błąd";
      else if (d == 6) z = "szejść";
      else if (d == 7) z = "siedem";
      return {z};
 
 
 
sensor:
  - platform: wifi_signal
    id: inverter_wifi_signal
    name: "ESP-Sofar WiFi Signal"
    update_interval: 60s
    icon: "mdi:wifi"
 
  - platform: uptime
    id: inverter_uptime
    name: "ESP-Sofar Uptime"
    filters:
      - lambda: return x / 60.0;
    unit_of_measurement: minutes
    icon: "mdi:clock-start"
 
  - platform: heapmon  
    id: heapspace  
    name: "ESP-Sofar Heapsize"
    icon: "mdi:memory"
    update_interval: 5s
 
  - platform: modbus_controller
    modbus_controller_id: sofarsolar
    name: ${friendly_name} DC1 Voltage
    id: inverter_dc_v1
    register_type: holding
   # address: 0x0006
    address: 0x0584 
    unit_of_measurement: "V"
    state_class: "measurement"
    device_class: "voltage"
    icon: "mdi:alpha-v-circle-outline"
    value_type: U_WORD
    accuracy_decimals: 1
    filters:
      - multiply: 0.1
 
  - platform: modbus_controller
    modbus_controller_id: sofarsolar
    name: ${friendly_name} DC1 Current
    id: inverter_dc_c1
    register_type: holding
  #  address: 0x0007
    address: 0x0585 
    unit_of_measurement: "A"
    state_class: "measurement"
    device_class: "current"
    icon: "mdi:alpha-a-circle-outline"
    value_type: U_WORD
    accuracy_decimals: 2
    filters:
      - multiply: 0.01
 
  - platform: modbus_controller
    modbus_controller_id: sofarsolar
    name: ${friendly_name} DC2 Voltage
    id: inverter_dc_v2
    register_type: holding
    #address: 0x0008
    address: 0x0587 
    unit_of_measurement: "V"
    state_class: "measurement"
    device_class: "voltage"
    icon: "mdi:alpha-v-circle-outline"
    value_type: U_WORD
    accuracy_decimals: 1
    filters:
      - multiply: 0.1
 
  - platform: modbus_controller
    modbus_controller_id: sofarsolar
    name: ${friendly_name} DC2 Current
    id: inverter_dc_c2
    register_type: holding
   # address: 0x0009
    address: 0x0588 
    unit_of_measurement: "A"
    state_class: "measurement"
    device_class: "current"
    icon: "mdi:alpha-a-circle-outline"
    value_type: U_WORD
    accuracy_decimals: 2
    filters:
      - multiply: 0.01
 
  - platform: modbus_controller
    modbus_controller_id: sofarsolar
    name: ${friendly_name} DC1 Power
    id: inverter_dc_power1
    register_type: holding
   # address: 0x000a
    address: 0x0586 
    unit_of_measurement: "W"
    state_class: "measurement"
    device_class: "power"
    icon: "mdi:solar-power"
    value_type: U_WORD
    filters:
      - multiply: 10
 
  - platform: modbus_controller
    modbus_controller_id: sofarsolar
    name: ${friendly_name} DC2 Power
    id: inverter_dc_power2
    register_type: holding
   # address: 0x000b
    address: 0x0589 
    unit_of_measurement: "W"
    state_class: "measurement"
    device_class: "power"
    icon: "mdi:solar-power"
    value_type: U_WORD
    filters:
      - multiply: 10
 
  - platform: modbus_controller
    modbus_controller_id: sofarsolar
    name: ${friendly_name} AC Power
    id: inverter_ac_power
    register_type: holding
    address: 0x0485
    #  address: 0x0485 - niemam pewności czy to to 
    

   # address: 0x0488  # nie podaje ale wczesniej było .. ***************************************111111111111111

    
    unit_of_measurement: "W"
    state_class: "measurement"
    device_class: "power"
    icon: "mdi:solar-power-variant-outline"
    value_type: U_WORD
    filters:
      - multiply: 10
 
  - platform: modbus_controller
    modbus_controller_id: sofarsolar
    name: ${friendly_name} AC Reactive Power
    id: inverter_ac_reactive_power
    register_type: holding
    address: 0x0487  ## 

  #  address: 0x000d    ## 
    unit_of_measurement: "kVar"
    state_class: "measurement"
    #device_class: "reactive_power"
    icon: "mdi:math-cos"
    value_type: S_WORD
    filters:
      - multiply: 10
 
  - platform: modbus_controller
    modbus_controller_id: sofarsolar
    name: ${friendly_name} AC Freq
    id: inverter_ac_freq
    register_type: holding
    address: 0x0484                       ## jest ok. 
    unit_of_measurement: "Hz"
    state_class: "measurement"
    #device_class: "frequency"
    icon: "mdi:current-ac"
    value_type: U_WORD
    accuracy_decimals: 2
    filters:
      - multiply: 0.01
 
  - platform: modbus_controller
    modbus_controller_id: sofarsolar
    name: ${friendly_name} L1 Voltage
    id: inverter_ac_v1
    register_type: holding
    ## address: 0x098b

  ##  address: 0x000f
    address: 0x048D

    unit_of_measurement: "V"
    state_class: "measurement"
    device_class: "voltage"
    icon: "mdi:alpha-v-circle"
    value_type: U_WORD
    accuracy_decimals: 1
    filters:
      - multiply: 0.1
 
  - platform: modbus_controller
    modbus_controller_id: sofarsolar
    name: ${friendly_name} L1 Current
    id: inverter_ac_c1
    register_type: holding
  #  address: 0x0010
    address: 0x048E
    unit_of_measurement: "A"
    state_class: "measurement"
    device_class: "current"
    icon: "mdi:alpha-a-circle"
    value_type: U_WORD
    accuracy_decimals: 2
    filters:
      - multiply: 0.01
 
  - platform: modbus_controller
    modbus_controller_id: sofarsolar
    name: ${friendly_name} L2 Voltage
    id: inverter_ac_v2
    register_type: holding
    address: 0x0498
   # address: 0x0011
    unit_of_measurement: "V"
    state_class: "measurement"
    device_class: "voltage"
    icon: "mdi:alpha-v-circle"
    value_type: U_WORD
    accuracy_decimals: 1
    filters:
      - multiply: 0.1
 
  - platform: modbus_controller
    modbus_controller_id: sofarsolar
    name: ${friendly_name} L2 Current
    id: inverter_ac_c2
    register_type: holding
  #  address: 0x0012
    address: 0x0499
    unit_of_measurement: "A"
    state_class: "measurement"
    device_class: "current"
    icon: "mdi:alpha-a-circle"
    value_type: U_WORD
    accuracy_decimals: 2
    filters:
      - multiply: 0.01
 
  - platform: modbus_controller
    modbus_controller_id: sofarsolar
    name: ${friendly_name} L3 Voltage
    id: inverter_ac_v3
    register_type: holding
  #  address: 0x004BA
    address: 0x04A3
   # address: 0x0586    # faluje 2.1 2,2
#    address: 0x0013
    unit_of_measurement: "V"
    state_class: "measurement"
    device_class: "voltage"
    icon: "mdi:alpha-v-circle"
    value_type: U_WORD
    accuracy_decimals: 1
    filters:
      - multiply: 0.1
 
  - platform: modbus_controller
    modbus_controller_id: sofarsolar
    name: ${friendly_name} L3 Current
    id: inverter_ac_c3
    register_type: holding
                                                ################ tu sprawdzam. 
   # address: 0x0418    # podaje o.14 - temperatura ?  w aplikacji jest taka temperatura  singla ambied
   # address: 0x0483             # 249.59
  
   # address: 0x0585   # podaje 0,66 to jagby jeden string ampery . 
   # address: 0x0587   # 38,56
   # address: 0x0588     # ampery na linię pv2 dc
    address: 0x04A4
    unit_of_measurement: "A"
    state_class: "measurement"
    device_class: "current"
    icon: "mdi:alpha-a-circle"
    value_type: U_WORD
    accuracy_decimals: 2
    filters:
      - multiply: 0.01

 


  - platform: modbus_controller
    modbus_controller_id: sofarsolar
    name: ${friendly_name} Energia całkowita Produkcji Parking
    id: inverter_energy_total
    register_type: holding
    ##### address: 0x0015
    address: 0x0686    # licznik całkowitej energi 

    unit_of_measurement: "kWh"
    accuracy_decimals: 2
    device_class: "energy"
    state_class: "total_increasing"
    icon: "mdi:solar-power-variant-outline"
    value_type: U_DWORD
    filters:
        # Multiplication factor from W to kW is 0.001
      - multiply: 0.1
      #unit_of_measurement: kW
 
  - platform: modbus_controller
    modbus_controller_id: sofarsolar
    name: ${friendly_name} Energy produkcja time total
    id: inverter_energy_generation_time_total
    register_type: holding

    address: 0x0427
  # address: 0x0428

# unit_of_measurement: "h"
    unit_of_measurement: "min"
    icon: "mdi:timeline-clock"
    value_type: U_DWORD
 
 
  - platform: modbus_controller
    modbus_controller_id: sofarsolar
    name: ${friendly_name} Energia dzisiaj
    id: inverter_energy_today
    register_type: holding
    address: 0x0685
    #address: 0x0426
    unit_of_measurement: "kWh"
    state_class: "measurement"
    device_class: "energy"
    icon: "mdi:solar-power-variant-outline"
    value_type: U_WORD
    accuracy_decimals: 2
    filters:
      - multiply: 0.01
 
  - platform: modbus_controller
    modbus_controller_id: sofarsolar
    name: ${friendly_name} Energy generation time today
    id: inverter_energy_generation_time_today
    register_type: holding
    address: 0x0426
    unit_of_measurement: "min"
    icon: "mdi:timeline-clock"
    value_type: U_WORD
 
  - platform: modbus_controller
    modbus_controller_id: sofarsolar
    name: ${friendly_name} Temprature module
    id: inverter_temp_module
    register_type: holding
   # address: 0x001B
    address: 0x041A
    unit_of_measurement: "°C"
    state_class: "measurement"
    device_class: "temperature"
    icon: "mdi:temperature-celsius"
    value_type: U_WORD
 
  - platform: modbus_controller
    modbus_controller_id: sofarsolar
    name: ${friendly_name} Temprature inverter
    id: inverter_temp_inverter
    register_type: holding
  #  address: 0x001C
    address: 0x0418
    unit_of_measurement: "°C"
    state_class: "measurement"
    device_class: "temperature"
    icon: "mdi:temperature-celsius"
    value_type: U_WORD
 
  - platform: modbus_controller
    modbus_controller_id: sofarsolar
    name: ${friendly_name} Bus voltage
    id: inverter_bus_voltage
    register_type: holding
    address: 0x06CC      
    unit_of_measurement: "V"
    state_class: "measurement"
    device_class: "voltage"
    icon: "mdi:alpha-v-circle-outline"
    value_type: U_WORD
    accuracy_decimals: 1
    filters:
      - multiply: 0.1
 
 
  - platform: modbus_controller
    modbus_controller_id: sofarsolar
    name: ${friendly_name} PV- isolation resistance
    id: inverter_cathode_to_ground_impedance
    register_type: holding
    address: 0x042B                 #***************************
    unit_of_measurement: "Ohm"
    state_class: "measurement"
    icon: "mdi:omega"
    value_type: U_WORD
 
  - platform: template
    name: ${friendly_name} AC Current (total)    
    lambda: |-
      return (id(inverter_ac_c1).state + id(inverter_ac_c2).state + id(inverter_ac_c3).state);
    unit_of_measurement: A
    accuracy_decimals: 2
    icon: "mdi:alpha-a-circle"
    device_class: "current"
    state_class: "measurement"
    update_interval: 5s
 
  - platform: template
    name: ${friendly_name} DC Current (total)  
    lambda: |-
      return (id(inverter_dc_c1).state + id(inverter_dc_c2).state);
    unit_of_measurement: A
    accuracy_decimals: 1
    state_class: "measurement"
    device_class: "current"
    icon: "mdi:alpha-a-circle-outline"
    update_interval: 5s
 
  - platform: template
    name: ${friendly_name} DC Power (total)  
    lambda: |-
      return (id(inverter_dc_power2).state + id(inverter_dc_power1).state);
    unit_of_measurement: W
    state_class: "measurement"
    device_class: "power"
    accuracy_decimals: 0
    icon: "mdi:alpha-a-circle-outline"
    update_interval: 5s
 
  - platform: uptime
    name: ${friendly_name} Uptime
    id: uptime_sensor
    update_interval: 5s
    icon: "mdi:clock-start"
    internal: true
    on_raw_value:
      then:
        - text_sensor.template.publish:
            id: uptime_human
            state: !lambda |-
              int seconds = round(id(uptime_sensor).raw_state);
              seconds = seconds % (24 * 3600);
              int hours = seconds / 3600;
              seconds = seconds % 3600;
              int minutes = seconds /  60;
              seconds = seconds % 60;
              return (
                (hours ? to_string(hours) + "h " : "") +
                (minutes ? to_string(minutes) + "m " : "") +
                (to_string(seconds) + "s")
              ).c_str();
 
  - platform: template
    unit_of_measurement: "%"
    name: "ESP-Sofar WiFi Signal (human readable)"
    accuracy_decimals: 0
    update_interval: 30s
    device_class: "signal_strength"
    icon: "mdi:wifi"
    lambda: return (-0.0134 * (id(inverter_wifi_signal).state * id(inverter_wifi_signal).state ) ) + (-0.2228 * id(inverter_wifi_signal).state) + 100.2;
 
switch:
  - platform: restart
    name: "ESP-Sofar Restart"
 
binary_sensor:
  - platform: status
    name: "ESP-Sofar Status"

jak na razie wszystko działa. :slight_smile:

tu adresy na podstawie których uzyskałem konfigurację ten plik został przygotowany przez kogoś innego ale jest aktualny

Witajcie, czy macie pomysł jak zintegrować falownik Corab Encore FALOWNIK CORAB ENCOR HYBRID 8K+MODUŁ KOMUNIKACYJNY WIFI ?