ESPHome modbus Growatt ShineWiFi-S

I got this working really easily with my shinewifi-S and Growatt 3000-S inverter. However, my Growatt inverter shuts itself off when there is no power from the solar panels. Which leaves my total energy produced today set to unavailable, which means I cannot add a simple ‘this was todays energy production’ to my main dashboard. After lots of threads with complicated setups to fix this, I decided this needs a simple SQL sensor:

select * 
from states 
where entity_id = 'sensor.growatt_today_s_generation' 
    and state != 'unavailable' 
    and state != 'unknown' 
order by state_id desc 
limit 1;

Then select the state column for the sensor value, and set units of measurement to kWh. This always shows the last value of today’s generation, updated every 30 seconds. This every 30 seconds makes it less efficient than event based, but also much more simple to setup. A second SQL sensor showing total power can also be added.

This works - but has someone found a better way to mark these two sensors as never being unavailable, instead of this trick?

Also I think it would be nice if the default accuracy of the total_energy_produced and energy_production_day sensor of ESPhome would be single decimal, as it appears to be in every example I could find in this thread. So I created Default decimal accuracy for total generated power is incorrect · Issue #3888 · esphome/issues · GitHub . Any input on whether this is correct for more inverter types than mine?

What is the config that you use? What is your history looks like? It seems it gets a big number somewhere. It is fixable in analytics but of course not how it is meant to be.

For now I have managed just to read info from SPF5000ES. It is connected to port usb-A.
This is the adapter used:image

Hi.

Sorry for the late reply.

My config is:

substitutions:
  devicename: "esphome-growatt-01"
  upper_devicename: "ESPHome Growatt 01"

esphome:
  name: growatt

esp8266:
  board: esp07s

# Enable logging
logger:
  baud_rate: 0

# Enable Home Assistant API
api:

ota:
  password: "fb53133b1e3dea138dfbbbee8d3e6653"

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Growatt Fallback Hotspot"
    password: "sR4TFWhJzHBT"

  # Enable Web server
web_server:
  port: 80

captive_portal:
    
time:
  - platform: homeassistant
    id: homeassistant_time

output:
# Blue Led
  - id: light_bl
    platform: gpio
    pin: 16
# Green Led
  - id: light_gr
    platform: gpio
    pin: 0
# Red Led
  - id: light_rd
    platform: gpio
    pin: 2

uart:
  id: mod_bus
  tx_pin: 1
  rx_pin: 3
  baud_rate: 115200
  
modbus:
  id: modbus1
  uart_id: mod_bus
  
modbus_controller:
  - id: growatt
    ## the Modbus device addr
    address: 0x1
    modbus_id: modbus1
    setup_priority: -10  


