ESPHome modbus Growatt ShineWiFi-S

hi.
This is the esphome code for Growatt SPF 5000 ES.

I’m using a d1 mini with a ttl converter.
This code allows changing the parameters of the inverter. BE CAREFUL !! (The worst thing that can happen is you have to configure the inverter again.)
The code has all the configurations that I was able to find, it doesn’t mean that they are all here.
The names are the factory names, I don’t change anything.
Thanks to all.

substitutions:
  device_name: inv1
  friendly_name: "inv1"
  device_description: "Growatt SPF 5000 ES"

esphome:
  name: '${device_name}'
  comment: '${device_description}'
  
esp8266:
  board: d1_mini

# Enable logging
logger:
  baud_rate: 0
  level: DEBUG
# Enable Home Assistant API
api:
  encryption:
    key: " your new api key " #     https://esphome.io/components/api.html


ota:
  safe_mode: true
  reboot_timeout: 10min
  num_attempts: 5
  
#web_server:
# port: 80


wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password
  reboot_timeout: 2min
  # Optional manual IP

  # Enable fallback hotspot (captive portal) in case wifi connection fails
#  ap:
#    ssid: '${device_name}'
#    password: !secret wifi_password
    
captive_portal:

time:
  - platform: homeassistant
    id: homeassistant_time

uart:
  id: mod_bus
  tx_pin: 1
  rx_pin: 3
  baud_rate: 9600
  #baud_rate: 115200
  debug:
    direction: RX
    dummy_receiver: false
    after:
      delimiter: "\n"
    sequence:
      - lambda: UARTDebug::log_string(direction, bytes);

modbus:
  id: modbus1
  uart_id: mod_bus
#  flow_control_pin: GPIO4

modbus_controller:
  - id: growatt
    address: 0x1
    modbus_id: modbus1
    setup_priority: -10  
#    update_interval: 30s 

text_sensor:
  - platform: template
    name: "${friendly_name} Status"
    icon: mdi:eye
    entity_category: diagnostic
    lambda: |-
      if ((id(status).state) == 1) {
        return {"Normal"};
      } else if ((id(status).state) == 0)  {
        return {"Standby"};
      } else if ((id(status).state) == 2)  {
        return {"Discharge"};
      } else if ((id(status).state) == 3)  {
        return {"Fault"};
      } else if ((id(status).state) == 4)  {
        return {"Flash"};
      } else if ((id(status).state) == 5)  {
        return {"PV Charging"};
      } else if ((id(status).state) == 6)  {
        return {"AC Charging"};
      } else if ((id(status).state) == 7)  {
        return {"Combined Charging"};
      } else if ((id(status).state) == 8)  {
        return {"Combined Charging & Bypass"};
      } else if ((id(status).state) == 9)  {
        return {"PV Charging & Bypass"};
      } else if ((id(status).state) == 10)  {
        return {"AC Charging & Bypass"};
      } else if ((id(status).state) == 11)  {
        return {"Bypass"};
      } else if (id(status).state == 12)  {
        return {"PV Charge and Discharge"};
      } else {
        return {"Unknown"};
      }

sensor:
  - platform: wifi_signal
    name: "WiFi Signal Sensor"
    update_interval: 60s
    
  - platform: modbus_controller
    address: 0
    register_type: "read"
    internal: true
    accuracy_decimals: 0
    id: status
    
#### temp ###
 
  - platform: modbus_controller
    name: "${friendly_name} Inverter Temperature"
    address: 25
    register_type: "read"
    unit_of_measurement: °C
    device_class: temperature
    entity_category: diagnostic
    state_class: measurement
    icon: mdi:thermometer
    value_type: U_WORD
    accuracy_decimals: 1
    filters:
    - multiply: 0.1
    
  - platform: modbus_controller
    name: "${friendly_name} PV Temperature"
    address: 32
    register_type: "read"
    unit_of_measurement: °C
    device_class: temperature
    state_class: measurement
    entity_category: diagnostic
    icon: mdi:thermometer
    value_type: U_WORD
    accuracy_decimals: 1
    filters:
    - multiply: 0.1

  - platform: modbus_controller
    name: "${friendly_name} DC‐DC Temperature "
    address: 26
    register_type: "read"
    unit_of_measurement: °C
    device_class: temperature
    entity_category: diagnostic
    state_class: measurement
    icon: mdi:thermometer
    value_type: U_WORD
    accuracy_decimals: 1
    filters:
    - multiply: 0.1

