Integrating SRNE MPPT Inverter with HA

@Mattie thank you for this work! I got an HF4850S80-H type of inverter that I have been controlling with my own bash/python integration by reverse engineering the commands I received from the supplied manufacturer software iPower.exe.

Can you share any documentation about the registers you use? How did you find/acquire this documentation?

I created the below script to configure values, but I would like to expand this to all the battery settings, have you done this with modbus and any mapping between the configuration settings in the manual and the modbus commands?

Is there a way to configure the modbus and intervals, so it does not lock up the tcp connection the port all the time as it prevents my script to run and then my automation fails with writing my settings.

Has anyone found documentation about temperature monitoring and maximum temperatures?
Has anyone found firmware updates for your devices? HF4850S80-H (with parallel communication).

#!/bin/bash -x

INPUT=$1
VALUE=$2

apk add sed socat xxd python3 -q

decimal_to_modbus_hex() {
    local decimal=$1
    local high_byte=$((decimal / 256))
    local low_byte=$((decimal % 256))
    printf "%02X %02X\n" "$high_byte" "$low_byte"
}

modbus_hex_to_decimal() {
    local hex="$1"
    local high_byte="0x${hex%% *}"  # Extract the high byte
    local low_byte="0x${hex##* }"   # Extract the low byte
    local decimal=$(( (high_byte * 256) + low_byte ))  # Calculate the decimal value
    echo "$decimal"
}

#OUTPUT PRIORITY
     OUTPUT_PV_FIRST="01 10 e2 04 00 01 02 00 00 65 da"
   OUTPUT_MAIN_FIRST="01 10 e2 04 00 01 02 00 01 a4 1a"
OUTPUT_BATTERY_FIRST="01 10 e2 04 00 01 02 00 02 e4 1b"
       OUTPUT_STATUS="01 03 e2 04 00 01 f3 b3"
       OUTPUT_RETURN="01 10 e2 04 00 01 76 70"

#CHARGER SOURCE PRIORITY 
    CHARGER_PV_FIRST="01 10 e2 0f 00 01 02 00 00 64 a1"
  CHARGER_MAIN_FIRST="01 10 e2 0f 00 01 02 00 01 a5 61"
 CHARGER_PV_AND_MAIN="01 10 e2 0f 00 01 02 00 02 e5 60"
     CHARGER_ONLY_PV="01 10 e2 0f 00 01 02 00 03 24 a0"
      CHARGER_STATUS="01 03 e2 0f 00 01 82 71"
      CHARGER_RETURN="01 10 e2 0f 00 01 07 b2"

#POWER SAVING MODE
 SAVING_POWER_ENABLE="01 10 e2 0c 00 01 02 00 01 a5 52"
SAVING_POWER_DISABLE="01 10 e2 0c 00 01 02 00 00 64 92"
 SAVING_POWER_STATUS="01 03 e2 0c 00 01 72 71"
       SAVING_RETURN="01 10 e2 0c 00 01"

#MAX AC CHARGER CURRENT
VALUE=$((VALUE * 10))
VALUE=$(decimal_to_modbus_hex "$VALUE")
  CURRENT_AC_CHARGER="01 10 e2 05 00 01 02 $VALUE"
CRC=$(python3 /config/modbus_crc16_calculator.py "$CURRENT_AC_CHARGER")
#CRC=$(python3 /usr/local/bin/modbus_crc16_calculator.py "$CURRENT_AC_CHARGER")
  CURRENT_AC_CHARGER=$(echo $CURRENT_AC_CHARGER $CRC)
   CURRENT_AC_STATUS="01 03 e2 05 00 01 a2 73"
      CURRENT_RETURN="01 10 e2 05 00 01"
         
	 BATTERY_SOC="01 03 01 00 00 0f 04 32"
      BATTERY_RETURN="01 03 1e"

     AMPERAGE_STATUS="01 03 e2 05 00 01 a2 73"
     AMPERAGE_RETURN="01 03 02"

#RETURN="${INPUT%_*}_RETURN"
RETURN="$(echo $INPUT | cut -f 1 -d "_")_RETURN"
RETURN="${!RETURN}"

COMMAND="${!INPUT}"
COMMAND=$(echo "$COMMAND" | sed 's/[[:blank:]]//g')
RETURN=$(echo "$RETURN" | sed 's/[[:blank:]]//g')

