Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
92 commits
Select commit Hold shift + click to select a range
39d8145
Add Octopus Energy Agile tariff price support
ipc-zpg Feb 27, 2026
720063a
Merge pull request #1 from pookey/feature/octopus-energy-support
pookey Feb 27, 2026
9511f44
Update docs for Octopus Energy price support
ipc-zpg Feb 27, 2026
ad7a506
Merge pull request #2 from pookey/feature/octopus-energy-support
pookey Feb 27, 2026
f9f8bad
Bump version to 6.1.0 for Octopus Energy support
ipc-zpg Feb 27, 2026
e0b8424
Merge pull request #3 from pookey/feature/octopus-energy-support
pookey Feb 27, 2026
7f08016
Handle missing tomorrow prices for Octopus Energy
ipc-zpg Feb 27, 2026
fe401d5
Bump version to 6.1.1
ipc-zpg Feb 27, 2026
6a0c7e0
Merge pull request #4 from pookey/feature/octopus-energy-support
pookey Feb 27, 2026
630331b
Fix Inverter page blank when dashboard endpoint fails
ipc-zpg Feb 27, 2026
7e7808e
Merge pull request #5 from pookey/fix/inverter-page-blank-on-dashboar…
pookey Feb 27, 2026
81c3d60
Fix Octopus Energy optimization crash due to period index mismatch
ipc-zpg Feb 27, 2026
6b2fd06
Merge pull request #6 from pookey/fix/octopus-price-period-normalization
pookey Feb 27, 2026
fa9edff
Fix InfluxDB queries to support both 1.x and 2.x data models
ipc-zpg Feb 28, 2026
899e81c
Merge pull request #7 from pookey/fix/influxdb-dual-version-support
pookey Feb 28, 2026
888c2d5
Fix Octopus Energy price display showing ~1.33 GBP/kWh instead of act…
ipc-zpg Feb 28, 2026
b5d2ffd
Merge pull request #8 from pookey/fix/price-settings-not-propagated
pookey Feb 28, 2026
329ddfb
Fix Inverter page blank when dashboard endpoint fails
ipc-zpg Feb 27, 2026
0da4936
Fix Octopus Energy optimization crash due to period index mismatch
ipc-zpg Feb 27, 2026
9904e4e
Fix InfluxDB queries to support both 1.x and 2.x data models
ipc-zpg Feb 28, 2026
a118182
Merge remote-tracking branch 'fork/main'
ipc-zpg Feb 28, 2026
4835d19
Bump version to 6.2.1 for Home Assistant add-on detection
ipc-zpg Feb 28, 2026
11861f8
Fix InfluxDB 1.x entity_id filter matching nothing
ipc-zpg Feb 28, 2026
9297fe4
Merge pull request #9 from pookey/fix/influxdb-1x-entity-id-filter
pookey Feb 28, 2026
e693c27
Fix battery SOC showing >100% due to capacity mismatch
ipc-zpg Feb 28, 2026
fd48f43
Merge pull request #11 from pookey/worktree-battery_soc
pookey Feb 28, 2026
0b342c7
chore: pointless version bump
ipc-zpg Feb 28, 2026
a28b214
Persist historical data across restarts
ipc-zpg Feb 28, 2026
bc0cb25
Merge pull request #12 from pookey/worktree-first_loaded
pookey Feb 28, 2026
13ac26f
Fix persistence files lost on restart by using /data instead of /config
ipc-zpg Feb 28, 2026
a0c7805
Merge pull request #14 from pookey/fix/persistence-path
pookey Feb 28, 2026
0c01fc5
Add persistence diagnostics to historical-data-status endpoint
ipc-zpg Feb 28, 2026
b18c6dc
Merge pull request #15 from pookey/fix/persistence-diagnostics
pookey Feb 28, 2026
c94fa26
Fix grid charging rate being throttled instead of charging at full power
ipc-zpg Mar 1, 2026
f5c0ad6
Merge pull request #16 from pookey/fix/grid-charging-rate
pookey Mar 1, 2026
af272e6
Fix CLAUDE.md formatting and add venv instructions, reduce log spam
ipc-zpg Mar 1, 2026
184d591
Merge pull request #17 from pookey/fix/claude-md-and-log-spam
pookey Mar 1, 2026
65d25cd
Fix resilient error handling for HA service calls during outages
ipc-zpg Mar 1, 2026
28ca202
Merge pull request #18 from pookey/fix/resilient-ha-error-handling
pookey Mar 1, 2026
049c07a
Fix historical data lost on restart due to InfluxDB batch parser pref…
ipc-zpg Mar 1, 2026
bb07c9a
Merge pull request #19 from pookey/fix/influxdb-batch-prefix-mismatch
pookey Mar 1, 2026
39aca0a
Pass BatterySettings reference instead of bare float capacity
ipc-zpg Mar 2, 2026
f4877f1
Merge pull request #20 from pookey/worktree-battery_soc
pookey Mar 2, 2026
fd88eb9
Extend DP optimization horizon with tomorrow's prices and terminal va…
ipc-zpg Mar 2, 2026
e04d953
Fix DST-unsafe timestamp calculation in _add_timestamps_to_period_data
ipc-zpg Mar 2, 2026
c097e0a
Merge pull request #21 from pookey/feature/extended-dp-horizon
pookey Mar 2, 2026
d177616
Extend dashboard charts to show tomorrow's optimization horizon
ipc-zpg Mar 2, 2026
c405d66
Merge pull request #22 from pookey/feature/dashboard-tomorrow-horizon
pookey Mar 2, 2026
7f34056
Show tomorrow's planned schedule on Inverter page
ipc-zpg Mar 2, 2026
ccd3e46
Merge pull request #23 from pookey/feature/inverter-tomorrow-schedule
pookey Mar 2, 2026
69b7384
Rolling 24h TOU schedule with tomorrow's optimized intents
ipc-zpg Mar 3, 2026
d294a6e
Merge pull request #24 from pookey/feature/inverter-tomorrow-schedule
pookey Mar 3, 2026
4736728
Fix DST-unsafe hardcoded period counts for tomorrow's data extraction
ipc-zpg Mar 3, 2026
a33e3be
Scope EconomicSummary to today-only and add tomorrow section to Savin…
ipc-zpg Mar 3, 2026
aae1c6a
Merge pull request #26 from pookey/feature/inverter-tomorrow-schedule
pookey Mar 3, 2026
49aa0c0
Merge pull request #25 from pookey/fix/dst-unsafe-period-counts
pookey Mar 3, 2026
8a85e27
Apply black/ruff formatting to core and tests
ipc-zpg Mar 4, 2026
101f488
Fix dashboard chart visual issues: X-axis labels, price step function…
ipc-zpg Mar 5, 2026
12a8b64
Remove midnight separator line from both dashboard charts
ipc-zpg Mar 5, 2026
d78715d
Merge pull request #27 from pookey/worktree-chart_improvement
pookey Mar 5, 2026
b63516c
Fix sensor data corruption when HA sensors temporarily unavailable (#28)
pookey Mar 5, 2026
80b6035
Fix chart data positioning: remove fake zero-point and align to perio…
pookey Mar 5, 2026
c7b1364
Fix predicted hours shading not rendering on energy flow chart (#30)
pookey Mar 5, 2026
016b093
Fix current period showing as Predicted instead of Actual (#31)
pookey Mar 5, 2026
7b9e001
setup for local development
ipc-zpg Mar 5, 2026
6d2db2c
Fix terminal value using last known price instead of daily average (#32)
pookey Mar 5, 2026
0c05be9
Add ML energy consumption predictor with web UI report tab (#13)
pookey Mar 6, 2026
61ccf04
Add ML energy consumption predictor with web UI report tab
ipc-zpg Mar 6, 2026
6defdbe
Merge remote-tracking branch 'origin/main' into worktree-machine_lear…
ipc-zpg Mar 6, 2026
4236421
Fix Docker build: add ml/ module and xgboost build deps to production…
ipc-zpg Mar 6, 2026
5f35873
Switch Docker base from Alpine to Debian for prebuilt ML wheels
ipc-zpg Mar 6, 2026
ff33897
Fix invalid ML schema: remove stray sensor fields from ml config section
ipc-zpg Mar 6, 2026
7b4ecfd
Remove hardcoded SEK currency and Swedish locale references
ipc-zpg Mar 6, 2026
b2a8716
Fix dashboard 500s: add missing power sensor fields to config schema
ipc-zpg Mar 6, 2026
373849a
Add weekly average profile to ML Report and support influxdb_profile …
ipc-zpg Mar 6, 2026
0851d13
Train ML model on boot and daily regardless of consumption_strategy
ipc-zpg Mar 6, 2026
143c1c1
Bump version to 7.0.6
ipc-zpg Mar 6, 2026
f440e52
Fix ML config crash: fall back to options.json for InfluxDB credentials
ipc-zpg Mar 6, 2026
52caaeb
Fix ML predictions missing from report when using influxdb_profile
ipc-zpg Mar 6, 2026
3d86271
Fix overnight chart gaps and tomorrow data rendering issues
ipc-zpg Mar 6, 2026
ec449c2
Merge pull request #34 from pookey/fix/chart-gaps-and-tomorrow-data
pookey Mar 6, 2026
e2233e8
Merge pull request #33 from pookey/locale-cleanup
pookey Mar 6, 2026
a19e88d
Make ML config optional and generate predictions proactively
ipc-zpg Mar 6, 2026
754521e
Merge pull request #35 from pookey/worktree-machine_learning
pookey Mar 6, 2026
18b06e4
Fix ML weather forecast auth: use HASSIO_TOKEN in add-on container
ipc-zpg Mar 6, 2026
dbdbc87
Remove redundant disk persistence from HistoricalDataStore
ipc-zpg Mar 6, 2026
8e7638b
Merge pull request #36 from pookey/remove/historical-data-persistence
pookey Mar 6, 2026
f51e321
Use median price for terminal value instead of last known price
ipc-zpg Mar 6, 2026
2d516c3
Merge pull request #37 from pookey/fix/terminal-value-median
pookey Mar 6, 2026
614c4b3
Fix startup data collection using live sensors instead of InfluxDB fo…
ipc-zpg Mar 6, 2026
c7c286d
Read timezone from Home Assistant instead of hardcoding (#38)
pookey Mar 7, 2026
103f05c
Fix ML predictions missing from report page after next-day preparation
ipc-zpg Mar 7, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ HA_DB_BUCKET=homeassistant/autogen
HA_DB_USER_NAME="YOUR DB USERNAME HERE"
HA_DB_PASSWORD="YOUR DB PASSWORD HERE"

# Container timezone (for log timestamps, etc.)
TZ=Europe/Stockholm

# Development mode
FLASK_DEBUG=true

Expand Down
8 changes: 7 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,11 @@ yarn-error.log*
.env.local
.env.*.local

# Development options (contains sensitive settings)
# Development options and personal config (contains sensitive settings)
backend/dev-options.json
ml_config.yaml
myconfig.yaml
ha.secret

# Build output
dist/
Expand All @@ -43,6 +46,9 @@ build/
# TypeScript
*.tsbuildinfo

# ML model artifacts (generated by training)
ml/trained_model.*

# Miscellaneous
*.log
.bess-logs/
Expand Down
289 changes: 289 additions & 0 deletions CHANGELOG.md

Large diffs are not rendered by default.

90 changes: 50 additions & 40 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,85 +11,73 @@ BESS Battery Manager is a Home Assistant add-on for optimizing battery energy st
### Backend (Python)

```bash
# Activate virtual environment (required for all Python commands)
source .venv/bin/activate

# Install dependencies

pip install -r backend/requirements.txt

# Run development server

./dev-run.sh

# Run tests

pytest
pytest core/bess/tests/unit/
pytest core/bess/tests/integration/
pytest --cov=core.bess

# Code quality

black .
ruff check --fix .
mypy .
```text
```

### Frontend (React/TypeScript)

```bash
cd frontend

# Install dependencies

npm install

# Development server

npm run dev

# Build production

npm run build

# Generate API client from OpenAPI spec

npm run generate-api
```text
```

### Docker Development

```bash

# Start both backend and frontend

docker-compose up -d

# View logs

docker-compose logs -f
```text
```

### Build Add-on

```bash
chmod +x package-addon.sh
./package-addon.sh
```text
```

### Quality Checks

```bash

# Run comprehensive quality checks

./scripts/quality-check.sh

# Individual checks

black . # Format Python code
ruff check --fix . # Fix Python linting issues
cd frontend && npm run lint:fix # Fix TypeScript issues
```text
```

## Architecture Overview

Expand Down Expand Up @@ -163,16 +151,17 @@ cd frontend && npm run lint:fix # Fix TypeScript issues
**Required Analysis Steps**:

1. **Search for Existing Implementations**:

```bash
# Search for similar functionality
grep -r "dataclass\|serialization\|formatting" --include="*.py"
grep -r "HealthStatus\|SystemHealth" --include="*.ts" --include="*.tsx"
grep -r "HealthStatus\|SystemHealth" --include="*.ts" --include="*.tsx"
find . -name "*api*" -name "*model*" -name "*conversion*"
```

1. **Examine Related Files**:
- `backend/api_dataclasses.py` - existing API models
- `backend/api_conversion.py` - serialization utilities
- `backend/api_conversion.py` - serialization utilities
- `frontend/src/types.ts` - TypeScript interfaces
- `core/bess/` - domain models and services
- Any files matching the functionality you plan to add
Expand Down Expand Up @@ -200,18 +189,21 @@ cd frontend && npm run lint:fix # Fix TypeScript issues
## Codebase Analysis for Sensor Formatting

### Existing Infrastructure Found:
- ✅ API Dataclasses: `backend/api_dataclasses.py`

- ✅ API Dataclasses: `backend/api_dataclasses.py`
- ✅ Serialization: `backend/api_conversion.py`
- ✅ Health Types: `frontend/src/types.ts`
- ✅ Health Endpoint: `/api/system-health` in `backend/api.py`

### What's Actually Missing:

- ❌ Centralized sensor unit formatting (only frontend string matching exists)
- ❌ Unit metadata in METHOD_SENSOR_MAP

### Minimal Required Changes:

1. Add unit metadata to existing METHOD_SENSOR_MAP
2. Create SensorFormattingService
2. Create SensorFormattingService
3. Integrate with existing health check system
```

Expand Down Expand Up @@ -262,10 +254,11 @@ cd frontend && npm run lint:fix # Fix TypeScript issues
- **Proper list spacing**: Add blank line before lists, none between list items
- **No trailing spaces**: Remove all trailing whitespace
- **Single blank lines**: Never use multiple consecutive blank lines
- **Consistent heading levels**: Don't skip heading levels (no h1 h3)
- **Consistent heading levels**: Don't skip heading levels (no h1 to h3)

```markdown
Good markdown example:

```markdown
# Good Example

## Header with proper spacing
Expand All @@ -279,23 +272,24 @@ This paragraph has proper spacing around it.
- List item 3

Another paragraph after the list.
```

Bad markdown example:

```markdown
## Bad Example

###Missing blank lines

- List immediately after header
- No spacing


Too many blank lines above.
```text
```

#### Pre-Commit Quality Checklist

Before creating or modifying any files, ALWAYS:

1. **Check Problems Tab**: View Problems in VS Code - must show zero errors/warnings for modified files
1. **Check Problems Tab**: View > Problems in VS Code - must show zero errors/warnings for modified files
2. **Run Code Formatters**:
- Python: `black .` and `ruff check --fix .`
- TypeScript: `npm run lint:fix` in frontend directory
Expand All @@ -310,7 +304,7 @@ Run the quality check script before committing:

```bash
./scripts/quality-check.sh
```text
```

This script automatically checks:

Expand Down Expand Up @@ -344,7 +338,7 @@ use snake_case. Added conversion to properly map keys before validation.
Bad commit messages:

```text
Fix issue 🤖 Generated with Claude Code
Fix issue Generated with Claude Code
Update settings (AI-assisted)
Changes made by Claude
```
Expand Down Expand Up @@ -402,18 +396,14 @@ Changes made by Claude
#### Code Examples

```python

# Good: Use existing controller method

soc_value = self.ha_controller.get_battery_soc()

# Bad: Manual sensor key extraction

sensor_info = self.ha_controller.METHOD_SENSOR_MAP["get_battery_soc"]
soc_sensor_key = sensor_info.get("entity_id")

# Good: Use centralized health check

return perform_health_check(
component_name="Battery Monitoring",
description="Real-time battery state monitoring",
Expand All @@ -424,15 +414,14 @@ return perform_health_check(
)

# Bad: Custom health check logic with hardcoded thresholds

working_count = sum(1 for method in methods if test_method(method))
if working_count >= 3:
return "OK"
elif working_count >= 1:
return "WARNING"
else:
return "ERROR"
```text
```

#### API Conventions

Expand Down Expand Up @@ -545,10 +534,10 @@ assert slot_start_times == ['02:40', '05:20'] # Specific slot boundaries
def test_export_arbitrage_enables_battery_discharge():
strategic_intents[20] = 'EXPORT_ARBITRAGE'
scheduler.apply_schedule(strategic_intents)

# Test BEHAVIOR: Battery should discharge during target hour
assert scheduler.is_hour_configured_for_export(20)

# Test CONSTRAINTS: Hardware requirements must be met
assert scheduler.has_no_overlapping_intervals()
assert scheduler.intervals_are_chronologically_ordered()
Expand Down Expand Up @@ -591,3 +580,24 @@ def test_export_arbitrage_enables_battery_discharge():
4. **Make tests algorithm-agnostic**: Could a different implementation pass?

**Remember**: Good tests survive refactoring. Bad tests require updates when internal implementation changes.

### Code Intelligence

Prefer LSP over Grep/Read for code navigation - it's faster, precise, and avoids reading entire files:

- `workspaceSymbol` to find where something is defined
- `findReferences` to see all usages across the codebase
- `goToDefinition` / `goToImplementation` to jump to source
- `hover` for type info without reading the file

Use Grep only when LSP isn't available or for text/pattern searches (comments, strings, config).

After writing or editing code, check LSP diagnostics and fix errors before proceeding.

## Python Environment

**Always use the project virtual environment** (`.venv`) for all Python commands. Activate it before running any Python, pytest, black, ruff, or mypy commands:

```bash
source .venv/bin/activate
```
15 changes: 13 additions & 2 deletions DOCS.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,19 @@ The add-on requires sensors for:

- Battery: SOC, charge/discharge power, control switches
- Solar: Production, consumption, grid import/export
- Pricing: Nordpool spot prices (today and tomorrow)
- Consumption: 48-hour average forecast
- Pricing: Electricity spot prices via Nordpool or Octopus Energy (today and tomorrow)
- Consumption: Depends on `consumption_strategy` setting (see below)

### Consumption Forecasting

Four strategies are available for consumption forecasting, configured via `consumption_strategy` in the `home` section:

| Strategy | Sensor requirements |
|---|---|
| `sensor` (default) | `48h_avg_grid_import` sensor configured |
| `fixed` | None (uses `home.consumption` value) |
| `influxdb_profile` | `local_load_power` sensor + InfluxDB |
| `ml_prediction` | Trained ML model + HA weather entity |

See the [Installation Guide](https://github.com/johanzander/bess-manager/blob/main/INSTALLATION.md) for complete sensor configuration examples.

Expand Down
12 changes: 7 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -22,24 +22,26 @@ LABEL \
org.label-schema.vcs-url="https://github.com/johanzander/bess-manager"

# Install requirements for add-on
RUN apk add --no-cache \
RUN apt-get update && apt-get install -y --no-install-recommends \
python3 \
py3-pip \
python3-pip \
python3-venv \
python3-dev \
gcc \
musl-dev \
bash \
nodejs \
npm
npm \
&& rm -rf /var/lib/apt/lists/*

# Set working directory
WORKDIR /app

# Copy Python application files from backend directory
COPY backend/app.py backend/api.py backend/api_conversion.py backend/api_dataclasses.py backend/log_config.py backend/requirements.txt ./

# Copy core directory
# Copy core directory and ML module
COPY core/ /app/core/
COPY ml/ /app/ml/

# Build and copy frontend
WORKDIR /tmp/frontend
Expand Down
Loading