### ac input ### 

  - platform: modbus_controller
    name: "${friendly_name} AC Input Hz"
    address: 21
    register_type: "read"
    device_class: FREQUENCY
    unit_of_measurement: Hz
    entity_category: diagnostic
    state_class: measurement
    icon: mdi:flash
    value_type: U_WORD
    accuracy_decimals: 1
    filters:
    - multiply: 0.01

  - platform: modbus_controller
    name: "${friendly_name} AC Input Voltage"
    address: 20
    register_type: "read"
    unit_of_measurement: V
    device_class: VOLTAGE
    state_class: measurement
    entity_category: diagnostic
    icon: mdi:flash
    value_type: U_WORD
    accuracy_decimals: 1
    filters:
    - multiply: 0.1


  - platform: modbus_controller
    name: "${friendly_name} AC Charge Current"
    address: 68
    register_type: "read"
    unit_of_measurement: A
    device_class: CURRENT
    entity_category: diagnostic
    state_class: measurement
    icon: mdi:flash
    value_type: U_WORD
    accuracy_decimals: 1
    filters:
    - multiply: 0.1
    
  - platform: modbus_controller
    name: "${friendly_name} AC charge watt (low) "
    address: 14
    register_type: "read"
    unit_of_measurement: W
    device_class: POWER
    state_class: measurement
    entity_category: diagnostic
    icon: mdi:flash
    value_type: U_WORD
    accuracy_decimals: 2
    filters:
    - multiply: 0.1

  - platform: modbus_controller
    name: "${friendly_name} AC input watt (low) "
    address: 37
    register_type: "read"
    unit_of_measurement: W
    device_class: POWER
    state_class: measurement
    entity_category: diagnostic
    icon: mdi:flash
    value_type: U_WORD
    accuracy_decimals: 2
    filters:
    - multiply: 0.1
  - platform: modbus_controller
    name: "${friendly_name} AC charge Energy today  "
    address: 57
    register_type: "read"
    unit_of_measurement: KW
    device_class: POWER
    state_class: total_increasing
    entity_category: diagnostic
    icon: mdi:flash
    value_type: U_WORD
    accuracy_decimals: 2
    filters:
    - multiply: 0.1


## ac output ##

  - platform: modbus_controller
    name: "${friendly_name} Output active power (low) "
    address: 10
    register_type: "read"
    unit_of_measurement: W
    device_class: power
    state_class: measurement
    entity_category: diagnostic
    icon: mdi:flash
    value_type: U_WORD
    accuracy_decimals: 2
    filters:
    - multiply: 0.1

  - platform: modbus_controller
    name: "${friendly_name} AC output Volt"
    address: 22
    register_type: "read"
    unit_of_measurement: V
    device_class: voltage
    state_class: measurement
    entity_category: diagnostic
    icon: mdi:flash
    value_type: U_WORD
    accuracy_decimals: 1
    filters:
    - multiply: 0.1

  - platform: modbus_controller
    name: "${friendly_name} Output Current "
    address: 34
    register_type: "read"
    unit_of_measurement: A
    device_class: current
    state_class: measurement
    entity_category: diagnostic
    icon: mdi:flash
    value_type: U_WORD
    accuracy_decimals: 1
    filters:
    - multiply: 0.1

  - platform: modbus_controller
    name: "${friendly_name} AC discharge watt (low) "
    address: 70
    register_type: "read"
    unit_of_measurement: W
    device_class: power
    state_class: measurement
    entity_category: diagnostic
    icon: mdi:flash
    value_type: U_WORD
    accuracy_decimals: 1
    filters:
    - multiply: 0.1