while [[ "$RESPONSE" != *"$RETURN"* ]]; do
    RESPONSE=$(echo -n $COMMAND | xxd -r -p | socat -t 1 -b 9600 TCP-CONNECT:192.168.24.235:11000 STDIO | xxd -ps -c 256)
    sleep 1
done

#if [ "$INPUT" == "BATTERY_SOC" ]; then
#    RESPONSE=$(echo "$RESPONSE" | sed "s/.*$RETURN/$RETURN/")
#    #RESPONSE=$(echo "$RESPONSE" | awk -F "$RETURN" '{print $2}')
#    # battery state of charge field five
#    # hexSOC=$(echo $RETURN$RESPONSE | head -c 10 | tail -c 2)
#    hexSOC=$(echo $RESPONSE | head -c 10 | tail -c 2)
#    SOC=$(( 16#$hexSOC ))
#    echo $SOC
#fi

if [ "$INPUT" == "AMPERAGE_STATUS" ] || [ "$INPUT" == "BATTERY_SOC" ]; then
    RESPONSE=$(echo "$RESPONSE" | sed "s/.*$RETURN/$RETURN/")
    # data can be found in field five
    hexDATA=$(echo $RESPONSE | head -c 10 | tail -c 4 | sed 's/../& /g; s/ $//')
    DATA=$(modbus_hex_to_decimal "$hexDATA")
    echo $DATA
fi

exit

Hi! I’m glad to hear that :slight_smile: I will post some docs on the modbus indexes here instead of uploading it when I get to the computer. You can set the scan intervals in the modbus configuration if that’s an alternative for you. I don’t know if you can poll it manually. An easy work around would be to control the modbus gateway with a zwave switch or something like that. Depending on what you wish for it could work. And if you only wish to send commands (write registers) through the gateway it can be done with scripts so that you don’t need to poll at all.

1 Like

Would it be possible to write the registers with the same modbus connection used to read the sensors, then I can replace my custom script with writing to sensors etc. Have you done this with HA modbus and any mapping/documentation between the configuration settings in the manual and the modbus commands?

I guess that should be doable if you just copy the modbus config without the “sensors:” part if you dont want any. Then try to make a script like I made in this post: Integrating SRNE MPPT Inverter with HA - #10 by Mattie worked nicely for me

I am new to the Home Assistant. Recently I just try to setup the modbus with USB(rs485 to USB with CH340T) for my SRNE 48V 5000W all in one inverter. Currently I can read all the data with modbus sensor as Entities, but they are not listed and HA complain no unique_ID. I try to manually add some unique_ID as your configuration.yaml, I still can’t use them in the energy dashboard even with right kWh unit. Your dashboard looks so good, I want to setup it up as yours. Would you tell me how you integrate these modbus sensors into Home Assistant and Dashboard?

Sorry to Hijack this thread…

I am working on supporting the Japanese specific SolaX Hybrid Inverter J1 into my custom_integration Universal Solar Inverter over Modbus RS485 / TCP custom_component (Growatt, Sofar, SolaX, Solis)

By any chance do you know anyone in Japan who owns one?

Also is there any benefit to you all if I added SRNE into my custom_integration if it makes it easier to install / keep upto date etc? Assuming there are adequate Modbus docs available.

1 Like

Hello my friend, I dont know about the device you are using, easiest way for you is to buy the part I used in the guide and just follow the steps above. Also for the graphs I export data to influxDB, its a timeseries database that can show data over time better. For visualisation it uses grafana, then integrate that into your dashboard. It needs some reading to understand but is very powerful… :slight_smile:

For everyones use I uploaded the modbus-index-pdf to another filesharing site, I hope it stays there for longer than 30 days. I anyone else has some space feel free to share it here

Modbus index.pdf

1 Like

Shows as deleted?

New link here Valid 30 days

2 Likes

That one worked.

I have SRNE inverter. Can someone guide me how to connect it with Home Assistant through ESP32 ?

Just started to add in support for these SRNE Inverters into my custom_component.
It’s limited at the moment and I’ll carry on adding to it over the next few days. Unless someone wants to look how the registers are defined in the plugin_srne and submit a PR.

1 Like

I would gladly do it if I had the time but life doesnt allow it currently :confused:

offtopic, is anyone having issues with your sensors after latest update? Most of my values have went crazy after yesterdays update…!

