Repository navigation
EV Trip Planner Integration — Multi-Trip Deferrable Load Management #820
Replies: 3 comments 1 reply
|
Hi and wow! |
|
Thank you for the kind words! Let me address each question: What is MVP?You're right, I should have been clearer. MVP = Minimum Viable Product — the minimum set of features that delivers real value to users. In our case, that means the core charging window calculation and EMHASS sensor integration work correctly, but there are known areas that need polish (panel UX, automations, etc.). Do you have results examples?Honestly — not yet anything visually impressive to show. The current functional output is the sensor attributes that get passed in the optimization request to EMHASS via the shell command. Here's what I can share: What the sensors produce right now: The component creates per-trip sensors with these attributes that map directly to EMHASS deferrable load parameters:
These are passed to EMHASS via Jinja2 templates in the shell command that triggers the optimization. Real-world usage: I'm currently testing it in my own home with my daily driver. I've set up all my weekly trips and the component is correctly sending the planning data to EMHASS. EMHASS then optimizes when to charge based on my trip schedule. In my case, I have a large home battery so I use weekly planning in EMHASS — which means I pass a 168-hour profile. This is where the multi-trip window calculation really shines: coordinating charging across a full week of trips. For users with standard 24-hour planning horizons, the component still works but the value proposition is more limited — a daily schedule with one or two trips is a simpler problem to solve manually. One thing I've noticed that would be nice to expose: the If it would be helpful, I could share: After running it for a full week in production, I could put together a table showing:
This would be more meaningful than a screenshot of sensor attributes — but let me know if that level of detail is useful or if the technical description above is sufficient. An improvement I'm already seeing the need for: When EMHASS detects that energy is very cheap and abundant, it may schedule charging well in advance, leaving the car sitting at a high SOC for many hours. This is not ideal for battery health — and for some vehicles like my Nissan Leaf (30kWh), it's particularly bad. I'm planning to add a configurable dynamic SOC limit that caps the maximum SOC based on how many hours remain until the next trip departure. For example, if the car won't be used for 3 days, there's no reason to charge it to 100% even if energy is practically free. This parameter would be vehicle-specific since battery degradation sensitivity varies significantly between models. Do you plan to keep it as a custom component for HA?Yes, absolutely. The plan is:
The custom component approach gives us flexibility to iterate quickly without being tied to HA core release cycles. And the Jinja2 template bridge to EMHASS means users can adopt it incrementally without changing their existing EMHASS setup. Thanks again for the interest!. And if anyone wants to test it with their own vehicle/EMHASS setup, I'm happy to help with configuration. |
Before/after comparisonAgreed — that comparison is the goal. I plan to run a full week of production data and document the difference between EMHASS optimization with and without trip planner data. I'll try to create a visual diagram showing how the charging profile changes when the optimizer has trip schedule information vs. when it doesn't — to make it clear and easy to understand at a glance. Cookbook contributionThe idea of contributing EV Trip Planner as an official EMHASS cookbook example is great. The real value case is: multi-trip deferrable load management with temporal dependencies and backward deficit propagation — which is exactly the pattern described in discussion #824. EMHASS has been a huge help in my daily life, so I'm happy to contribute back. I'll submit a PR for the EMHASS cookbook documenting this use case: how to manage multiple EV charging trips with different schedules, recurring patterns, and cascading hour-deficit constraints — all driven through Home Assistant. |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
EV Trip Planner Integration — Multi-Trip Deferrable Load Management
Status: MVP Experimental — Seeking Contributors
Repository: informatico-madrid/ha-ev-trip-planner
Version: 0.5.24
Overview
This is an experimental Home Assistant custom component that manages EV charging schedules through EMHASS deferrable loads. It's currently an MVP — functional but with known technical debt and areas needing improvement.
The component transforms EV trip data (distance, departure/return times, charging power) into EMHASS-compatible deferrable load profiles, supporting multiple simultaneous trips with independent optimization per trip.
What Works
Window Calculation Algorithm (Core Contribution)
This is where the real innovation lies. The component implements a multi-dimensional charging window calculation that solves the EV charging scheduling problem across multiple trips with constrained time windows — a significantly more complex challenge than simple charging calculations.
The Algorithm Pipeline
Step 1: Energy Calculation per Trip
Step 2: Multi-Trip Window Calculation
The core function
calculate_multi_trip_charging_windows()chains charging windows across multiple trips:The algorithm considers:
Step 3: Backward Pass — Hours Deficit Propagation
When the total available time across all windows is insufficient for the required charging hours, the algorithm performs a backward pass to redistribute the deficit:
Example:
Step 4: SOC Milestone Deficit Propagation
A parallel backward pass handles SOC milestones:
Step 5: Power Profile Generation
The final step generates the 168-hour power profile matrix:
Dynamic Index Management
Each trip gets an EMHASS index (0-49) with persistence across restarts:
EMHASS Integration
The component creates a template sensor with 6 attributes that map directly to EMHASS parameters:
number_of_deferrable_loadsnumber_of_deferrable_loadsdef_total_hours_arraydef_total_hoursp_deferrable_nom_arrayP_deferrable_nomdef_start_timestep_arraydef_start_timestepdef_end_timestep_arraydef_end_timestepp_deferrable_matrixP_deferrableJinja2 Template Integration
Users configure EMHASS via Jinja2 templates in
optimize.yaml:Known Issues and Areas for Improvement
1. Control Panel UX (Technical Debt)
The current control panel has inherited technical debt from an earlier development phase. It uses hardcoded CSS gradients and lacks proper theming integration. The panel works functionally but the code quality is below the project's current standards.
What needs improvement:
2. SOC-Based Charging Start/Stop Automation
The component does not currently include automations for starting/stopping charging based on SOC thresholds. This is a planned feature but currently requires manual configuration.
What's needed:
3. Single Optimizer Dependency
Currently, the component only supports EMHASS as the optimization backend. The architecture uses
emhass_adapter.pyas an adapter pattern, prepared to add other optimizers (Tibber, custom) in the future, but this is not implemented.What's needed:
DeferrableLoadOptimizerprotocol/interface4. Planning Horizon is Static
The planning horizon is fixed at 7 days by default and configurable but static. It does not dynamically adapt to EMHASS's actual planning horizon.
What's needed:
Planned Improvements and Welcome Contributions
The following features are planned and contributions are welcome. If any of these interest you, please open an issue or PR.
High Priority
SOH (State of Health) Integration
Dynamic Charging Power
SOC-Based Charging Start/Stop Automations
Medium Priority
Multi-Vehicle Support
Optimizer Abstraction
DeferrableLoadOptimizerprotocol/interfaceLow Priority
Smart Learning
Dynamic Planning Horizon
Architecture Overview
Key Components
trip_manager.pyemhass_adapter.pycalculations.pycoordinator.pysensor.pyconfig_flow.pyservices.pyTotal: ~12,432 lines of Python code, 18 modules, 85+ unit tests, 8 E2E specs.
Development Methodology (Optional Context)
This project was developed using an AI-assisted spec-driven development methodology with:
This context is provided because it explains the architectural decisions and documentation quality. If you're interested in the development approach, see the _ai/ directory in the repository.
How to Contribute
High Priority Contributions (Most Needed)
SOH (State of Health) Integration — Medium/Complex
Dynamic Charging Power — Trivial
SOC-Based Automations — Quick Win
Quick Wins (Good for First-Time Contributors)
Medium Complexity
Complex
Getting Started
Prerequisites
Installation
optimize.yamlTesting
Questions I'd Like Community Input On
SOH integration: What vehicle APIs expose SOH data reliably? Should SOH be a separate integration layer or built into the component?
Maximum charging power: How do others manage max charging power limits? Is time-of-use aware limiting common?
SOC integration: What's the best approach for vehicle SOC integration and start/stop automations?
Optimizer abstraction: Has anyone implemented a similar pattern for pluggable optimization backends? What's the cleanest interface?
Multi-vehicle: How do others handle multiple EVs with EMHASS? Is the current single-vehicle-per-entry design a limitation?
Window calculation: Has anyone implemented a similar backward deficit propagation algorithm for other deferrable load types (thermal batteries, home batteries)?
License
MIT License — See LICENSE file for details.
This is an experimental MVP. Use at your own risk. The author is actively seeking contributors and collaborators.
All reactions