By Per Frank-Hansen
This article is based on a system description from May 2026. The author’s house, 190 m² over two floors plus a 110 m² basement, dates from 1950, and the system covers solar panels, battery, underfloor heating, and a Swedish property without solar panels.
Purpose and principle
The system manages the house’s energy consumption based on solar production, battery status, electricity prices, expected consumption, and whether anyone is home. The goal isn’t maximum automation for its own sake, but affordable comfort: warm floors, hot water, and low imports, without putting critical functions at risk. So it’s about optimizing comfort and economy, not pure energy efficiency.
I tried several AI-driven energy management tools, but they were too generic and too poor at handling my specific priorities: comfort, battery wear, local operation, and manual fallback.
Home Assistant gathers data from the inverter, electricity meter, prices, sensors, and weather forecasts. Node-RED calculates energy budgets and decides which loads are allowed to run, as well as when the battery should charge or discharge.
The house and the system
The house: 190 m² over 2 floors, 110 m² basement. Relatively well insulated for its age. Built in 1950. Consumption before the system and solar panels: 1,700 m³ of gas and 7,000 kWh of electricity.
Solar system: 6.4 kW of panels, a 10 kW Growatt SPH inverter, 23 kWh battery. The panel area was chosen based on what could be fitted neatly on the roof — maximum production isn’t the only consideration.
Notable detail: About 40 m² of flooring has both electric and water-based heating. The rest is radiators. There’s an immersion heater in the hot water tank.
The system: Home Assistant with Node-RED integration runs on a dedicated Intel NUC. The devices are a mix of Sonoff Wi-Fi, Sonoff Zigbee, Shelly, Tuya, and various other brands. An alarm system (Verisure), Ikea Trådfri, and Philips Hue are also integrated. I’m in the process of cutting down the number of brands in use — today it’s mostly Shelly for Wi-Fi and Sonoff for Zigbee, with Zigbee devices managed via ZHA.
Many of the on/off devices are plugs that can be physically removed so the function runs manually — meaning my descendants won’t need to be engineers to live in the house. I aim to document everything, and to run as much as possible locally without intermediaries harvesting data. Most dedicated cloud hubs have now been phased out; the exceptions are the inverter itself (for warranty and service reasons) and the alarm system.
Themed dashboards give an overview of what’s happening and easy access to control parameters.

Comfort and convenience are given high priority — the system’s job is, in particular, to keep that comfort as cheap as possible.
I don’t know whether the system could have been built in HA alone, but I find Node-RED easier to keep an overview of. It’s easier for me to write code in a function node than to get HA automations to behave.
Data sources
- Inverter data via Solax Modbus
- Electricity meter data from the Kamstrup meter’s HAN port (a data output on the meter that provides local readings)
- Electricity prices from Nordpool and EDS
- PV forecast from Solcast
- Temperatures, humidity, and device status from Home Assistant
- Presence via pinging mobile phones
Data comes in via integrations in HA.
Overall architecture
The decision hierarchy is:
- Safety: frost, freezers, and critical alarms
- Comfort: hot water, underfloor heating, and practical use of the house
- Economy: avoid expensive imports and make use of cheap self-production
- Battery care: avoid unnecessary cycles and repeated inverter writes
- Export: only when it makes sense
The system can roughly be seen as five layers:
- Data sources: inverter, electricity meter, electricity prices, Solcast, temperatures, presence, and device status
- Calculation: load profiles, energy budget, battery trajectory, and import/export needs
- Decision: dispatch of controllable loads, import plan, and export plan
- Action: relays, plugs, and inverter parameters
- Monitoring: dashboard, status flows, emails, backup, and alarms