see this thread: Anyone else having MODBUS issues?

Does anyone have this working over the Bluetooth adapter my solar is in a shed in the back yard not able to run network cable

Hi Mattie,

I’ve purchased this waveshare RS485 to ETH adapter and have pluged in the respective cables (Ground pin 2, B- pin 7, and A+ pin 8) and setup my baud rate and port to be the same as yours and used the modbus template you provided as an example but always get the error:

“Received 0 bytes, unpack error unpack requires a buffer of 2 bytes”

I can see in the Wareshare portal that the RX and TX values are going up:

But still nothing, I have the ASF48100S200-H inverter so very similar to yours.

Any tips or help would be appreciated, here is my HA yaml, I have modbus working with my victron gear no issues there. Just need to get this inverter communicating.

#modbus:

  • name: SRNEInverter
    type: rtuovertcp
    host: 192.168.10.198
    port: 8888
    sensors:

    #Battery level percentage
    
    • name: Modbus_Inverter_BatteryLevel
      scan_interval: 60
      unit_of_measurement: “%”
      slave: 1
      scale: 1
      address: 256
      unique_id: 700
      input_type: holding

You should get a state on Modbus_Inverter_BatteryLevel with my config. If you copied every setting it should be fine and it sounds like your ha ip is the one showing up in the waveshare gateway? So it’s collection something?

What does your modbus config look like?

I have managed to integrate my SRNE inverter to HA using ESP32 & ESPHome addon.

Part of my yaml file is as follows.

esphome:
  name: srne
  friendly_name: SRNE

esp32:
  board: esp32dev
  framework:
    type: arduino


# Enable Home Assistant API
api:
  encryption:
    key: "+EMWnue33wLGXOUUcZdBgtEcWOJjQIPoN7E3WbVj2UA="

ota:
  password: "27a70d64573b33d2dc248577739abfa5"


wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password
  use_address: 192.168.1.16
  manual_ip:
    static_ip: 192.168.1.16
    gateway: 192.168.1.1
    subnet: 255.255.255.0

uart:
 id: mod_bus
 tx_pin: 19
 rx_pin: 18
 baud_rate: 9600
 stop_bits: 1
 
modbus:
 id: tdt1_modbus
 flow_control_pin: 4
 
modbus_controller:
 - id: srne1
   address: 0x01
   modbus_id: tdt1_modbus
   setup_priority: -10
   update_interval: 15000ms #data refresh rate
                       
sensor:

 - platform: modbus_controller
   modbus_controller_id: srne1
   name: "Inverter Frequency" #name for HA
   id: srne_inverter_freq #id for HA
   register_type: holding
   address: 0x0218 
   unit_of_measurement: Hz 
   filters:
      - multiply: 0.01  

 - platform: modbus_controller
   modbus_controller_id: srne1
   name: "Output Priority" #name for HA
   id: srne_output_priority #id for HA
   register_type: holding
   address: 0xE204 

 - platform: modbus_controller
   modbus_controller_id: srne1
   name: "Charger Priority" #name for HA
   id: srne_charger_priority #id for HA
   register_type: holding
   address: 0xE20F 

Since E204 support read write both, how can I change the value of that registry through Home Assistant?

What I want to do is to change the Output priority UTI, SBU, SOL through HA automation.
Is this possible?

I tried the following way

switch:
  - platform: template
    name: "Output Priority Switch"
    id: output_priority_switch
    turn_on_action:
      - modbus.write_register:
          id: tdt1_modbus
          address: 0xE204
          value: 1
    turn_off_action:
      - modbus.write_register:
          id: tdt1_modbus
          address: 0xE204
          value: 0

But it gives me the error

switch.template: [source /config/esphome/srne.yaml:52]
platform: template
name: Output Priority Switch
id: output_priority_switch
turn_on_action:

Unable to find action with the name ‘modbus.write_register’.
modbus.write_register:
id: tdt1_modbus
address: 57860
value: 1

How can I do this?
Please help

Esphome is beyond my knowledge unfortunately. I have no clue :confused:

1 Like

under the select section use this:

select:

  • platform: modbus_controller
    modbus_controller_id: srne
    id: Output_priority
    name: ${name}_Output_priority
    address: 0xE204
    value_type: U_WORD
    icon: mdi:power
    optionsmap:
    “SOL”: 0
    “UTI”: 1
    “SBU”: 2