This repository contains two single-file HTML tools for Home Assistant. Each tool runs locally in the browser and connects to Home Assistant over the WebSocket API to query historical statistics from the recorder. The idea is to keep each tool as a single file with no build step.
To run the tools, copy the HTML files to your Home Assistant www directory:
/config/www/ha-battery-optimizer.html/config/www/ha-heating-monthly.html
Open them via your Home Assistant host so the WebSocket connection goes to the same server:
https://<ha-host>/local/ha-battery-optimizer.htmlhttps://<ha-host>/local/ha-heating-monthly.html
You must create a long-lived access token in Home Assistant (Profile -> Long-Lived Access Tokens) and paste it into each tool. The tools store your configuration, including the token, in the browser localStorage.
Both tools use Home Assistant long-term statistics from the recorder (statistics_during_period). The results depend on the historical data that is already recorded.
These tools were coded with AI and can contain errors or wrong calculations. They are both a practice project and a useful tool for me. The code could be more efficient.
This tool simulates different battery sizes and estimates savings over a selected period. It uses hourly statistics for grid import, grid export, and total consumption. PV production is derived from the energy balance, and the simulation applies battery efficiency, SoC limits, and optional power limits. The output includes charts and a result table with savings and energy flows.
| Entity | Purpose | Notes |
|---|---|---|
| Grid import energy (kWh) | Energy imported from the grid | Example: sensor.energy_import_sum; must have recorder long-term statistics |
| Grid export energy (kWh) | Energy exported to the grid | Example: sensor.energy_export_sum; must have recorder long-term statistics |
| Total consumption energy (kWh) | Total household consumption | Example: sensor.energy_consumption_sum; must have recorder long-term statistics |
| Input | Description |
|---|---|
| Access token | Long-lived access token for the Home Assistant WebSocket API |
| Grid price | Price per kWh (CHF) |
| Feed-in price | Feed-in tariff per kWh (CHF) |
| Capacity min / max / step | Battery capacity range in kWh |
| Round-trip efficiency | Battery efficiency in percent (50 to 100) |
| SoC min / max | State of charge limits in percent |
| Max charge power | Optional limit in kW |
| Max discharge power | Optional limit in kW |
| Start date / End date | Simulation period |
This tool creates monthly heating summaries for a heat pump system. It reads long-term statistics for energy, costs, and temperatures, then calculates MAZ (COP), electricity costs with and without PV, gas comparison costs, PV share, and heat price. It also renders charts and a monthly table.
| Entity | Purpose | Notes |
|---|---|---|
| Thermal energy per month (kWh) | Heat output per month | Example: sensor.thermische_energie_lwwp_monatlich; uses the last recorded value per month |
| Electric energy per month (kWh) | Heat pump electricity per month | Example: sensor.elektrische_energie_lwwp_monatlich; uses the last recorded value per month |
| Electric energy from PV per month (kWh) | PV share of heat pump electricity | Example: sensor.elektrische_energie_lwwp_monatlich_aus_pv; uses the last recorded value per month |
| Electric energy from grid per month (kWh) | Grid share of heat pump electricity | Example: sensor.elektrische_energie_lwwp_monatlich_aus_stromnetz; uses the last recorded value per month |
| Total heating cost (CHF) | Total cost sensor | Example: sensor.gesamtkosten_lwwp_heizen_saison; uses the monthly delta from recorder statistics |
| Outside temperature (deg C) | Outdoor temperature | Example: sensor.panasonic_heat_pump_main_outside_temp; uses mean values from recorder statistics |
| Inside temperature (deg C) | Indoor temperature | Example: sensor.shelly_ht_livingroom_temperature; uses mean values from recorder statistics |
| Input | Description |
|---|---|
| Access token | Long-lived access token for the Home Assistant WebSocket API |
| Gas price | Gas price per kWh (CHF) |
| Electricity price | Electricity price per kWh (CHF) |
| Start month / year | Start of the reporting range |
| End month / year | End of the reporting range |