For historical reasons (the solar panels were added later), the system is partly split into load management and inverter management. Both parts use the same basic principle: look ahead before acting now. If a surplus is expected, comfort loads are allowed to run, and the battery may export. If a deficit is expected, consumption is held back, and imports are planned for cheap hours.
The principle in load management is that everything with long thermal time constants (underfloor heating, freezers, wine fridge, dehumidifier, and hot water tank) gets power in priority order whenever it’s cheaper than gas. Freezers, however, always run if their temperature gets too high.
PIR sensors and presence control lighting in hallways and utility rooms as needed. Some lighting, TV, hot water, and ventilation are partly controlled by whether we’re home — a Node-RED routine pings our phones, and no response means nobody’s home.
Inverter management balances production, storage, price, and consumption. Selling surplus production is a side matter — we’d rather have a warm bathroom floor than earn a few cents on export.
Load management
The load profiles flow builds an hourly model of the house’s normal electricity consumption over the day. The model isn’t used for direct control, but as input to the energy budget, so the system can predict upcoming baseline consumption more realistically than with fixed standard figures.
The flow learns two separate daily profiles: one for when we’re home, and one for when we’re away. This keeps night, day, and standby consumption from being blended across very different operating situations.
There’s some feedback between the load profiles and the energy management: when there’s a large PV surplus, the system allows more consumption, which in turn affects the profile. This is accepted because the profile should reflect how the house is actually run — not a theoretical passive house.

