Growatt Inverter Mode Switch

I use the Growatt integration in HA to get data on load, battery state of charge etc.

Data on charge status and changing charge status (telling the inverter to charge) is through app deamon.

I don’t have a description of the UI. I use node-red (image and code above) to control when to start and stop charging.
The entities used in node-red are then displayed and controlled from the UI in HA.

1 Like

Hi, @KasperEdw , would it be possible for you to offer a how to? Im a novice (literally installed Home assistant today)

I have the HA running and installed Growatt extension but thats as far as ive got. I would love to be able to set to bat first for example. I was even hoping to somehow trigger from the wholesale price of elec API.

thanks in advance

Hi there,

First of all - credits to @mjdyson, @KasperEdw, @muppet3000 and @indykoning for providing all the important pieces of the actual code. I too wanted to automate the charging of my Growatt battery, and without their work I wouldn’t be able to achieve that.

For the benefits of others in a similar situation, this is how I combined the different pieces together for my nightly routine (I am using HA running in Docker on Synology NAS):

  1. Installed AppDaemon and configured so it listens to my HA instance. I run AppDaemon in Docker, alongside my HA instance. AppDaemon with Docker — AppDaemon 4.2.1 documentation

  2. Deployed growattServer.py and set_charge_rate.py from mjdyson/ad-growatt (github.com) into …\appdaemon\conf\apps.

  3. Made sure that growattServer.py is referring to the right server URL; Growatt seems to have been switching between https://server.growatt.com/ and https://server-api.growatt.com/ recently.

  4. Next I modified the set_charge_rate.py module, so it better suited my needs (I wanted to call the set_charge_rate routine as a service from HA, only setting the Stop charging SoC %):

import growattServer
import appdaemon.plugins.hass.hassapi as hass

SET_CHARGE_RATE = 'SET_CHARGE_RATE'


class HouseBatteryCharge(hass.Hass):

  def initialize(self):
    self.listen_event(self.set_charge_rate, SET_CHARGE_RATE)


  def set_charge_rate(self, event, data, kwargs):

    stop_battery_soc = str(data['stop_battery_soc'])
...

Plus I added logging in various places of the ‘set_charge_rate’ function and made the #Stop charging SoC % the only variable in self.schedule_settings. I didn’t need any other variables, my charging time window is fixed by the cheaper night tariff provided by my energy supplier.

  1. The final piece of AppDaemon config was adding this entry into …\appdaemon\conf\apps\apps.yaml
set_charge_rate:
  module: set_charge_rate
  class: HouseBatteryCharge
  1. Then I configured HA to call my AppDaemon app - this 3-part blog was absolutely essential to understand how to do that: AppDaemon, next level home automation | Medium

  2. As a result, I added this entry into my HA scripts.yaml:

set_charge_rate:
  alias: Growatt Battery - Set Charge Rate
  sequence:
    - event: SET_CHARGE_RATE
      event_data:
        stop_battery_soc: "{{ stop_battery_soc }}"    
  1. Finally, in HA I configured a nightly automation which looks at the solar energy production forecast and then calls the script service (and passes the Stop charging SoC % as a variable), which then triggers the event, which AppDaemon is listening to and which then finally runs the set_charge_rate app. How to call the service and pass the variable:
- service: script.set_charge_rate
  data:
  stop_battery_soc: 70

Because the Growatt servers have been somewhat unreliable recently (even in the ShinePhone app I often get ‘Network Error’ and have to try several times to get the actual status), the automation makes the call twice (could be more frequently, if it runs OK it completes within 5 seconds). For ref, the complete automation logic:

alias: Set solar battery charging rate
description: ""
trigger:
  - platform: time
    at: "20:00:00"
condition: []
action:
  - repeat:
      count: 2
      sequence:
        - if:
            - type: is_energy
              condition: device
              device_id: 5c6093279048b524c3282a0040c49398
              entity_id: sensor.energy_production_tomorrow
              domain: sensor
              below: 10
              above: 0
          then:
            - service: script.set_charge_rate
              data:
                stop_battery_soc: 100
        - if:
            - type: is_energy
              condition: device
              device_id: 5c6093279048b524c3282a0040c49398
              entity_id: sensor.energy_production_tomorrow
              domain: sensor
              below: 20
              above: 10
          then:
            - service: script.set_charge_rate
              data:
                stop_battery_soc: 70
        - if:
            - type: is_energy
              condition: device
              device_id: 5c6093279048b524c3282a0040c49398
              entity_id: sensor.energy_production_tomorrow
              domain: sensor
              below: 30
              above: 20
          then:
            - service: script.set_charge_rate
              data:
                stop_battery_soc: 60
        - if:
            - type: is_energy
              condition: device
              device_id: 5c6093279048b524c3282a0040c49398
              entity_id: sensor.energy_production_tomorrow
              domain: sensor
              above: 30
          then:
            - service: script.set_charge_rate
              data:
                stop_battery_soc: 30
        - delay:
            hours: 0
            minutes: 1
            seconds: 0
            milliseconds: 0
mode: single

The sensor.energy_production_tomorrow is from Forecast.Solar integration.

Hope it helps!

PS I also run my own Grott instance, so have been wondering if it wouldn’t be more reliable to run the set_charge_rate against that. Not sure though whether is also listening to calls, or just forwarding calls from the inverter to growatt servers. I reckon it should be the former, but not sure.

1 Like

Thanks for sharing, this is really cool, especially as a HA integration.
I completely forgot this forum/chain existed for feature requests for Growatt.

I actually implemented some very similar functionality myself which you can find here: GitHub - muppet3000/growatt-weather-based-charger: A tool for configuring overnight charging (i.e. during off-peak periods) for Growatt inverters that have storage capacity (batteries) based on the predicted solar generation for the day it’s also available as a docker image that can be run as well.

My implementation took into account the maximum charging rate of the batteries as well i.e. if you can only fill them at 3kw, then the rest will be shoved out the door etc. etc.

Either way, it’s all really cool, just wanted to share my implementation (even if it sits completely outside of the home-assistant domain).

1 Like

Thanks for sharing too. I have something similar in mind (with two EVs in the mix), so thanks for the inspiration!

Hi guys

I am very interested in being able to switch my growatt SPH 3600 inverter on/off in HA and also be able to automate when the battery is charging from the grid.

I tried to follow the guide from @martinm, but unfortunately I cant make it work.

I’m not very skilled at all this, can anyone help me out with a more “simple” guide for newbies?

Thank you very much and great job!

Hi @kassand, how far did you get?

Hey Martinm

I followed your guide/post from OCT 28… But No luck so far

Kind regards

Hi @kassand - where did you get stuck?

Hey martinm

Thanks for the quick reply. Its some time ago, but one of my questions was, where do i find the “device_id”:

device_id: 5c6093279048b524c3282a0040c49398

And also, how do i get the stuff on a Card inside the overview?

Also in the mjdyson/ad-growatt (github.com), there are several files, do i only have to use the 2 files that you mention?
growattServer.py and set_charge_rate.py

I will test it out again during one of the next weekends, after that i got some more questions :slight_smile:

Once again thanks :+1:

Hello ,
This project is local and I’m working on implementing it right now.

Would someone be able to walk us through this? I set up home assistant yesterday for this purpose alone but have had no luck.

Cheers.

Hello all. I’ve dropped off this thread a bit, but have a bit of time to help over the next week or two.

Would anyone be interested in co-working on a wiki page that helps simplify the setup guide and perhaps a PR to add a readme into the Growatt integration? @martinm @KasperEdw ?

@muppet3000 AppDaemon can be a little tricky to get working - there are lots of different parts to configure and needs some coding experience. Do you have any appetite to build something into the integration directly that allows control in addition to the monitoring? I’m not sure what the minimum viable solution would be. Happy to discuss via smaller group / DM if needed.

Hi @mjdyson

I’m happy to be involved and advise where I can, adding the ability to configure the inverter i.e. for charging would be possible, however I’m currently working through the backlog list of items for the integration.
I’m maintaining a prioritised list of items here: Growatt Integration - Prioritised List of Features for Implementation/Fixing once I’ve worked through all of those maybe then I’ll turn my attention to allowing for things to be configured as well.
With regards to adding documentation, I also maintain that (and have been meaning to improve it) so I’m happy to review anything that is being added.

Right now though my spare time (what little of it that I have) is going to be focussed on completing that list, I’m slowly working through it so I’ll get there eventually :slight_smile:

Hey Mark - @mjdyson

Unfortunately I cant help you, because I dont know how to make this stuff work :slight_smile:

However I am very interested in testing your setup guide. And i will probably be the right person for this, because i know very little about all the coding stuff.

I really hope you will work something out, because i really want this feature…

Thank you very much and good job.

Same for me… Looks like @mjdyson might be the guy who can make it work for us :slight_smile:

1 Like

I’ll see what I can do. I have to update my code to use the latest growatt server code. I think I was half way through something any never came back to it. Fingers crossed I can get it working again. Currently it has a compile error! I have a little bit of time over the next week or two so should be able to get to it.

3 Likes

I too am not quite up to speed to make it work myself, only just dipping my toes into HA but would be really keen to try anything out and help test. Was going to have a go at the non HA version shared by @muppet3000 above as that’s exactly the use case I wanted to get to myself. Would be nice to have it “inside” HA.

With regards to adding something into HA, if I were to finally get around to adding the ability to make configuration changes then it would be quite generic. It would then be down to each user to configure it to be ‘automated’ as they needed e.g. Target battery charging, peak & off-peak times etc.

1 Like