sensor:
  - platform: modbus_controller
    name: "${devicename} DcPowerPV1"
    address: 5
    register_type: "read"
    unit_of_measurement: W
    device_class: power
    icon: mdi:flash
    value_type: U_DWORD
    accuracy_decimals: 1
    filters:
    - multiply: 0.1
    
  - platform: modbus_controller
    name: "${devicename} DcPowerPV2"
    address: 10
    register_type: "read"
    unit_of_measurement: W
    device_class: power
    icon: mdi:flash
    value_type: U_WORD
    accuracy_decimals: 1
    filters:
    - multiply: 0.1
    
  - platform: modbus_controller
    name: "${devicename} DcVoltage"
    address: 3
    register_type: "read"
    unit_of_measurement: V
    device_class: voltage
    icon: mdi:flash
    value_type: U_WORD
    accuracy_decimals: 1
    filters:
    - multiply: 0.1
    
  - platform: modbus_controller
    name: "${devicename} DcInputCurrent"
    address: 4
    register_type: "read"
    unit_of_measurement: A
    device_class: current
    icon: mdi:flash
    value_type: U_WORD
    accuracy_decimals: 1
    filters:
    - multiply: 0.1
    
  - platform: modbus_controller
    name: "${devicename} AcFrequency"
    address: 37
    register_type: "read"
    unit_of_measurement: Hz
    icon: mdi:flash
    value_type: U_WORD
    accuracy_decimals: 1
    filters:
    - multiply: 0.01
  
  - platform: modbus_controller
    name: "${devicename} AcVoltage"
    address: 38
    register_type: "read"
    unit_of_measurement: V
    device_class: voltage
    icon: mdi:flash
    value_type: U_WORD
    accuracy_decimals: 1
    filters:
    - multiply: 0.1
  
  - platform: modbus_controller
    name: "${devicename} AcOutputCurrent"
    address: 39
    register_type: "read"
    unit_of_measurement: A
    device_class: current
    icon: mdi:flash
    value_type: U_WORD
    accuracy_decimals: 1
    filters:
    - multiply: 0.1
    
  - platform: modbus_controller
    name: "${devicename} AcPower"
    address: 40
    register_type: "read"
    unit_of_measurement: W
    device_class: power
    icon: mdi:flash
    value_type: U_DWORD
    accuracy_decimals: 1
    filters:
    - multiply: 0.1
    
  - platform: modbus_controller
    name: "${devicename} EnergyToday"
    address: 53
    register_type: "read"
    unit_of_measurement: kWh
    device_class: energy
    icon: mdi:flash
    value_type: U_DWORD
    accuracy_decimals: 1
    filters:
    - multiply: 0.1
    
  - platform: modbus_controller
    name: "${devicename} EnergyTotal"
    address: 55
    register_type: "read"
    unit_of_measurement: kWh
    state_class: total_increasing
    device_class: energy
    icon: mdi:flash
    value_type: U_DWORD
    accuracy_decimals: 1
    filters:
    - multiply: 0.1

    
  - platform: modbus_controller
    name: "${devicename} Temperature"
    address: 3093
    register_type: "read"
    unit_of_measurement: C
    device_class: temperature
    icon: mdi:thermometer
    value_type: U_WORD
    accuracy_decimals: 1
    filters:
    - multiply: 0.1

My history looks like this:


december

I really cant say what is causing this. -But my theory is that the inverter maybe switches between on-/offline a couple of times during the odd days which leads to an accumulating value? (My total production so far is only 97.4 kWh and my reading from the inverter seems correct and accumulating with no spikes).

17/12-22 EDIT: today it happended again. It seems to show exactly 4x the total production of my inverter when this occurs.

Manage to flash both my sticks S + X via VSCode with the PlatformIO plugin… The S was connected with a USB-TTL CP2102 converter, RX-TX needed NOT to be crossed and baudrate needed to be lowered to 115200.
Could not get them flashed with my MBPro M1, the device was found but timeout while flashing perhaps due to the USB-C to USB conversion? So I used a x86 Intel NUC with Ubuntu (again with VSCode) which worked fine. Both devices now show their graphs nicely when connecting to their IP.

I do have a question about the integration in HA, whenever I add the below to my configuration.yaml the configuration check hangs and it does not want to restart (I did not force it since it will probably not come up).
So am I missing some integration? some modbus support somewhere?

modbus:
  id: modbus1
  uart_id: mod_bus
  flow_control_pin: GPIO4

modbus_controller:
  - id: growatt
    address: 0x1
    modbus_id: modbus1
    setup_priority: -10

Would it be possible to re-flash the usb dongle, but still keep sending data to server.growatt.com?

That way the app still works. In case my home assistant hobby ends sooner than the inverter lifetime :slight_smile:

1 Like

(post deleted by author)

Please familiarise yourself with this and this.

I’m having trouble setting the powerfactor. I’ve got all sensors working and can even read holding address 3 with the powerfactor but the code below does not work.

<code language== “YAML” >
number:

  • platform: modbus_controller
    modbus_controller_id: growatt3000
    id: pv_powerfactor3000
    name: “PV inverter Power factor Growatt 3000”
    address: 0x3
    value_type: U_WORD
    lambda: "return x; "
    write_lambda: |-
    ESP_LOGD(“main”,“Modbus Number incoming value = %f”,x);
    uint16_t powerfactor = x ;
    payload.push_back(powerfactor);
    return x;

