npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@iseeberg79/battery-usage-optimization-nodes

v0.2.2

Published

A custom Node-RED package for battery usage optimization

Downloads

279

Readme

🇬🇧 English · 🇩🇪 Deutsch

92C08093-CA7B-463E-8BE3-9F03C6622BD6_klein

Optimizing home battery storage usage with Node-RED, evcc and a dynamic electricity tariff

How it works

The battery storage is preferentially charged with surplus PV power. Discharging during periods of cheap grid electricity is avoided. If the price difference is high enough (e.g. > 15 ct/kWh), grid charging can take place at the cheapest time of day to charge the battery up to 80 %. The grid-charging price is taken into account for further control: the battery only releases energy when the grid electricity price is clearly above the grid-charging price (~130 %).

To avoid inefficient charging and discharging, the battery is only charged once its state of charge drops below 30 %. The control focuses on shifting energy use and optimizing storage deployment.

The thresholds for grid charging are configurable and set high by default, since grid charging is often not economical. If sufficient PV generation is forecast for the following day to cover the expensive price periods, no grid charging takes place.

Input factors

The optimized control is only active when the forecast daily PV generation is below the daily electricity demand (PV forecast < 17.5 kWh). Forecast data can be obtained from SOLCAST via a personal home-use API. Throughout the day, the remaining PV yield is dynamically fed into the control.

A predefined standard load profile for a 4-person household with working parents and school-age children (approx. 15 kWh/day) is used. Consumption is calculated from the current hour until the next morning (8 a.m.), taking the hourly demand into account.

If electricity prices for the current and the upcoming day are available, they are included in the optimization. Prices can be obtained via evcc through its HTTP API, or alternatively from the Fraunhofer ISE Energy-Charts.

Controlling the battery storage

The calculation determines the optimal battery mode. Actually controlling a (hybrid) inverter must be implemented separately due to hardware-dependent factors:

  • Grid charging can be controlled by passing the grid-charging price to an evcc instance via the MQTT/HTTP API.
  • Blocking the battery can, if evcc supports it, be realized based on the information in the evcc wiki. Either the calculated price can be used directly, or the mode can be controlled via the MQTT/HTTP API (charge/discharge mode).

Node-RED integration

The Node-RED package contains several nodes for optimizing battery usage. The nodes are flexible and can be combined with external data sources. It is also possible to integrate your own nodes for additional data sources. This way the solution can be run with or without evcc. The nodes come preconfigured with default values, while the message inputs allow configuration overrides. The modular design makes it easy to reuse and adapt them to different installations.

Available nodes

Main components

  • DetermineBatteryMode - Determines the optimal battery mode based on price, SOC and forecasts (documentation)
  • EstimateBatterymode - Builds 24-hour charging schedules with cost optimization (documentation | JSDoc)
  • BatteryModeControl - Controls the battery mode (documentation)
  • ControlBattery - Battery control (documentation)

Forecast & data sources

  • EvaluateSolarForecast - Processes Solcast PV forecasts (documentation)
  • EvaluateSolarForecastAPI - Fetches Solcast data from the API (documentation)
  • EvaluateSolarForecastOpenMeteo - Open-Meteo solar forecasts (documentation)
  • CombinePVForecasts - Combines multiple PV forecasts (documentation)
  • EstimateSolarEnergy - Estimates solar energy from forecasts (documentation)
  • EstimateHouseholdConsumption - Estimates household consumption (documentation)
  • EvaluateGridEnergyPrices - Processes electricity prices (documentation)
  • EvaluateGridEnergyPricesAPI - Fetches electricity prices from the API (documentation)
  • TibberApiPrices - Tibber electricity prices (documentation)
  • PrepareForecastData - Prepares forecast data (documentation)

Helper functions

Examples

Complete flow examples for all nodes can be found in the examples/ directory. Import them into Node-RED via Menu → Import → Clipboard.

An external control can be integrated that still takes the status of the evcc charging control and current energy values into account.

The control's forecast function represents such an external input. It returns a JSON that can be used for control:

