Beginners Guide: Automating Inverter actions with GivTCP in Home Assistant

35 comments started 2024-10-03 last 2025-09-11
Home AutomationHome Assistant
G
#1 geoffreycoan

It comes up a few times "how do I automate my inverter to do X outside of the GivEnergy Portal/App"

So to help others out, I am sharing how I do X in Home Assistant. There are of course other ways to achieve inverter automation, cloud services like WonderWatt, full battery management systems like Predbat, using the GivLocal HA integration or calling the inverter API's directly yourself.

This covers using GivTCP to automate certain actions in Home Assistant. It assumes you already have Home Assistant running and have installed and got GivTCP running. If you need help with GivTCP and Mosquitto install then there is a walkthrough of the process in the Predbat documentation https://springfall2008.github.io/batpred/inverter-setup/#givenergy-with-givtcp and a useful 'speak to the geek' video although this video is based on GivTCP v2 and there are changes in the latest version 3 (see changes highlighted in the Predbat documentation).

I do my control of the inverter by using Home Assistant scripts for each task, that way I can call the scripts as and when I want to either manually or from an automation.

My scripts have evolved over time and they are now very 'belt and braces' in that they assume nothing about the current inverter state and will configure every aspect of the inverter to ensure that the action works as I want it to. Doubtless some of these control settings could be omitted, but they are what they are.

Also worth highlighting that there are "quick action" controls in GivTCP that can be used to do a force charge or a force discharge for a number of minutes. These do work as expected but I don't use them in my scripts, I do it the 'old fashioned' way of setting the low level controls I need. These controls are select.givtcp_SERIALNO_force_charge and select.givtcp_SERIALNO_force_export - simply choose the desired time duration, 2, 15, 30, 60 minutes, etc from the dropdown.

To create a script in Home Assistant it's Settings / Automations & Scenes / Scripts
Add Script / Create new script / three dots top right / edit in YAML

Then paste my script in.

To run a script in an automation, Add action / type 'script' then choose your script name from the list presented

I'll add each script as a separate comment below.

G
#2 geoffreycoan

Force charge script:

alias: Inverter Force Charge
sequence:
  - data:
      option: Normal
    target:
      entity_id:
        - select.givtcp_SERIALNO_temp_pause_charge
    action: select.select_option
  - data:
      value: "100"
    target:
      entity_id:
        - number.givtcp_SERIALNO_target_soc
    action: number.set_value
  - data:
      option: "00:00:00"
    target:
      entity_id:
        - select.givtcp_SERIALNO_charge_start_time_slot_1
    enabled: true
    action: select.select_option
  - data:
      option: "23:59:00"
    target:
      entity_id:
        - select.givtcp_SERIALNO_charge_end_time_slot_1
    enabled: true
    action: select.select_option
  - data:
      option: Eco
    target:
      entity_id:
        - select.givtcp_SERIALNO_mode
    enabled: true
    action: select.select_option
  - delay:
      seconds: 20
  - data:
      value: "2600"   XX or your own max inverter charge rate
    target:
      entity_id:
        - number.givtcp_SERIALNO_battery_charge_rate
    action: number.set_value
  - data:
      option: Running
    target:
      entity_id:
        - select.givtcp_SERIALNO_force_charge
    action: select.select_option
  - data: {}
    target:
      entity_id:
        - switch.givtcp_SERIALNO_enable_discharge
    action: switch.turn_off
description: Force a full rate battery charge
mode: single
icon: mdi:battery-charging-30
G
#3 geoffreycoan

Stop charging or discharging, put the inverter into Eco mode:

alias: Inverter Eco Mode
description: Return the inverter to Eco mode, cancel any forced charge or discharge
sequence:
  - data:
      option: Normal
    target:
      entity_id:
        - select.givtcp_SERIALNO_force_charge
    action: select.select_option
  - delay:
      seconds: 20
  - data:
      option: Eco
    target:
      entity_id:
        - select.givtcp_SERIALNO_mode
    action: select.select_option
  - data: {}
    target:
      entity_id:
        - switch.givtcp_SERIALNO_enable_discharge
    action: switch.turn_on
  - data:
      value: "2600"  XX or your own inverter max charge/discharge rate
    target:
      entity_id:
        - number.givtcp_SERIALNO_battery_discharge_rate
        - number.givtcp_SERIALNO_battery_charge_rate
    action: number.set_value
  - data:
      value: "4"
    target:
      entity_id:
        - number.givtcp_SERIALNO_battery_power_reserve
    action: number.set_value
  - data: {}
    target:
      entity_id:
        - switch.givtcp_SERIALNO_enable_charge_schedule
        - switch.givtcp_SERIALNO_enable_discharge_schedule
    action: switch.turn_off
  - data:
      option: "00:00:00"
    target:
      entity_id:
        - select.givtcp_SERIALNO_charge_start_time_slot_1
        - select.givtcp_SERIALNO_charge_end_time_slot_1
        - select.givtcp_SERIALNO_discharge_start_time_slot_1
        - select.givtcp_SERIALNO_discharge_end_time_slot_1
    action: select.select_option
  - metadata: {}
    data:
      option: Disabled
    target:
      entity_id:
        - select.givtcp_SERIALNO_battery_pause_mode
    action: select.select_option
mode: single
icon: mdi:battery-lock-open
G
#4 geoffreycoan

Force discharge script:

alias: Inverter Force Discharge
description: Force a full rate battery discharge and export of excess power
sequence:
  - data:
      option: "00:00:00"
    target:
      entity_id: select.givtcp_SERIALNO_discharge_start_time_slot_1
    action: select.select_option
  - data:
      option: "23:59:00"
    target:
      entity_id: select.givtcp_SERIALNO_discharge_end_time_slot_1
    action: select.select_option
  - data:
      value: "2600"  XX or your own inverter max discharge rate
    target:
      entity_id: number.givtcp_SERIALNO_battery_discharge_rate
    action: number.set_value
  - data:
      value: "4"
    target:
      entity_id: number.givtcp_SERIALNO_battery_power_reserve
    action: number.set_value
  - delay:
      seconds: 15
  - data:
      option: Disabled
    target:
      entity_id: select.givtcp_SERIALNO_battery_pause_mode
    action: select.select_option
  - delay:
      seconds: 5
  - data:
      option: Timed Export
    target:
      entity_id: select.givtcp_SERIALNO_mode
    action: select.select_option
mode: single
icon: mdi:battery-minus-outline
#5 miffy

Thanks so much for pasting in the above.
I have a problem though. What are you supposed to do when HA refuses to save the yaml you've pasted in? I've gone back into the script and pasted it again and again and again, but then there is no save button. So now I have three named scripts, contents empty.
This is all I end up with for all three scripts:

G
#6 geoffreycoan

miffy you'll need to make some minor edits to the scripts above when you have pasted them in before they can save:

  • change all the SERIALNO bits to your inverter serial number
  • where I have lines marked 'XX or your own inverter max discharge/charge', that's a note to highlight that the value I have used is 2600 (2.6kW) for my gen 1 inverter, change that to the appropriate value for your inverter and delete the XX and the rest of the line

I suspect these are why the scripts won't save for you as they are not valid YAML with the XX note in them

#7 miffy

geoffreycoan Ahh, my husband figured out the problem. I was copying your code, popping it into Notepad to make the edits, then pasting that into HA. But this method messed up the tabs. Once reformatted to fix the tabs, it's saving successfully.
[We fixed it by getting the Microsoft CoPilot AI to fix the yaml formatting for us!]

It's late, so I'll faff with HA again tomorrow. Thanks again.

G
#8 geoffreycoan

miffy Yes YAML is very sensitive about formatting and indentation. Best to not try editing it in notepad

Glad you sorted although I wonder what Microsoft AI thought of my code!

V
#9 Vestas

Probably worth pointing out that for most things you don't need to use YAML - there's a "visual" editor where you can select triggers, conditions and actions....

S
#10 SteveCook

Editing in YAML scares me so I go - Settings - Automations and Scenes and then Create Automation.
Summary window and example below.

#11 miffy

Vestas Yes, that's true. However a new HA user like myself has no chance of being able to create something like this without a lot of help.

S
#12 SteveCook

miffy looks far more complicated way than my example. Regards Steve

#13 miffy

SteveCook Ohh, I'm coming to hate HA. Every time someone shows me how they have theirs set up, mine looks nothing like what they have, and the options they talk about do not exist!

Looking at your first screenshot, you have
Then do:
Perform action 'GivEnergy Local: Activate timed export mode' on Solar Inverter

Where the heck do you find that in the drop down? I don't have anything that looks like that in the options. If I could find the options you show, this would be easy.

S
#14 SteveCook

TBH i just blundered around until i found what I thought would work. I think I went.
Settings - Automations and scenes - Create Automation.
I then clicked on the "when" and put a time.
I then went to "then do" and found("add action") a prewritten action "enable timed charging" and then clicked on my inverter.

NB i have GivTCP and MQTT installed.

I ran these for about a year and then installed Predbat and now just let Predbat do everything, however If I ever crash Predbat (my incompetence with fiddling).I just enable them in 10 seconds

W
#15 Weasel

On a tangentially related topic, I have written a couple of automations that trigger when the current Octopus import cost crosses a threshold. This enables me to easily turn on/off certain devices during higher cost periods.

I will post them up on a new thread once I am happy with them.

PS. I use predbat and it is awesome

G
#16 geoffreycoan

miffy Looking at your first screenshot, you have
Then do:
Perform action 'GivEnergy Local: Activate timed export mode' on Solar Inverter

Where the heck do you find that in the drop down? I don't have anything that looks like that in the options. If I could find the options you show, this would be easy.

@miffy @SteveCook is using GivEnergy Local which is a different integration that talks to the inverter, it’s not the same as GivTCP so the options are quite different. I think there’s probably more people using GivTCP than GivEnergy Local and I do know that GivTCP now supports newer kit like multiple AIO’s and 3-phase inverters (albeit the 3 phase doesn’t work fully with Predbat still). No idea about GivEnergy local.

As I said in the preamble there are lots of different ways of doing things in HA and I was outlining how I do it. Even with GivTCP there are the select controls that can be used to force a discharge or charge for a set period of time that can be used as an alternative.

My approach mimics what the GivEnergy app does when you do the quick play charge or discharge, and is similar to what Predbat uses to control the inverter.

S
#17 SteveCook

geoffreycoan Geoffrey. Thanks. Shows how incompetent I am. Regards Steve

#18 miffy

SteveCook Yeah, I still hate HA. I have GivTCP and MQTT installed. I have set up dashboards in HA that show what my system is doing, which uses both those plugins. But I simply cannot find any setting or option or whatever that talks about enable timed charging. 🙁

Darn it, just seen @geoffreycoan 's reply. Okay, thanks for clarifying. I'll look into GivEnergy Local too. I haven't had time yet to use the scripts in automations, hopefully later today.

Thanks so much for the help, this HA stuff is really getting me down. I don't understand why it's made so complicated.

W
#19 Weasel

miffy I think the problem with HA is that it is a techie framework and not complete solution in itself. If you like tinkering with programming-type things, then HA is great (I love it, I am a geek/nerd/propellor-head).

To provide a timed charging capability in HA, I would write two scripts - one for the start and one for the end of the timed period. Each script would take the necessary actions using GivTCP entities. However, a solution this simple would potentially conflict with predbat if you are using it, so I am sure there would be more to it that I have just stated.

G
#20 geoffreycoan

Weasel would potentially conflict with predbat if you are using it

Correct. Predbat controls the battery according to its forecasted plan. If you want to do something that Predbat hasn’t planned then you either need to set predbat into read only mode and then you can do what you want to, or there are select.manual_xxxx controls that you can force Predbat to charge, idle the battery, discharge, etc at specific time slots.

W
#21 Weasel

In that case running a script each day that sets the relevant predbat switches/controls would seem to be the way to go. I have manually set up extra forced charging periods using the UI and it has served me well. Automating them by creating a periodic script shouldn't be too difficult

L
#22 Leeshore

Weasel I'm slightly techie but would have struggled without the excellent instructions and also @geoffreycoan

G
#23 geoffreycoan

Weasel here's a script I used last year when Predbat had a habit of doing a force discharge at 3pm just before my export price override for the DFS saving session.

I put a delay between each command to give Predbat time to recognise the first action before sending a second rather than banging them in one after another and Predbat missing one:

alias: "Predbat: stop 3pm discharge"
description: ""
trigger:
  - platform: time
    at: "23:00:00"
action:
  - data:
      option: "15:00:00"
    target:
      entity_id:
        - select.predbat_manual_idle
    action: select.select_option
  - delay:
      minutes: 1
  - data:
      option: "15:30:00"
    target:
      entity_id: select.predbat_manual_idle
    action: select.select_option
mode: single
A
#24 Annaka

I find using Node Red within Home Assistant, so much easier for simple and some quite complexed automations. There is a bit of a learning curve, but I honestly believe its worth it ...rather than messing with yaml or the automation editor.

G
#25 geoffreycoan

Annaka I have done some stuff with node red in the past, not in Home Assistant, and you can certainly do some very powerful functions and logic flows.

Of course with Home Assistant it’s another add-on to have running which adds to memory and CPU overhead whereas the YAML scripting in Home Assistant is native.

Part of the reason I shared the scripts was the hard work I’d done in formulating them, they can be treated as ‘black boxes’ and all that’s then needed is the automation as to when to trigger them.

Anyway, lots of ways to do things with Home Assistant !

W
#26 Weasel

That's what I like about these communities, learning new stuff and techniques. I am HA newbie and have never heard of Node Red, so I have just installed to see what it's all about. I have 40 years professional IT and programming experience so am capable of writing my automation in YAML, but I think Node Red might help me quickly develop prototypes before tweaking and/or rewriting in YAML if desired

#27 PianSom

Weasel I think Node Red might help me quickly develop prototypes before tweaking and/or rewriting in YAML if desired

Node Red is great.

But if you haven't tried it out then have a look at getting one of the new AI tools to produce yaml (or any other) code for you. You can just type a command like "Produce Home Assistant yaml code which <insert random task here>".

I find it simply mind-blowing. One of my mates is a Chair in Statistics. I showed him how to ask ChatGPT to develop R code to run a specific test he wanted to do. His mind was blown too! It's the best way I have ever seen of producing a first cut of code.

B
#28 Brotchaq

Thanks for these scripts - giving them a go now!

#29 miffy

Thanks to @SteveCook and @geoffreycoan I now have HA successfully controlling my GE inverter. 🙂 Woohoo!
I'm using a combination of GivTCP and GivEnergy Local to create rules, and after a lot of faffing, testing, and tweaking, they are working as intended! I'm sure there are better ways to do some of my rules, but I did a thing and it works!

The biggest headache was getting HACS installed which was necessary to install GivEnergy Local.

I decided I don't need to use PredBat. I treat each day as an isolated entity, are on the Octopus Flux tariff, and have written my rules for this scenario.

G
#30 geoffreycoan

Great news, and a great sense of satisfaction I bet

#31 miffy

geoffreycoan Something I can't figure out how to do with HA is Pause and unPause the battery. Specifically, this setting:

What I am doing instead is setting the Battery Discharge Rate to 0. However, ideally I'd just pause the battery.
Any ideas?

G
#32 geoffreycoan

miffy In the givtcp configuration you need to set 'use old firmware' to OFF and then you'll get some additional sensors including Battery Pause Mode.

Setting discharge rate to zero sort of works but setting pause mode as well is more reliable.

#33 miffy

geoffreycoan
That was it! Thanks so much, found that switch now. 🙂

D
#34 dcsh

As a recent home assistant user, but a Givenergy customer for 5 years, I was wondering if there was a way to get the historic data from the Givenergy cloud into home assistant? Or even just simple historic pv generation data?

G
#35 geoffreycoan

[unknown] As a recent home assistant user, but a Givenergy customer for 5 years, I was wondering if there was a way to get the historic data from the Givenergy cloud into home assistant? Or even just simple historic pv generation data?

There is. I have developed some procedures to do just this, and will be sharing them soon