I get this response:

[13:23:54][D][number:054]: ‘PV inverter Power factor Growatt 3000’ - Setting number value
[13:23:54][D][number:113]: New number value: 99.000000
[13:23:54][D][main:070]: Modbus Number incoming value = 99.000000
[13:23:54][D][number:012]: ‘PV inverter Power factor Growatt 3000’: Sending state 99.000000
[13:23:55][D][modbus_controller:029]: Modbus command to device=1 register=0x00 countdown=0 no response received - removed from send queue
[13:23:56][D][text_sensor:067]: ‘Growatt3300 Status’: Sending state ‘Unknown’
[13:24:10][D][modbus.number:023]: Number new state : 100.00

And the number value goes back to 100 percent. What do I do wrong?

Hi,
First of all, thanks for all the hard work.
Question: I have a SPH-5000 inverter, connected to an SDM230-Modbus meter (connected by RJ45), in order to get house consumption data besides the production data. All the data us being sent by my Shine Wifi-S stick to growatt servers (with grott in the middle).
Using this method, will I be able to define sensors in ESPHome for all the data? I mean, not only for the production but also for the consumption data?

For anyone with SPH 10k-TL3 BH-UP here’s what worked for me for keeping the original USB stick and connections to the Growatt cloud and local updates every 10s. There are obviously far more values in the registers, I set up just what I was interested in…

HW:
ESP32
MAX3485 TTL/RS485

ESP32 pins tx/rx connected to the RS485 module, Pins 1 & 5 on the RS485-3 RJ-45 port on the inverter go to B & A on the RS485 module.

ESPHome config:

substitutions:
  devicename: Growatt
  esp_name: ESP Growatt #Device Name
  update_fast: 10s
  update_slow: 60s
  esp_hostname: "esp-growatt"
  ip_address: 192.168.5.104
  ip_gw: 192.168.5.1
  ip_netmask: 255.255.255.0


esphome:
  name: ${esp_hostname}

esp32:
  board: esp32dev
  framework:
    type: arduino

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password
  manual_ip:
    static_ip: ${ip_address}
    gateway: ${ip_gw}
    subnet: ${ip_netmask}
  ap:
    ssid: "${esp_name} Fallback Hotspot"
    password: !secret ap_password

ota:
  password: !secret ota_password

# Enable logging
logger:
  baud_rate: 0

# Enable Home Assistant API
api:
  encryption:
    key: !secret api_key

captive_portal:

web_server:
  port: 80
  include_internal: true  

uart:
  id: mod_bus
  tx_pin: 1
  rx_pin: 3
  baud_rate: 9600
 
modbus:
  id: modbus1
  uart_id: mod_bus
  
modbus_controller:
  - id: growatt
    address: 0x1
    modbus_id: modbus1
    update_interval: ${update_fast}
    setup_priority: -10    

button:
  - platform: restart
    name: "${esp_name} Restart"