## solar ##

  - platform: modbus_controller
    name: "${friendly_name} PV1 charge power (high) "
    address: 3
    register_type: "read"
    unit_of_measurement: Wh
    device_class: power
    state_class: measurement
    icon: mdi:solar-power
    value_type: U_DWORD
    accuracy_decimals: 1
    filters:
    - multiply: 0.1   

  - platform: modbus_controller
    name: "${friendly_name} PV1 voltage "
    address: 1
    register_type: "read"
    unit_of_measurement: V
    device_class: voltage
    state_class: measurement
    entity_category: diagnostic
    icon: mdi:flash
    value_type: U_WORD
    accuracy_decimals: 1
    filters:
    - multiply: 0.1
    
  - platform: modbus_controller
    name: "${friendly_name} Buck1 current"
    address: 7
    register_type: "read"
    unit_of_measurement: A
    device_class: current
    state_class: measurement
    entity_category: diagnostic
    icon: mdi:flash
    value_type: U_WORD
    accuracy_decimals: 1
    filters:
    - multiply: 0.1
 

  - platform: modbus_controller
    name: "${friendly_name} Epv1_today H"
    address: 48
    register_type: "read"
    unit_of_measurement: KW
    state_class: total_increasing
    device_class: energy
    icon: mdi:solar-power
    value_type: U_DWORD
    accuracy_decimals: 1
    filters:
    - multiply: 0.1    

        
## bat ## 


  - platform: modbus_controller
    name: "${friendly_name} Battery volt (M3)"
    address: 17
    register_type: "read"
    unit_of_measurement: V
    device_class: voltage
    state_class: measurement
    entity_category: diagnostic
    icon: mdi:flash
    value_type: U_WORD
    accuracy_decimals: 2
    filters:
    - multiply: 0.01


  - platform: modbus_controller
    name: "${friendly_name} Bus Voltage"
    address: 19
    register_type: "read"
    unit_of_measurement: V
    device_class: voltage
    state_class: measurement
    entity_category: diagnostic
    icon: mdi:flash
    value_type: U_WORD
    accuracy_decimals: 2
    filters:
    - multiply: 0.01

  - platform: modbus_controller
    name: "${friendly_name} fan speed"
    address: 82
    register_type: "read"
    unit_of_measurement: "%"
    device_class: POWER_FACTOR
    state_class: measurement
    entity_category: diagnostic
    icon: mdi:flash
    value_type: U_WORD
    accuracy_decimals: 0
    filters:
    - multiply: 1

####  TTL RS485   ####

