Skip to content

Add optional redesigned React based web interface - #5393

Open
calvind80 wants to merge 7 commits into
springfall2008:mainfrom
calvind80:feature/modern-web-ui
Open

calvind80 wants to merge 7 commits into
springfall2008:mainfrom
calvind80:feature/modern-web-ui

Conversation

@calvind80

@calvind80 calvind80 commented Oct 4, 2026 •

Copy link
Copy Markdown

Summary

Adds an optional modern web interface for Predbat, with responsive layouts, light and dark themes, and navigation between Overview, Dashboard, Plan, Charts, Compare, configuration and system pages.

Both interfaces run together: the classic pages keep their existing paths, and the modern interface is available under ./ui/. Select Try the new interface in the classic menu or Classic interface in the modern menu. The browser remembers the choice for this installation; no configuration change or restart is needed.

Plan-1

The new interface includes:

  • Responsive dashboard and energy overview
  • Plan timeline, table, history and debug views
  • Battery, power, cost, rates, solar, savings, degradation, marginal-cost and CO₂ charts
  • Apps configuration editor with schema help and Home Assistant entity autocomplete
  • Tariff helper with reviewable configuration suggestions
  • Entities, logs, compare, annual, discovery, cards, internals and documentation pages
  • Home Assistant ingress navigation and mobile layouts
  • Optional weather effects and configurable Overview integrations
  • PredHeat configuration reuse for weather and heat-pump data

Compatibility

  • The legacy interface remains the default.
  • Users do not need Node.js or Vite. The compiled interface is shipped as flat, fixed-name apps/predbat/predbat_ui* files.
  • Existing apps.yaml configurations remain supported.
  • Modern-only entities and settings are optional.
  • Frontend source remains available under frontend/.

Configuration

Add the relevant settings to your existing pred_bat: section in apps.yaml. Replace the example entity IDs with your own.
No web_ui setting is needed. All additional Overview settings below are optional. Existing grid, solar, battery and household entities are reused automatically.

pred_bat:
  # OPTIONAL: weather conditions and outdoor temperature on Overview.
  # Also supplies the conditions used by the optional visual weather effects.
  weather: weather.forecast_home

  # OPTIONAL: total solar-generation forecast for today, in kWh.
  # Reuse your existing setting if already configured.
  pv_forecast_today: sensor.solar_forecast_today

  # OPTIONAL EV SETTINGS
  # Only add these if your existing charger integration has not configured them.
  # Keep one entry per car, in the same order across the per-car lists.

  # OPTIONAL: number of cars represented by your configuration.
  # Keep your existing value if already configured.
  num_cars: 1

  # OPTIONAL: live charger power; enables the EV power display.
  # The entity must report W, kW or another convertible power unit.
  car_charging_power:
    - sensor.ev_charger_power

  # OPTIONAL: charger state, such as unplugged, connected or charging.
  car_charging_status:
    - sensor.ev_charger_status

  # OPTIONAL: vehicle battery state of charge, as a percentage.
  car_charging_soc:
    - sensor.ev_battery_percentage

  # OPTIONAL: daily accumulated charger electricity use, in kWh.
  car_charging_energy:
    - sensor.ev_charger_energy_today

  # OPTIONAL ASHP SETTINGS
  # Enable the heat-pump card when not already enabled by PredHeat.
  ashp_enable: true

  # OPTIONAL: current heat-pump electrical power consumption.
  # The entity must report W or a convertible power unit.
  ashp_power: sensor.heat_pump_power

  # OPTIONAL: heat-pump operating state.
  # Use off, hot_water or heating for the corresponding Overview states.
  ashp_status: sensor.heat_pump_status

  # OPTIONAL: indoor temperature, in degrees Celsius.
  internal_temperature: sensor.living_room_temperature

  # OPTIONAL: daily heat-pump ELECTRICITY consumption, in kWh.
  # Use electrical input energy rather than heat output.
  heat_energy: sensor.heat_pump_electricity_today

  # OPTIONAL compatibility alternative to heat_energy.
  # Use this only if heat_energy is not configured.
  # ashp_energy_today: sensor.heat_pump_electricity_today

Existing integrations and defaults

  • PredHeat: pump mode enables the ASHP card automatically and supplies its calculated indoor temperature and daily heating energy. Duplicate Overview settings are unnecessary.
  • Weather: predheat.weather takes precedence over the top-level weather setting. If neither is configured, Overview tries weather.forecast_home. Unavailable weather information is hidden.
  • EV integrations: retain automatically configured entities wherever available. Changing car settings can also affect Predbat’s existing charging configuration.
  • Optional readings: missing entities do not prevent the core Overview page from working.
  • Browser preferences: weather effects and device subtraction are controlled in the interface; they need no additional apps.yaml entries.

Packaging and delivery

  • House images and the Overview documentation screenshot are committed as WebP; the PNG conversion step and sharp dependency are removed.
  • CodeMirror 6 replaces Monaco, with YAML linting, schema help and entity completion, without web workers.
  • Vite emits 28 flat predbat_ui* files with fixed names and rejects empty chunks/assets. No zip is shipped.
  • The backend only serves prefixed assets with allowed extensions. FileResponse supplies ETag/Last-Modified and conditional responses, with Cache-Control: no-cache and compression for text assets.
  • Frontend CI runs npm ci, tests and a build, then checks for changed or untracked generated files. coverage/deploy copies predbat_ui*.
  • The obsolete UI selector, conditional routes, /legacy_* aliases and chart-path switch are removed. Modern UI guidance is in final sections of the web-interface and apps.yaml documentation.

Validation

  • 91 frontend tests pass on the committed branch.
  • Production build, lint and changed-file pre-commit checks pass.
  • Tooltip positioning checked at both edges in a browser fixture.
  • Production frontend files rebuilt; the build produces no differences from the committed assets.
  • Previously tested through Home Assistant ingress on desktop and mobile; the new side-by-side routing has local ingress-prefix tests and still needs a live ingress smoke test.

Frontend CI passed on both fork repositories at a1c64357. The upstream pull request workflows are awaiting maintainer approval.

@calvind80
calvind80 marked this pull request as ready for review October 10, 2026 07:51
@calvind80 calvind80 changed the title Add optional modern React web interface Add optional redesigned React based web interface Oct 10, 2026
@raldred

raldred commented Oct 10, 2026

Copy link
Copy Markdown
Contributor

Thanks for the PR, Can you share screenshots of the various features of the proposed dashboards?

@calvind80

calvind80 commented Oct 14, 2026 •

Copy link
Copy Markdown
Author
Dash-1 Dash-2 Plan-1 Plan-2 Overview Charts Tariff Comparison Editor

@springfall2008 springfall2008 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this. The new UI looks great and I'd like to get it in. Before it can merge I need changes to how it's packaged, and I'd like both interfaces to run side by side. I've reviewed head 5309cecb.

1. Size: every user downloads this, even on the legacy UI

The updater (download.py) and the add-on's first install (startup.py in predbat_addon) both download the whole repository archive and then copy apps/predbat/* out of it. Anything committed anywhere in the repo is therefore downloaded by every user on every update:

Size
Repo .tar.gz on main 10.7 MB
Repo .tar.gz on this PR 48.4 MB
frontend/src/assets/house/*.png (16 × ~2 MB) ~31 MB
apps/predbat/frontend.zip 4.7 MB
docs/images/web-interface-overview-view.png 1.7 MB

The source PNGs are never used at runtime; the build turns them into WebP files totalling about 2.8 MB. Please:

  • Commit the WebP files, not the PNGs, and drop the sharp / images:house pre-build step. If you want to go further, a base house image with car, heat-pump and snow overlays would replace the 16 combinations.
  • Shrink the docs screenshot. A WebP or a resized PNG should be well under 300 KB.

2. Replace Monaco

Most of the bundle is Monaco, which is used only on the apps.yaml editor page. It is shipped with about 80 language definitions (ABAP, Solidity, Verilog, …) when only YAML is used: editor.api is 2.5 MB, yaml.worker 1 MB and AppsEditorPage 1.1 MB.

Please switch to CodeMirror 6 (@codemirror/lang-yaml, linting and autocomplete), which is the successor to the CodeMirror 5 the legacy editor uses. It needs no web workers and comes to a few hundred KB. JSON-schema packages for CodeMirror cover the schema checking, hover and completion you get from monaco-yaml today, and the entity completion is your own code either way.

If you'd rather keep Monaco, at least limit it to YAML: import monaco-editor/esm/vs/editor/editor.api and only the YAML language contribution, rather than monaco-editor, which pulls in every language. The CDN route is awkward because Monaco's workers can't be started from another origin, and monaco-yaml's worker has to be bundled anyway.

3. Ship the built files directly instead of a zip

I'd like to avoid the zip. The committed zip can't be reviewed or diffed, nothing checks that it matches frontend/, and python3 -m zipfile stores file timestamps, so every rebuild is a new 4.7 MB file in history. This branch already holds 66 versions of it (~528 MB).

I've checked what the installers support:

  • Flat files directly in apps/predbat/ work. The updater lists the directory via the GitHub API, verifies each file against its Git blob SHA and writes it in binary, so .js, .css, .webp and .svg are all fine. The add-on's cp apps/predbat/* … picks them up too.
  • Subdirectories do not work. get_github_directory_listing drops directories, match_archive_member only accepts <repo>/apps/predbat/<file>, and predbat_update_move is a flat chain of mv commands. A frontend/dist/ folder would never reach users. Changing that would also need two updates for existing installs, because an update runs the old download.py.
  • The updater never deletes files. Vite's default content-hashed names (index-wqkwcjKB.js) would leave the old copies behind on users' disks after every frontend change.
  • check_install fails on a zero-byte file, so the build must not emit empty chunks.

So please:

  • Configure Vite to write fixed, prefixed names into apps/predbat/. For example: entryFileNames: 'predbat_ui.js', chunkFileNames: 'predbat_ui_[name].js', assetFileNames: 'predbat_ui_[name][extname]', plus predbat_ui.html. Updates then overwrite files rather than adding new ones.
  • Keep the file count small. Without Monaco this should be a few dozen files. Merge small page chunks with manualChunks where it helps.
  • Serve only those files. The asset route will be reading from the install directory, which also holds apps.yaml, secrets.yaml and the Python source. Serve only names matching predbat_ui* with an allow-listed extension, and nothing else from that directory.
  • Handle caching without hashed names. Use web.FileResponse (it sets ETag and Last-Modified and answers 304s) with Cache-Control: no-cache, or add ?v=<predbat version> to the asset URLs in predbat_ui.html. Please also enable compression; the JS is served uncompressed at the moment.
  • Add a CI job that runs npm ci && npm run build and fails on git diff --exit-code apps/predbat/predbat_ui*. It proves the committed files match the reviewed source. With fixed names and the lockfile, Vite's output should be deterministic.
  • Update coverage/deploy to copy predbat_ui* instead of frontend.zip.

4. Run both UIs at the same time

Rather than choosing one interface in apps.yaml at startup, I'd like both available all the time:

  • Mount the modern UI under a prefix, for example ./ui/, ./ui/plan, ./ui/charts. The legacy pages stay at their current paths.
  • Fix up the relative URLs. The frontend already uses relative URLs and takes the page from the last path segment, so this mostly works under ingress. From /ui/plan, ./api/... resolves to /ui/api/..., so build API and POST URLs as ../api/... (one level up), or register the API under the prefix as well. Assets resolve to ./ui/predbat_ui_*, which the prefixed asset route serves.
  • Add a link each way: "Try the new interface" in the legacy menu and "Classic interface" in the modern one. If a user wants the new UI as their landing page, remember it per browser (cookie or localStorage) and redirect / to ./ui/. No apps.yaml option or restart needed.
  • Remove what that makes unnecessary: the web_ui option, get_web_ui(), every self.html_modern_ui if modern_ui else … route, the duplicate /legacy_* routes (legacy_annual, legacy_chat, legacy_apps, legacy_charts, legacy_dash, legacy_plan) and the chart_path switch. Update docs/web-interface.md and docs/apps-yaml.md to match.

This also lets anyone try the new UI without editing their config. That's the best way to get feedback while the legacy UI remains the default.

Happy to talk any of this through.

@calvind80

calvind80 commented Oct 24, 2026 •

Copy link
Copy Markdown
Author

Those changes all make sense to me, I’ve implemented them all:

  • Replaced the house PNGs with WebP, removed the conversion step and sharp, and reduced the docs screenshot to about 183 KB.
  • Replaced Monaco with CodeMirror 6, retaining YAML/schema validation, hover help and completion.
  • Removed frontend.zip. The build now produces 28 flat, fixed-name predbat_ui* files, with restricted asset serving, cache revalidation and compression.
  • Added CI to install dependencies, test, rebuild and verify that the committed assets match the source. Updated coverage/deploy accordingly.
  • Made both interfaces available together, with the modern UI under /ui/, links between them and a browser-local preference. Removed the obsolete configuration and duplicate routes, and updated both documentation pages.

I’ve tested this in Home Assistant. All 100 frontend tests and the focused backend tests pass, and a clean build reproduces the committed assets exactly.

@calvind80
calvind80 force-pushed the feature/modern-web-ui branch from bb18f2c to 2bfcb90 Compare November 16, 2026 18:02
@springfall2008 springfall2008 added the enhancement New feature or request label Nov 21, 2026
@springfall2008

Copy link
Copy Markdown
Owner

@calvind80 thanks for working through the packaging review. I've checked the current head (8b6c9136): the zip is gone, the build is flat predbat_ui* files, the images are WebP, and the /ui/ asset route only serves the allowed names. That all looks right.

Before I review the UI itself, there's a problem with scope. Besides the UI, the branch now carries several engine changes that have nothing to do with it:

  • 8d518897 Octopus charge-to-add as target SoC: octopus_charge_limit_is_additive in fetch.py / config.py (Refs Predbat thinks car is charged if car soc > Octopus target charge to add #3034)
  • c7832907 Solis GS reserve-based battery holds: mode 17 hold in inverter.py, plus tests and docs
  • 1d7b1b38 carbon API failure reporting in carbon.py
  • 5beab194 backend hardening: MCP registration and scopes, chat approval IDs, bounds checks, and the calc_percent_limit guards in prediction_kernel.cpp
  • a2b3da77 the six rebuilt prediction_kernel_lib_*.so files and a new kernel-binary-check workflow

Some of these may well be good fixes. But each one changes how Predbat controls an inverter or plans, so each needs its own review and its own place in the release notes. They can't be merged as part of a UI PR. The rebuilt .so files are also why the branch now conflicts with main, and they will conflict again every time the kernel changes.

There are two ways forward, and I'm happy with either:

  1. You split it up. This PR keeps only the UI: frontend/, the predbat_ui* files, and the backend routes and data the UI needs. Each of the other fixes goes into its own PR against main, without the .so files. This branch also needs main merged in to clear the conflicts.
  2. I do the UI split for you. I cherry-pick the UI work onto a fresh branch from main and open a new PR, with you credited as co-author on the commits. I'd then close this one. The other fixes would still need their own PRs from you if you want them in.

Let me know which you'd prefer.

@calvind80

calvind80 commented Nov 30, 2026 •

Copy link
Copy Markdown
Author

@springfall2008

  1. You split it up. This PR keeps only the UI: frontend/, the predbat_ui* files, and the backend routes and data the UI needs. Each of the other fixes goes into its own PR against main, without the .so files. This branch also needs main merged in to clear the conflicts.
  2. I do the UI split for you. I cherry-pick the UI work onto a fresh branch from main and open a new PR, with you credited as co-author on the commits. I'd then close this one. The other fixes would still need their own PRs from you if you want them in.

Let me know which you'd prefer.

I will do the splitting up, I will keep this PR as the UI additions & required backend changes for that only.

@calvind80
calvind80 force-pushed the feature/modern-web-ui branch from 8b6c913 to 52b56fd Compare November 30, 2026 22:38
@calvind80

Copy link
Copy Markdown
Author

@springfall2008 Non-UI changes have been split out from this PR.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants