Solar & Batteries in Home Assistant

0 Shares
0
0
0
0

Solar panels, batteries and EVs are some of the fastest growing markets worldwide as the green revolution grips us all. The problem, like every new industry is that there are lots of players, and everyone has a different way of doing it. When I say it, I mean automation of course!

It’s 2024, you’re trying to be a new-age eco warrior… or just had your solar array and battery installed. Congrats – you’re doing the planet a good deed. But you want to maximise your investment right? This gear isn’t cheap. Whether it’s Solax, SolarEdge, GivEnergy or whoever, their automations are kinda basic. And to add to that, you have a load of smart devices you want to run when you’re going to produce loads of power, maybe you want to know when to charge your EV, maybe you want to run your dishwasher at the he cheapest time, the list goes on. Lets automate…

Electricity Tariff

In the UK (I assume in most countries) you can choose a different energy supplier, and each supplier has a differing set of tariffs, some using variable rates (based on demand), some with cheap imports overnight (when demand is low) and some that provide the same price no matter when you use electricity.

But you’ve got solar panels, they produce electricity right! Right! Well yeah, they do – but if you can’t use that power right when you produce it, you export it to the grid (paid or unpaid) or store in a battery for when you do need it…

To begin some clever automation, being blunt – you need to use a supplier that exposes their data – you need to be able to gather information automatically when things change (unit prices, daily standing charge). Secondly, to maximise savings, a tariff with a variable rate, whether thats a unit price that changes every 30 mins or has ‘cheaper times’. In the UK, Octopus Energy are very much the leaders in this area but there are other supplier too, like OVO Energy who are providing alternatives. Here are a few example tarriffs:

Batteries and Inverters

Home batteries are exactly what they sound like, essentially a way of storing energy until you need it. They are the same thing that you find in electric vehicles (EVs) and can be charged by solar or by the grid.

Inverters are where the clever bit happens – they are brains of the operation. They take the DC (variable direct current) that comes from your solar panels and convert it to AC (alternating current) which allows the appliances in your home to consume it, 230V for us in the UK and EU, 120V/240V for you folks in the US.

OK, so science and geography lesson over because that inverter does more than just covert current, it determines how much energy it can provide at once (could be 3600W, 5000W, 7500W, etc) something that is important to know when you design your system. So in addition to this, these inverters have gotten a little ‘smart’ with APIs to allow them to be controlled (when to charge, discharge, etc), integrations into Electricity supplier APIs, EV charger integration, etc. This, for me is super important when you decide to buy a battery/inverter – and choosing a forward thinking manufacturer is important. I’ve listed a few here who are highly regarded

  • Telsa (Battery: Powerwall & Solar Inverter)
  • GivEnergy (All-in-One, or Battery and Hybrid Inverter)
  • Solax (Battery System and Energy Storage Inverter)

Before I go on, just for reference and so you’re aware, this what I currently run at home:

  • 2x Solar Arrays (combined 4.56kW)
    • S-SW facing 8x 400W panels (3.20KW)
    • E-SE facing 4x 340W panels (1.36kW)
  • 1x GivEnergy Gen 2 Hybrid 5KW Inverter
  • 9.5KW GivEnergy Battery
  • 7kW / 32A AC GivEnergy EV Charger

Where Home Assistant can help

Some of these manufacturers are building some super-cool systems but they only partner with one or a couple of the energy suppliers, and those integrations aren’t exactly perfect. Ensuring you firstly know roughly what your solar array will produce on any given day is important, because it then may determine how much you want to pull from the grid, it may determine whether you charge your EV that day, or when or not you run the washing machine, dryer and dishwasher.

Thankfully, Home Assistant can help – with some more, pretty awesome community led projects. Let’s look at the stack:

GivTCP: Talks to your inverter and pulls statistics back on battery and inverter data

Solcast: Uses geo-location of solar panels and weather data to predict solar production

PredBat: Battery prediction and automatic charging

Forecasting Energy Production – Solcast

Solcast is a great free-for-use API, as long as you set it up properly and can be used for more than just predicting solar production. Either way, lets concentrate on getting it set up correctly.

Register here for hobbyist access – limited to 2 ‘sites’ (could be 2 different roofs) and 10 polls per day (combined) – resets at midnight UTC

Configure your roof(s), you’ll need to provide details such as:

  • Longitude/Latitude
  • Array capacity (total output
  • Inverter capacity
  • Roof tilt
  • Azimuth (roof direction in degrees)
  • Solar efficiency (decreased with solar panel age)

Get an API key from here once you’ve finished configuring your array. If you have more than 1 roof/array – follow this guide here for creating a second site.

Now we need to go into Home Assistant and get the data in via API.

Download solcast addon (via HACS) here

  1. Click Here to directly add a Solcast Solar integration or
    a. In Home Assistant, go to Settings -> Integrations
    b. Click + Add Integrations and select Solcast PV Forecast
  2. Enter your Solcast API Key
  3. Click Submit

Next we need to create an automation to regularly bring in the latest data. As usual we need to go Settings > Automations (you’ll get used to this!)

Create a regular update automation (remembering you only have 10 polls per day) I could go as low as every 2.4hrs, but the below does every 4 hours.

alias: "Action: Solcast Update"
description: ""
trigger:
  - platform: time_pattern
    hours: /4
condition: []
action:
  - service: solcast_solar.update_forecasts
    metadata: {}
    data: {}
mode: single

Once you’ve saved the automation, run it and within a minute or two you should be able to see some output against the solcast service (Settings > Devices and Services > Solcast Service). It shoud look a little something like this:

If you’ve added more than one ‘PV system’, i.e. you have more than 1 roof with solar on, you’ll see w separate entitin the diagnostic section, 2 separate entities, 1 for each roof. As you can see though – there is a lot of data and a lot of entities that are very useful.

Inverter Data – GivTCP

GivTCP is yet another community developed addon which is super easy to install, and gives tonnes of data on what your inverter is doing, however this is geared towards GivEnergy Inverters only however there are other addons for other vendor inverters such as Solax, Solaredge or even Tesla Powerwalls.

Before installing GivTCP, its a pre-req that you have a MQTT broker already installed – if you’ve been following my blogs – then you will have done this for the HA – Frigate install here. If not, just find Mosquitto broker in the add-ons store, and install that.

To install GivTCP, go into Settings > Add-ons, into the Add-ons store and add the repository for GivTCP here. Once you’ve added the repository, search for GivTCP and install

Before starting the add-on, you’ll need switch to the Configuration tab on the add-on page to provide some details on your Inverter.

You’ll need to know some basic information about your home setup, such as the number of inverters (most folk only have 1), the number of batteries, the inverter IP address (you can probably find this info on your inverter phone app, or router).

You’ll then need to provide the username and password for your mqtt broker so that it can pass the info into a mqtt topic.

There are plenty of other options here, such as forecasting (which hopefully you’ve done with Solcast above) and providing your tariff information (should you want to). Mine looks a little like this (I’ve cut out anything where its not switched on or configured).

Once you’ve saved your config, go ahead and start the service on the ‘info’ tab.

Within a few mins, go into Settings > Devices and Services > Entities and search for GivTCP, you should see a huge list of entities that are being pulled from your Inverter ranging from static info such as battery capacity, firmware versions and battery type, to more dynamic statistics such as battery cell temperatures, charge time, and grid to battery stats amongst many others.

Thankfully, Home Assistant gives you more than that. If you look on your left hand menu bar, you’ll see a tab called Energy. If you go into that, into the top right hand corner and click the 3 dots, and select Energy Configuration.

Under Grid consumption, click the pencil and type in “Grid Import Energy Today”

Under Return to grid, click the pencil and type in “Grid Export Energy Today”

These will give you the details for how much you’ve pulled from the grid, and how much you’ve exported to the Grid. You can provide details on the rate (if you get a flat rate for import and export) to provide further details if you wish

Onto the Solar panels card…

Under Solar production, click the pencil and type in “PV Energy Today” and also under forecasting select Solcast Solar.

This will provide you with accurate figures for how much energy your solar panels have produced, but will also use your Solcast data to forecast ahead of time.

Lastly onto the Battery card, click the pencil under Battery systems and put “Battery Discharge Energy Today” in the top field and “Battery Charge Energy Today” in the bottom field. This will give you the data on the battery charging and discharging throughout the day.

Once this is done, click back into the Energy dashboard on the left hand bar and within a couple of hours, this should start producing some really meaningful data that you can absolutely add on to your own dashboard. I’ve also used another addon for gas usage (I’m an Octopus Energy customer for reference) so I’ve also added that.

As always, here’s a brief look at mine:

Inverter Automation – Predbat

So we’ve can now predict solar production using Solcast, we can see actual data from our inverters using GivTCP, now we need to do some proper automation. Step forward Predbat!

Written by the quite awesome Trefor Southwall it essentially does battery prediction and automation for a number of different makes such as GivEnergy, Solis, Huawei, SolarEdge and Sofar. In short, it’s purpose is to try and save you money by optimising when to charge and discharge your battery and boy is it clever!

I’m not going to go through detailed instructions because Trefor has not only provided detailed ones on his website here but as recently as June 2024, he even produced a YouTube video walking you through it. For reference, the Github link to his project is here.

What I will do though, is point you in the directions of the rather good templates here. By default it’s set up for GivEnergy inverters, but there are lots of others.

A few hints, are firstly to ensure that you have GivTCP or equivalent set up first, and if you’re an Octopus Energy customer – making sure you have your tariff set up – using either BottleCapDave’s addon here or if you’re an Agile user like me, oatybiscuits NodeRed based addon here. If its not obvious by the install videos and guides too, having a file editor installed is kinda mandatory too 🙂

As long as you’ve not modified the names of the entities, Predbat should pick them all up by default, otherwise you’ll need to edit your apps.yaml config

The other, well hidden automation that is very well hidden in the instructions is a handy ready-made automation to monitor all the components needed for predbat to work are operating correctly. These can be found here.

OK, so hopefully you’ve got it installed, and you’ve got a load of funky entities (that start with predbat_ if you’ve kept with the default templates). Just like anything in HA, you can use those entities in any cards or automations.

Included by Trefor is a number of ready-made charts (using the apex-charts addon) showing some really interesting stats such as cost saving, solar intake amongst others when you let predbat come out of monitoring mode (it’s default). These are really useful for a dashboard, as it lets you know at a glance what your inverter will be doing throughout the day and the impact of using a significant amount of energy. It also gives you a ‘control panel’ which you can use to switch it out of monitor mode and into control mode when you’re happy with the predictions. Here are a few examples:

The above chart gives you an idea of cost using different models that predbat provides.

Despite me using some basic automation that came with the inverter, You can see the savings that predbat has given me over my inverter built-in automation and no doubt you’d see a lot more if you haven’t used any automation at all – and its not even been a full month.

There are also some really nice third party cards to show exactly what predbat is doing on a day-to-day basis if graphs really aren’t your thing. Predbat-Table-Card can be added using HACS and is a highly-customisable table to show exactly what Predbat is predicting, why and how much its costing you

tl:dr

Sorry, this was a super-long post, but honestly, it wasn’t long enough for 2 posts and I think it takes you through managing your energy end-to-end, saving you money in the process. I hope this is useful to one or two of you out there, and as always – feel free to reach out if you want to know more 🙂

0 Shares