| Start time | Energy | Import price (€/kWh) | Est. cost (€) | Mode | Consumption (-kWh) | Production (+kWh) | Discharge (-kWh) | SoC (%) | Eff. price (€/kWh) | Opt. cost (€) | |--------------------------|------|---------------------|------------|---------|------------------|------------------|---------------|---------|------------------------|--------------| | 2025-03-03 06:00:00+01:00 | 1 | 0.3150 | 0.3150 | normal | 1 | 0 | 0 | 5 | 0.0948 | 0.3150 | | 2025-03-03 07:00:00+01:00 | 0.427| 0.3453 | 0.2016 | normal | 1 | 0.00265 | 0.57 | 5 | 0.0948 | 0.2016 | | 2025-03-03 08:00:00+01:00 | 0.239| 0.3269 | 0.0780 | normal | 0.4 | 0.1613 | 0 | 5 | 0.0948 | 0.0780 | | 2025-03-03 09:00:00+01:00 | 0.115| 0.2784 | 0.0320 | normal | 0.4 | 0.28515 | 0 | 5 | 0.0948 | 0.0320 | | 2025-03-03 10:00:00+01:00 | -0.334| 0.2375 | 0 | hold | 0.4 | 0.7343 | 0 | 7.95 | 0.0790 | 0 | | 2025-03-03 11:00:00+01:00 | -2.382| 0.1590 | 0 | hold | 0.4 | 2.7824 | 0 | 30.64 | 0.0790 | 0 | | 2025-03-03 12:00:00+01:00 | -3.796| 0.1517 | 0 | hold | 1 | 4.79605 | 0 | 66.79 | 0.0790 | 0 | | 2025-03-03 13:00:00+01:00 | -5.208| 0.1514 | 0 | hold | 1 | 6.20825 | 0 | 100 | 0.0790 | 0 | | 2025-03-03 14:00:00+01:00 | -6.678| 0.2244 | 0 | hold | 0.4 | 7.07795 | 0 | 100 | 0.0790 | 0 | | 2025-03-03 15:00:00+01:00 | -6.742| 0.2514 | 0 | hold | 0.4 | 7.1421 | 0 | 100 | 0.0790 | 0 | | 2025-03-03 16:00:00+01:00 | -5.781| 0.2779 | 0 | hold | 0.4 | 6.1807 | 0 | 100 | 0.0790 | 0 | | 2025-03-03 17:00:00+01:00 | -3.360| 0.3284 | 0 | hold | 1 | 4.3602 | 0 | 100 | 0.0790 | 0 | | 2025-03-03 18:00:00+01:00 | 0 | 0.3702 | 0.0375 | normal | 1 | 0.6044 | 0.3956 | 96.23 | 0.0948 | 0.0375 | | 2025-03-03 19:00:00+01:00 | 0 | 0.3607 | 0.0948 | normal | 1 | 0 | 1 | 86.71 | 0.0948 | 0.0948 | | 2025-03-03 20:00:00+01:00 | 0 | 0.3304 | 0.0948 | normal | 1 | 0 | 1 | 77.18 | 0.0948 | 0.0948 |

The optimized trajectory of the known forecast data (price, PV forecast) is calculated, including an optional grid charge. Statistics and calculation data are returned. The example above is for a day with sufficient solar yield and high prices outside the hours of solar generation. Control is not required here, but would be used during hours with low electricity prices.

The statistics allow you to calculate whether an optimization leads to price savings:

image

The supplied standard distribution of the forecast electricity demand determines the accuracy of the result.

Usage and further development

I use the npm building blocks within a Node-RED instance on ioBroker. They should, however, also be compatible with other platforms such as Home Assistant.

The package has since been published; further real-world experience and optimizations are still needed.


Provided without warranty. Use of the provided content is at your own risk!

Example flow

image

Flow context data

image

For example as an upload in the palette manager of Node-RED in ioBroker, or:

npm install @iseeberg79/battery-usage-optimization-nodes

image

image

image

evcc

solcast

Open-Meteo

Energy-Charts

iobroker.net

node-red