select:
  - platform: modbus_controller
    name: "${friendly_name} Charge Source"
    address: 01
    value_type: U_WORD
    optionsmap:
      "Pv Priority": 0
      "Pv&Uti": 1
      "Only Pv": 2

  - platform: modbus_controller
    name: "${friendly_name} Output Source"
    address: 02
    value_type: U_WORD
    optionsmap:
      "Bat Priority": 0
      "Pv Priority": 1
      "Uti Priority": 2
      "Pv&Uti Priority": 3
  - platform: modbus_controller
    name: "${friendly_name} Uti Output Start Time"
    address: 03
    value_type: U_WORD
    optionsmap:
      "0h": 0
      "1h": 1
      "2h": 2
      "3h": 3
      "4h": 4
      "5h": 5
      "6h": 6
      "7h": 7
      "8h": 8
      "9h": 9
      "10h": 10
      "11h": 11
      "12h": 12
      "13h": 13
      "14h": 14
      "15h": 15
      "16h": 16
      "17h": 17
      "18h": 18
      "19h": 19
      "20h": 20
      "21h": 21
      "22h": 22
      "23h": 23
  - platform: modbus_controller
    name: "${friendly_name} Uti Output End Time"
    address: 04
    value_type: U_WORD
    optionsmap:
      "0h": 0
      "1h": 1
      "2h": 2
      "3h": 3
      "4h": 4
      "5h": 5
      "6h": 6
      "7h": 7
      "8h": 8
      "9h": 9
      "10h": 10
      "11h": 11
      "12h": 12
      "13h": 13
      "14h": 14
      "15h": 15
      "16h": 16
      "17h": 17
      "18h": 18
      "19h": 19
      "20h": 20
      "21h": 21
      "22h": 22
      "23h": 23
  - platform: modbus_controller
    name: "${friendly_name} Uti Charge Start Time"
    address: 05
    value_type: U_WORD
    optionsmap:
      "0h": 0
      "1h": 1
      "2h": 2
      "3h": 3
      "4h": 4
      "5h": 5
      "6h": 6
      "7h": 7
      "8h": 8
      "9h": 9
      "10h": 10
      "11h": 11
      "12h": 12
      "13h": 13
      "14h": 14
      "15h": 15
      "16h": 16
      "17h": 17
      "18h": 18
      "19h": 19
      "20h": 20
      "21h": 21
      "22h": 22
      "23h": 23
  - platform: modbus_controller
    name: "${friendly_name} Uti Charge End Time"
    address: 06
    value_type: U_WORD
    optionsmap:
      "0h": 0
      "1h": 1
      "2h": 2
      "3h": 3
      "4h": 4
      "5h": 5
      "6h": 6
      "7h": 7
      "8h": 8
      "9h": 9
      "10h": 10
      "11h": 11
      "12h": 12
      "13h": 13
      "14h": 14
      "15h": 15
      "16h": 16
      "17h": 17
      "18h": 18
      "19h": 19
      "20h": 20
      "21h": 21
      "22h": 22
      "23h": 23
  - platform: modbus_controller
    name: "${friendly_name} PV Input Mode"
    address: 07
    value_type: U_WORD
    optionsmap:
      "Independent": 0
      "Parallel": 1
  - platform: modbus_controller
    name: "${friendly_name} AC Input Mode"
    address: 08
    value_type: U_WORD
    optionsmap:
      "APL,90‐280VAC": 0
      "UPS,170‐280VAC": 1    
  - platform: modbus_controller
    name: "${friendly_name} Output Volt Type"
    address: 18
    value_type: U_WORD
    optionsmap:
      "208 VAC": 0
      "230 VAC": 1    
      "240 VAC": 2  
  - platform: modbus_controller
    name: "${friendly_name} Output Freq Type"
    address: 19
    value_type: U_WORD
    optionsmap:
      "50 Hz": 0
      "60 Hz": 1    
  - platform: modbus_controller
    name: "${friendly_name} Over Load Restart"
    address: 20
    value_type: U_WORD
    optionsmap:
      "Yes": 0
      "No": 1    
      "Swith to UTI": 2    
  - platform: modbus_controller
    name: "${friendly_name} Over Temperature Restart"
    address: 21
    value_type: U_WORD
    optionsmap:
      "Yes": 0
      "No": 1    
  - platform: modbus_controller
    name: "${friendly_name} Buzzer on/off enable"
    address: 22
    value_type: U_WORD
    optionsmap:
      "Enable": 0
      "Disable": 1    
  - platform: modbus_controller
    name: "${friendly_name} Maximum Ac Charge Current"
    address: 38
    value_type: U_WORD
    optionsmap:  # 0 - 99
      "5": 5
      "10": 10
      "15": 15
      "20": 20
      "25": 25
      "30": 30
      "35": 35
      "40": 40
      "45": 45
      "50": 50
      "55": 55
      "60": 60
      "65": 65
      "70": 70
      "75": 75
      "80": 80
      "85": 85
      "90": 90
      "95": 95
  - platform: modbus_controller
    name: "${friendly_name} Bat Low Volt Switch To Uti"
    address: 37
    value_type: U_WORD
    optionsmap: # check manual 44 - ??
      "44,0": 440
      "44,2": 442
      "44,6": 446
      "44,8": 448
      "45,0": 450
      "45,2": 452
      "45,4": 454
      "45,6": 456
      "45,8": 458
      "46,0": 460
      "46,2": 462
    #   ...       ...    check the range in the manual
 
 - platform: modbus_controller
    name: "${friendly_name} Mains to battery operating point"
    address: 95
    value_type: U_WORD
    optionsmap: 
      "48,0": 480
      "48,2": 482
      "48,4": 484
      "48,6": 486
      "49,0": 490
      "49,2": 492   
      "49,4": 494   
      "49,6": 496   
      "49,8": 498  
      "50,0": 500   
      "51,0": 510   
      "52,0": 520  
    #   ...       ...    check the range in the manual