# Setup for Growatt SPH 10k-TL3 BH-UP
sensor:
  - platform: modbus_controller
    name: "${devicename} Inverter Status"
    address: 0
    register_type: "read"
    icon: mdi:home-lightning-bolt
    value_type: U_WORD

  - platform: modbus_controller
    name: "${devicename} Input Power"
    address: 1
    register_type: "read"
    unit_of_measurement: W
    device_class: power
    state_class: measurement
    icon: mdi:solar-power-variant
    value_type: U_WORD
    accuracy_decimals: 0
    filters:
    - multiply: 0.1

  - platform: modbus_controller
    name: "${devicename} PV1 Power"
    id: pv1_power
    address: 5
    register_type: "read"
    unit_of_measurement: W
    device_class: power
    state_class: measurement
    icon: mdi:solar-power-variant
    value_type: U_DWORD
    accuracy_decimals: 0
    internal: true    
    filters:
    - multiply: 0.1

  - platform: modbus_controller
    name: "${devicename} PV2 Power"
    id: pv2_power    
    address: 9
    register_type: "read"
    unit_of_measurement: W
    device_class: power
    state_class: measurement
    icon: mdi:solar-power-variant
    value_type: U_DWORD
    accuracy_decimals: 0
    internal: true
    filters:
    - multiply: 0.1        

  - platform: template
    id: pv_power
    name: "${devicename} PV Power"
    unit_of_measurement: W
    device_class: power
    state_class: measurement
    icon: mdi:solar-power-variant
    accuracy_decimals: 0
    lambda: |-
      return float((id(pv1_power).state + id(pv2_power).state));
    update_interval: ${update_fast}

  - platform: modbus_controller
    name: "${devicename} Output Power"
    address: 35
    register_type: "read"
    unit_of_measurement: W
    device_class: power
    state_class: measurement
    icon: mdi:home-lightning-bolt
    value_type: U_DWORD
    accuracy_decimals: 0
    filters:
    - multiply: 0.1

  - platform: modbus_controller
    id: pv1_energy_today
    name: "${devicename} PV1 Energy Today"
    address: 59
    register_type: "read"
    unit_of_measurement: kWh
    device_class: energy
    state_class: total_increasing
    icon: mdi:solar-power-variant
    value_type: U_DWORD
    accuracy_decimals: 1
    internal: true    
    filters:
    - multiply: 0.1
  
  - platform: modbus_controller
    id: pv1_energy_total  
    name: "${devicename} PV1 Energy Total"
    address: 61
    register_type: "read"
    unit_of_measurement: kWh
    device_class: energy
    state_class: total_increasing
    icon: mdi:solar-power-variant
    value_type: U_DWORD
    accuracy_decimals: 1
    internal: true    
    filters:
    - multiply: 0.1

  - platform: modbus_controller
    id: pv2_energy_today
    name: "${devicename} PV2 Energy Today"
    address: 63
    register_type: "read"
    unit_of_measurement: kWh
    device_class: energy
    state_class: total_increasing
    icon: mdi:solar-power-variant
    value_type: U_DWORD
    accuracy_decimals: 1
    internal: true    
    filters:
    - multiply: 0.1
  
  - platform: modbus_controller
    id: pv2_energy_total
    name: "${devicename} PV2 Energy Total"
    address: 65
    register_type: "read"
    unit_of_measurement: kWh
    device_class: energy
    state_class: total_increasing
    icon: mdi:solar-power-variant
    value_type: U_DWORD
    accuracy_decimals: 1
    internal: true    
    filters:
    - multiply: 0.1

  - platform: template
    id: pv_energy_today
    name: "${devicename} PV Energy Today"
    unit_of_measurement: kWh
    device_class: energy
    state_class: total_increasing
    icon: mdi:solar-power-variant
    accuracy_decimals: 1
    lambda: |-
      return float((id(pv1_energy_today).state + id(pv2_energy_today).state));
    update_interval: ${update_slow}

  - platform: template
    id: pv_energy_total
    name: "${devicename} PV Energy Total"
    unit_of_measurement: kWh
    device_class: energy
    state_class: total_increasing
    icon: mdi:solar-power-variant
    accuracy_decimals: 1
    lambda: |-
      return float((id(pv1_energy_total).state + id(pv2_energy_total).state));
    update_interval: ${update_slow}

  - platform: modbus_controller
    name: "${devicename} Inverter Temperature"
    address: 93
    register_type: "read"
    unit_of_measurement: °C
    device_class: temperature
    state_class: measurement    
    icon: mdi:thermometer
    value_type: U_WORD
    accuracy_decimals: 1
    filters:
    - multiply: 0.1  

  - platform: modbus_controller
    name: "${devicename} Battery Discharging Power"
    address: 1009
    register_type: "read"
    unit_of_measurement: W
    device_class: power
    icon: mdi:battery-arrow-down
    value_type: U_DWORD
    accuracy_decimals: 0
    filters:
    - multiply: 0.1    

  - platform: modbus_controller
    name: "${devicename} Battery Charging Power"
    address: 1011
    register_type: "read"
    unit_of_measurement: W
    device_class: power
    icon: mdi:battery-arrow-up-outline
    value_type: U_DWORD
    accuracy_decimals: 0
    filters:
    - multiply: 0.1 

  - platform: modbus_controller
    name: "${devicename} Battery SoC"
    address: 1014
    register_type: "read"
    unit_of_measurement: "%"
    icon: mdi:home-battery
    value_type: U_WORD
    accuracy_decimals: 0

  - platform: modbus_controller
    name: "${devicename} AC Power to User Total"
    address: 1021
    register_type: "read"
    unit_of_measurement: W
    device_class: power
    state_class: measurement
    icon: mdi:transmission-tower-export
    value_type: U_DWORD
    accuracy_decimals: 0
    filters:
    - multiply: 0.1

  - platform: modbus_controller
    name: "${devicename} AC Power to Grid Total"
    address: 1029
    register_type: "read"
    unit_of_measurement: W
    device_class: power
    state_class: measurement
    icon: mdi:transmission-tower-import
    value_type: U_DWORD
    accuracy_decimals: 0
    filters:
    - multiply: 0.1

  - platform: modbus_controller
    name: "${devicename} INV Power to Local Load Total"
    address: 1037
    register_type: "read"
    unit_of_measurement: W
    device_class: power
    state_class: measurement    
    icon: mdi:home-import-outline
    value_type: U_DWORD
    accuracy_decimals: 0
    filters:
    - multiply: 0.1

  - platform: modbus_controller
    name: "${devicename} Battery Temperature"
    address: 1040
    register_type: "read"
    unit_of_measurement: °C
    device_class: temperature
    state_class: measurement    
    icon: mdi:thermometer
    value_type: U_WORD
    accuracy_decimals: 1
    filters:
    - multiply: 0.1

  - platform: modbus_controller
    name: "${devicename} Battery State"
    address: 1041
    register_type: "read"
    icon: mdi:home-battery
    value_type: U_WORD

  - platform: modbus_controller
    name: "${devicename} Energy to User Today"
    address: 1044
    register_type: "read"
    unit_of_measurement: kWh
    state_class: total_increasing
    device_class: energy
    icon: mdi:transmission-tower-export
    value_type: U_DWORD
    accuracy_decimals: 1
    filters:
    - multiply: 0.1
    
  - platform: modbus_controller
    name: "${devicename} Energy to User Total"
    address: 1046
    register_type: "read"
    unit_of_measurement: kWh
    state_class: total_increasing
    device_class: energy
    icon: mdi:transmission-tower-export
    value_type: U_DWORD
    accuracy_decimals: 1
    filters:
    - multiply: 0.1

  - platform: modbus_controller
    name: "${devicename} Energy to Grid Today"
    address: 1048
    register_type: "read"
    unit_of_measurement: kWh
    state_class: total_increasing
    device_class: energy
    icon: mdi:transmission-tower-import
    value_type: U_DWORD
    accuracy_decimals: 1
    filters:
    - multiply: 0.1

  - platform: modbus_controller
    name: "${devicename} Energy to Grid Total"
    address: 1050
    register_type: "read"
    unit_of_measurement: kWh
    state_class: total_increasing
    device_class: energy
    icon: mdi:transmission-tower-import
    value_type: U_DWORD
    accuracy_decimals: 1
    filters:
    - multiply: 0.1

  - platform: modbus_controller
    name: "${devicename} Battery Discharge Today"
    address: 1052
    register_type: "read"
    unit_of_measurement: kWh
    state_class: total_increasing
    device_class: energy
    icon: mdi:battery-arrow-down
    value_type: U_DWORD
    accuracy_decimals: 1
    filters:
    - multiply: 0.1

  - platform: modbus_controller
    name: "${devicename} Battery Discharge Total"
    address: 1054
    register_type: "read"
    unit_of_measurement: kWh
    state_class: total_increasing
    device_class: energy
    icon: mdi:battery-arrow-down
    value_type: U_DWORD
    accuracy_decimals: 1
    filters:
    - multiply: 0.1

  - platform: modbus_controller
    name: "${devicename} Battery Charge Today"
    address: 1056
    register_type: "read"
    unit_of_measurement: kWh
    state_class: total_increasing
    device_class: energy
    icon: mdi:battery-arrow-up-outline
    value_type: U_DWORD
    accuracy_decimals: 1
    filters:
    - multiply: 0.1

  - platform: modbus_controller
    name: "${devicename} Battery Charge Total"
    address: 1058
    register_type: "read"
    unit_of_measurement: kWh
    state_class: total_increasing
    device_class: energy
    icon: mdi:battery-arrow-up-outline
    value_type: U_DWORD
    accuracy_decimals: 1
    filters:
    - multiply: 0.1

  - platform: modbus_controller
    name: "${devicename} Local Load Today"
    address: 1060
    register_type: "read"
    unit_of_measurement: kWh
    state_class: total_increasing
    device_class: energy
    icon: mdi:home-import-outline
    value_type: U_DWORD
    accuracy_decimals: 1
    filters:
    - multiply: 0.1

  - platform: modbus_controller
    name: "${devicename} Local Load Total"
    address: 1062
    register_type: "read"
    unit_of_measurement: kWh
    state_class: total_increasing
    device_class: energy
    icon: mdi:home-import-outline
    value_type: U_DWORD
    accuracy_decimals: 1
    filters:
    - multiply: 0.1  
4 Likes

Hi Plawa,
I have an exact configuration as you do: 10k Growatt inverter, ESP32 board and MAX 485/TTL module. Tried your esphome code but there are no readings received from the inverter. I’am not sure about the pins - eventhough 1 and 5 are mentioned in the documentation, If I measure the voltage on these pins (connected to RS485-3 port on the inverter) there is only 15 mV but should be like 200 mV. Strange. Could you please check the RS485 settings one the invertor? It is under Basic parameters/RS485 Adr/COM Address, you can get to the settings menu by long press of the OK button next to inverter display? I have 001 there, not sure if this is the right value.

Attaching the screenshot with the log.

Any help or advise is appreciated.

Ahoj Pavle :slight_smile:

I checked my inverter config, it’s set to 001, plus when I measure the voltage across the pins I’m using I get ~1.7V… from what I have read it can either be pin 1&5 or 4&5, see if that works for you.

Hodne stesti…

Hi Plawa, I tried pins 1&5 and 4&5, also tried two diffeent boards - ESP8266 and ESP32 with two different RS485/UART modules but with no success. Seems like there is no data coming from the RS485-3 connector. Maybe it must be enabled somewhere in the invertor settings but I have no clue of where to do it. Will investigate it a bit further. Thanks a lot. Pavel

Hi Plawa! I will like to see what model of RS 485 you have used. Can you post a picture with your setup?
Regarding HA Card, what card did you use? Is looking very nice. Thanks!

There is an on-screen menu for configuring the RS485. Hold down the OK button for a couple of seconds until it says “Basic Parameters”, and then you can navigate to RS485 settings. (SPH10000-TL3)

Hi Christoffer, yes, I am anware of this settings. We checked with Plawa in an offline communication that his settings is “unused” (other are ShineMaster, VPP and Meter2). For me having set “unused” does not help either. Will investigate furhter over the weekend but seems I am stuck with no ovious reason.

1 Like

Hello there, im going to buy a SPH3600, i can see that you have export to grid information, is that provided by the GroWatt inverser or dou you use something else?

Thanks

Hi, I got the first MAX3485 hit I got on Aliexpress (the red one with angled pins)…

The graph is just the custom mini graph lovelace card, nothing special

That is provided by my inverter but I can’t obviously guarantee it will be provided by yours…