The energy budget calculates a rolling 24-hour energy budget in 30-minute intervals (slots) and simulates the expected course of the battery’s state of charge (SOC) based on:
- the battery’s capacity and current state of charge
- minimum SOC for battery and operational reasons
- a reserve for forecast uncertainty
- the PV forecast for the next 72 hours
- the learned consumption profile
- home/away status
The result is a basis for decisions: if the budget shows a surplus, thermal loads can be allowed to run; if it shows a deficit or a thin margin, they’re held back. This avoids a situation where a warm floor in the afternoon ends up being paid for with expensive imports at night.
Controllable loads: The most important thermal functions — with the exception of the dehumidifier — interact with the gas-based heating. Electricity is used when there’s a PV surplus or low prices. The flow translates the energy budget’s decisions into on/off per device, prioritized by PV surplus, price, comfort needs, and the energy budget.
Inverter management
Communication with the inverter happens via an RS485 port and Modbus (a serial communication standard widely used in industrial settings). An RS485-to-LAN converter connects the inverter to HA, and a Solax integration in HA translates the data. No direct Modbus commands are involved, and the system runs independently of Growatt’s app and server — though the app can still be used in the field.
The energy needs/optimizer flow builds a physically forward-looking battery trajectory in 15-minute intervals:
- PV covers load first
- PV surplus charges the battery up to SOC_MAX
- load deficits discharge the battery down to SOC_MIN
- if load is still missing at SOC_MIN, an import need is registered
- if PV is still in surplus at SOC_MAX, an export potential is registered
The flow first calculates the battery trajectory, then passes that basis on to separate import and export plans. A “plan selector” picks the relevant plan and writes to the inverter’s priority configuration, which can be:
| Priority | Function |
|---|---|
| Load First | Consumption is covered by PV or battery; surplus goes to the battery or export |
| Battery First | Battery is charged from the grid |
| Grid First | Battery exports to the grid |
Import and export orders to the inverter pass through filter nodes that prevent repeated writes of the same values — relevant because the inverter stores parameters in EEPROM (a type of memory that tolerates a limited number of write cycles).
Manual overrides
Overrides are used when automation needs to be stopped, tested, or overridden in special situations. They’re deliberately simple, so the system can be controlled manually:
- Export stop: continuously checks the spot price. If it goes negative, the export limit is set to 0. Once the price is positive again, export is re-enabled.
- Force export: exports from the battery down to a chosen state of charge, or until the routine is stopped manually.
- Force charge: charges the battery until the desired state of charge is reached.
The battery
The battery, 23 kWh nominal, comfortably covers our daily consumption. The original calculation pointed to that size, and it was later expanded by 10 kWh when a good deal came up — a decision that hasn’t been regretted. A larger capacity isn’t economical until the per-kWh price of batteries drops further; arbitrage trading doesn’t make sense at current battery and electricity prices.
The principles for using the battery:
- PV charging is prioritized over grid charging
- grid charging only happens when the forecast/price makes it sensible
- export from the battery is secondary
- minimum SOC and reserve protect the night and upcoming consumption
- battery wear is factored in as a practical and economic consideration
Error handling and failsafes
Values are stored in flow or global variables with persistent context, so they survive a restart. A complete backup is taken every night, so the system can be restored after a failure.
Critical functions like freezers and frost protection are monitored, and an alert is sent on failure. Each unit has an Aqara temperature/humidity sensor — chosen because it still works at -20°C and can transmit through the Faraday cage a freezer effectively forms.
The inverter stores parameters in EEPROM, which tolerates a limited number of write cycles. With the filter nodes in place, it typically only writes 4-6 times a day, and the expected lifespan of an EEPROM is over 100,000 write cycles.
The battery is used relatively intensively in this setup. The supplier promises a 10-year warranty, and figures around 6,000 cycles have been reported, giving a lifespan of roughly 16 years at one full cycle per day. Battery temperature, SOC, load, and round-trip efficiency are logged continuously.
In summary:
- Critical functions don’t rely on automation alone
- Freezers always run if their temperature rises too much
- Plug-based controls can be removed, allowing manual operation
- Repeated inverter commands are filtered
- Alerts are sent on critical failures
- Backups are taken daily
The operating systems, HA, and Node-RED are kept updated, both to protect the system from outside threats and to avoid functions breaking due to technical obsolescence.
The Swedish property
The system also covers a Swedish property without solar panels. The main house is built from timber dating to around 1850 and was heavily renovated in the 1970s. Heating and frost protection are provided by direct-acting electric panel heaters, all fed through a contactor in the fuse box — that’s what the system switches on and off. The panel heaters’ thermostats are set to around 17°C, and the minimum temperature is set to 7°C, measured in a reference room.
7°C is enough to prevent condensation and frozen installations.
In a separate building there’s an insulated room kept at 4°C for the sake of paint and other water-based liquids. If humidity exceeds 85%, the temperature is raised to prevent rust on the tools.
The system’s job in Sweden is mainly to minimize the energy cost of frost protection, in particular by avoiding heating during the hours when electricity prices are highest. A couple of days before arrival, the system is switched to “comfort mode” so the house is around 17°C on arrival. The rest of the heating is done with wood in the tiled stove and the cooker.
There’s fiber internet, and a site-to-site VPN between the routers handles the connection between the two properties. There used to be issues with the router not always coming back up after an update or restart — this is now solved with a watchdog that power-cycles the router if the connection drops.
Lessons and limitations
The system has been built gradually, which has the clear advantage that each part can be understood and tested on its own. The downside is that historical layers and names accumulate that aren’t always logical from the outside.
Forecasts are useful, but not truths. Weather forecasts, presence detection, and consumption profiles can all be wrong, which is why safety margins, manual overrides, and failsafe rules are used.
The biggest practical challenge isn’t the control logic itself, but keeping complexity under control. Much of the code has been generated with ChatGPT, which is fast and effective, but requires tight oversight — AI-generated code easily ends up too long and too complex, trying to account for problems that don’t actually exist.
Results
The system today handles the daily management of the solar installation, battery, selected loads, and monitoring. The biggest economic gain comes from reducing expensive imports and shifting thermal consumption to hours with self-production or low prices.
The exact figures vary with season and weather, but the main results (from the system going live in 2023 through mid-June 2026) are:
- self-sufficiency above 90% during the summer half of the year
- no imports during the peak-load period since the system went live
- reduced gas consumption for hot water and underfloor heating


Export is treated as secondary — comfort and self-consumption are prioritized over small export earnings. The cost per kWh from the battery, including wear and losses, is calculated at roughly DKK 1.10, so exporting from the battery only makes economic sense at relatively high electricity prices. The battery shifts around 10-20 kWh per day.
At current electricity prices, the payback period for the total investment is just under 10 years. The system is still under development, particularly around the economic optimization of imports, battery use, and long-term battery wear.
Glossary
- SOC: Battery state of charge, in %
- PV: Energy from the solar panels
- Load profile: Learned daily consumption profile
- Dispatch: Decision on which loads are allowed to switch on
- Reserve: Safety margin in the battery budget
- Slot: Calculation step, typically 15 or 30 minutes
- Grid: The public electricity grid
- Node-RED (NR): Flow-based, graphical programming environment
- Home Assistant (HA): Open-source home automation platform with an active user community
- EEPROM: Electrically erasable programmable memory
- RS485: Physical standard for serial data communication
- Modbus: Communication protocol for data exchange, widely used in industry
- Inverter: Converts direct current from solar panels and battery into alternating current
- HAN port: A data output on the electricity meter that can provide local readings
Per Frank-Hansen perfrankhansen@gmail.com