Save solar power for the evening peak: Growatt control in Home Assistant

Growatt hybrid inverter and 10 kWh battery

I have installed Home Assistant in three properties: a year-round home and two summer houses. All three have solar panels and a Growatt hybrid inverter with a battery. I have therefore been working on controlling the inverters so that I avoid drawing power from the grid during the evening peak.

Between 5 pm and 9 pm, electricity is significantly more expensive than during the rest of the day in Denmark. The grid operators’ tariff rises during exactly this period, and the spot price is typically higher as well. That is why there is the most to save by having power in the battery when the evening peak hours begin.

There are two ways to do this. The battery can be charged from the grid when electricity is cheap, or you can save the power the sun has charged into the battery during the day. However, I am not convinced that the extra wear on the battery from overnight charging is worth the gain, and I have most recently chosen not to do it. The control is therefore only about saving the power the sun charges into the battery during the day for the evening peak, so that it is not used on ordinary consumption earlier in the day.

To do this, Home Assistant has to estimate two things: how much power the solar panels will deliver, and how much power the house will use up to and during the evening peak. Solar production is estimated with a forecast from Solcast. For consumption, one thing matters more than anything else: whether anyone is in the house. In the year-round home, which has district heating, the difference in electricity consumption between occupied and unoccupied is not that large. The summer houses, on the other hand, are heated with electricity from air-to-air heat pumps and electric radiators, and they have electric underfloor heating in the bathrooms. Here, winter consumption depends entirely on whether anyone is in the house and whether the heating is on.

There are ready-made Danish solutions that control Growatt inverters automatically based on consumption history, electricity prices and solar forecasts. I have chosen to build the control myself in Home Assistant. In the summer houses, consumption depends first and foremost on whether anyone is in the house, and in Home Assistant I can use the signals I already have directly in the forecast: heating mode, EV charging, barrier and motion.

I have described the method for reading and controlling the Growatt inverter in another article. This article builds on it.

Load First and an adjustable lower limit

The inverter runs in Growatt’s Load First mode. This means that the house’s consumption is covered first by the solar panels, any surplus charges the battery, and power is only bought from the grid when neither sun nor battery is enough. In other words, the battery is only charged from the sun.

The reservation is controlled with the discharge-stop-SOC setting, which is the lower limit for how far the battery may be discharged. Normally it is set low, so the battery can be used freely. If the limit is raised to the level the battery is at right now, discharging stops. The power then stays in the battery until the evening peak, without the battery having to be charged an extra time. All Home Assistant does is turn the limit up and down. This causes no wear on the battery.

Two decisions a day

The limit is adjusted twice a day:

  • At 9 pm, right after the evening peak, a calculation is made for the next day. The starting point is the battery’s current state of charge. From there, it is calculated block by block up to 5 pm the next day: expected solar minus expected consumption, limited by the battery’s capacity and lower limit. If the result is less power in the battery than the evening peak’s expected consumption minus expected solar, discharging is stopped right away.
  • At 9:30 am, right after the morning peak, the same calculation is made for the rest of the day. If a shortfall is still expected, the level is held. If not, the limit is lowered again so the battery can be used freely.

The morning peak does not have its own reservation.

The consumption forecast is the core

The forecast is based on 14-day rolling averages, split into five time blocks: night (00–07:30), morning peak (07:30–09:30), day (09:30–17), evening peak (17–21) and late evening (21–24). Each block has one average for occupied and one for unoccupied, giving a total of ten averages per house.

The averages are built with a utility meter (utility_meter) that has a tariff for each of the ten combinations. An automation switches tariff when a time block ends or when the status changes, so that consumption is allocated precisely down to the minute. At midnight, each block is only added to the 14-day list if it is “clean”, meaning that power was used under only one status. Blocks from arrival and departure days, where both statuses occur, are skipped. This costs a few data points, but the averages are not skewed by half days.

The 14 days were chosen to follow the seasons. A summer house with electric heating does not use the same amount in winter as in summer, and a longer average would mix the two together.

EV charging is included in the house’s consumption and is not kept out of the calculation. A single large charging session can therefore pull the average for that block up somewhat. On the other hand, the averages automatically reflect when charging typically happens, without requiring a separate model. Here I have prioritised simplicity over precision.

Signals for occupied and unoccupied

In all three houses, the status is shown in a virtual on/off switch: on means occupied, and off means unoccupied. The switch can always be set manually, and it remembers its state after a restart. Various automatic signals can change the state.

Most signals are more reliable in one direction than the other. It is easy to see that someone has arrived, but harder to see that they have left. A phone that drops off wifi might just as well be on the beach. That is why several of the signals are only allowed to act in the safe direction. The houses use different signals, depending on what equipment was already in place.

Heating mode

The heating mode is used in all three houses and is the strongest signal, because it is chosen deliberately. Switching on heating or air conditioning sets the house to occupied, and 10 °C frost protection on the heat pump and radiators sets it to unoccupied. Switching off the heat pump and heating changes nothing, since that is also a summer mode.

The EV plugged into the charger sets the house to occupied, but only on a new connection. Unplugging the cable does not say enough about departure.

A barrier at the driveway with a Zigbee door sensor is used in one of the summer houses. Here the signal works both ways, because the barrier is only opened on arrival and closed on departure. It is the simplest and most precise signal, but it only works because the household’s habits suit it.

Smartphones on wifi are used in the year-round home. The Nmap Tracker integration scans the network and recognises the phones by their MAC address. “Home” takes effect immediately and sets the state to occupied. “Away”, on the other hand, is only checked just before midnight, and the state is only changed to unoccupied if the heating mode is not set to Heat or Cool and the car is not plugged in. A day trip that ends before midnight therefore never sets the house to unoccupied.

Lenovo tablet running Fully Kiosk

A tablet as a motion sensor is used in the other summer house. The Lenovo tablet runs Fully Kiosk, which uses the front camera to detect motion and turns on the screen when someone walks past. The screen state is available in Home Assistant through the Fully Kiosk integration, and when the screen turns on, it is registered as motion. If the tablet has not registered any motion since 5 pm, the house is set to unoccupied, but only if the heat pump and heating are switched off and the car is not plugged in.

If you set the house to unoccupied from the dashboard before leaving, motion and phones are ignored for a period. That gives you time to leave the house without it being registered as occupied again.

Equipment

Home Assistant Green, a ready-made hardware device designed to run Home Assistant

Growatt hybrid inverters with battery, read and controlled via SunMate’s Home Assistant integration.

Zaptec Go 2, EV charger with Home Assistant integration. Plugging in the cable is used as an arrival signal.

SONOFF SNZB-04P, Zigbee door sensor on the driveway barrier.

Lenovo tablet as a Home Assistant wall panel and motion sensor.

About the code

This article describes the principles behind the setup, not the specific Home Assistant automations. The exact code depends on the installation in any case: entity names, the names of the heating modes, which signals are available, and how the house is used. The automations can be generated with AI if it is given the prerequisites described above.