4 Likes

So cool! Thanks for sharing.
I will give this a go. Is there no youtube tutorial about this? :slight_smile:

I don’t think so.

Screenshot of the parameters.

kBw3zL0
6X9zhDk

2 Likes

And thanks to you I now have immediate local control over the parameters on my SPH 10k-TL3 BH-UP I was most interested in:

select:
  - platform: modbus_controller
    name: "${devicename} AC Charging"
    icon: mdi:battery-charging-100
    address: 1092
    value_type: U_WORD
    optionsmap:
      "Disabled": 0
      "Enabled": 1

  - platform: modbus_controller
    name: "${devicename} Inverter Priority"
    icon: mdi:arrow-decision-outline
    address: 1044
    value_type: U_WORD
    optionsmap:
      "Load First": 0
      "Battery First": 1
      "Grid First": 2

Tested, works exactly as expected… this means I can finally build proper logic around low/high tariff use from grid (i.e. I can charge the battery at night using low tariff and then use it during high tariff period - that alone can save quite a few $ around here), be able to prepare for a planned outage and eventually when the market catches up and we can actually sell for spot prices, I can do that too…

Thanks!

2 Likes

This is really a game changer for the battery mangement. I’m going to do the same, using the production forecast I will charge or not the battery, and use the low tariff to charge wen need.

I’ve been waiting for such a solution for a long time, I’m testing it and it works fine.
Thanks !!

Hello Pavel,
do you have found a solution for this problem? Seems i have the same problem.
Greetings
Izi1

Thanks for info. I have ordered two types of converters, now waitng for them to arrive and test.
Until then i am stuck with standard integration with data update from server at 5min.

Hi goodmorning,

Thanks for sharing this.
I read the most of this thread and have ‘your’ version up and running now.
Original Shine WiFi-X stick and flashed with the yaml.
Got rid of the sensors I didn’t have and running in HA now.
Working with the MIC 3000 TL-X.

Thanks to Chris Huitema and Wilbert Verhoeff for helping me pointing in the right direction.

Pieter, what If you add external power to the stick?
5V ( USB Power ) soldered to the board?

Hi izi, no, I did not manage to get it working. Tried two different boards (esp8266 and esp32), two different RS485 converters, different pins (1-5, 4-5), different RS485 settings (VPP, unused) in all possible combinations, but nothing. There is no data coming on RX pin (LED does not blink). I will try the code from candidotsa but I am afraid it will not work. Probably the RS-485 connector is failed or the communication is somehow disabled.

Hi. Jumper You’re rs485 connection is RJ 45? Did you tried the pin 7&8? 7 for A and 8 for B.

Hi caro7372. The code is the same from the 5000es?

I used the next one as found above:

You can try to connect your converter and ESP32 to Easton SDM 630 smart meter if you have that installed and flash the ESP32 with Eastron SDM code. You will see some of the parameters provided by Growatt from there since the invertor is taking data form the smart meter. Here you can find info:

I did not try it myself, but i am planning to do it once i will receive the RS485 to TTL converter.

Hi guys, I also tried ShineBus software directly from Growatt (downloaded from here: Software - Growatt Italia), using the USB/RJ45 cable, but again no data read from the inverter. It is a mistery.

Hi. Did you tried the pin 7 and8?

1 Like

I ordered the same setup - what hardware did you use to talk to the inverter? Esp32, TTL, type of cable? Would you mind sharing a picture? Got a bit confused looking at all the different varieties on this forum but i know for sure I want to be able to do what you do :grinning: - eg. Buy low sell high

The best way I would describe my setup is “always the first link on Aliexpress”…

2 Likes

Thanks, and the white cable is a standard CAT5/6 ethernet cable with an RJ45 directly into the inverter? Think I will manage thanks!:+1: