Home Automation · Open Source
Ford EV for Home Assistant: An Independent Range Model and the Real Cost of Driving
fordev4ha is an open-source Home Assistant integration for Ford electric vehicles. It keeps a self-calibrating range model independent of the car's drifting state of charge, prices every kWh with charging losses and solar, and reports what driving actually costs per 100 km.

What it is
fordev4ha is an open-source (MIT) Home Assistant integration for Ford battery-electric vehicles. It builds on FordConnect Query, the community integration that brings a Ford’s data into Home Assistant, and adds what the car’s own app does not provide:
- An independent range estimate that accounts for outside temperature and cabin climate, and recalibrates itself every time the car charges to 100 %.
- Reports: distance per day, week, month and year; energy used and charged; consumption; a charging log; charging cost; and the cost of driving per 100 km.
- Notifications: car left unlocked, door or window open, plug-in reminder, warning lights, charging finished, car data stopped, night activity, and a weekly summary.
- A ready-made dashboard that builds itself from the vehicle’s entities.
Everything is configured from the Home Assistant UI. There is no YAML to write and no entity ID to edit. It installs through HACS as a custom repository.
The project is not affiliated with, endorsed by, or connected to Ford Motor Company.
The problem: raw telemetry is not an answer
FordConnect Query exposes the vehicle as Home Assistant entities: state of charge, range, odometer, plug and charging state, locks, doors, windows, warning lights, location. That is raw telemetry. The questions an owner actually asks need accounting on top of it:
- How far will a full battery take me tomorrow, at tomorrow’s temperature?
- What did driving cost this month: not what was paid at the charger, but what the kilometres consumed?
- Is the car still unlocked in the driveway?
Two effects make the naive answers wrong.
State of charge drifts. On LFP batteries the displayed state of charge is only exact right after a charge to 100 %, and it drifts in between. The car’s own range estimate is derived from it, so it drifts too.
Charging cost is not driving cost. A battery is a buffer. One week shows a full charge and a large bill, the next week nothing. Dividing a week’s charging bill by that week’s kilometres produces noise, not a cost per kilometre.
Design decision: one integration, not YAML
The logic started as hand-written YAML packages on a single Home Assistant installation, tied to one car’s VIN-based entity IDs. Three ways to generalise it were considered:
- Generalised YAML packages. Rejected: no discovery, every user substitutes entity IDs by hand, learned values live in loose helper entities, and updating means copying files again.
- An integration for the data, blueprints for the notifications. Rejected: about eight imports per user, HACS cannot install blueprints, and the two halves drift apart between releases.
- One integration that does everything. Chosen. Discovery, accounting, the range model and notifications are Python inside the integration, state is persisted in its own versioned store, and the dashboard ships with it. It is the most code to write, but installation is a single step, behaviour is identical everywhere, and every part can be tested automatically.
Discovery matches FordConnect Query entities by their translation key, never by entity ID, so entities the user has renamed keep working.
The range model
The model keeps its own energy balance instead of following the car’s state of charge.
Energy out. After every trip, the trip’s energy is taken from a model battery:
| |
Driving energy rises 1 % per °C below 20 °C. Climate power depends on the gap between the outside temperature T and the cabin setpoint sp, and on whether heating or air conditioning normally runs while driving. a and b are the two factors the model learns.
Energy in. Energy reported by the charger is added to the model battery. If the car does not report charger energy for a session, the session’s state-of-charge rise is used instead.
Calibration at 100 %. When the car has stayed at 100 % for five minutes, the battery is known to be full, so the energy charged since the previous full charge is exactly what the car used in that cycle. The model compares that with its prediction and refits a and b by ridge least squares with a forgetting factor of 0.85: recent cycles count more, and a prior keeps a single unusual cycle from swinging the fit. The factors are bounded (driving 0.5 to 2, climate 0.2 to 3), and a cycle whose measured energy is outside 0.5 to 2 times the prediction is recorded but not used for fitting. The model battery is then reset to full. The error of each cycle and the learned factors are shown on the dashboard.
Capacity estimate. When the final charge of a cycle started below 80 %, the charger energy divided by the state-of-charge rise estimates what the charger delivers for a full battery. The sensor shows the median of the last five estimates next to the configured capacity. It is never applied automatically.
For battery chemistries whose state of charge is reliable below 100 %, an option also calibrates when a charge reaches a lower charge target. For LFP it stays off.
Pricing every kWh
Each kWh the car reports is priced at the moment it is counted, so time-of-use and dynamic tariffs come out right.
- Losses. The meter bills more than the car reports: the car counts energy after its onboard charger, while the meter also sees the losses of the onboard charger, the wallbox and the cable. The billed energy is the reported energy plus a configurable loss, 10 % on AC and 5 % on DC by default, chosen by the charging type the car reports.
- Location. A session is billed in one place: where the car was when its first energy was counted. At home the electricity price applies, as a fixed value or from any price entity; elsewhere, the public charging price.
- Solar. With a solar power sensor, solar production above the house base load covers home charging first. It is priced at what a solar kWh is worth to the owner, for example what exporting it would have earned.
Charges the integration did not see, such as those before installation, can be added with an action that also takes the amount actually paid, so an invoice can correct the estimate.
The cost of driving: an inventory method
To separate what driving costs from when the bill arrives, the battery is treated as one pool of energy with a monetary value:
- Each charge adds its cost to the pool’s value.
- The value divided by the energy in the battery is the battery energy price: the average cost of what is in the battery now, losses included.
- Every state-of-charge drop takes its share of the value out of the pool and adds it to the driving cost. Energy used while the car is parked is part of it, and is also reported on its own.
Cost per 100 km is the driving cost of a period divided by its distance, for the week, month, year and since the start. Everything paid is either used or still in the battery, so over a long period driving cost and charging cost converge. Week to week, however, the driving figure follows the kilometres, not the charging calendar. It is the weighted-average costing used for warehouse stock, applied to a battery.
Reliability in a home automation context
Home Assistant restarts, cloud APIs go quiet, and counters in the car reset. The integration treats all of these as normal operating conditions:
- Deltas against the last known value. Energy and distance are accounted as differences from the last known reading, so a gap in the data is counted when the data returns: never lost, never double-counted.
- Persistent state and restart recovery. Internal state lives in a versioned store, saved with a short delay after each change and once more on shutdown. On startup, a trip or charging session left open is reconciled against the car’s current state.
- Counter restarts. The car’s charger counter restarts when charging pauses and resumes within one session. When the session’s state-of-charge rise exceeds what the counter reported by more than 1.5 % of the battery, the difference is added, and the session records how much of its energy was estimated this way.
- No notification spam. Each alert fires once per occurrence and re-arms only after its condition has cleared, across restarts too. Every alert is also an event entity, so owners can build their own automations even with the built-in notifications switched off.
A dashboard without a build step
The dashboard is a Home Assistant dashboard strategy written as a plain ES module, with no bundler. The integration serves the file and loads it on every frontend page, so Ford EV appears under Community dashboards in the “Add dashboard” dialog without the user registering a resource by hand. It is regenerated each time it is opened, so new entities appear on their own. Take control turns it into an ordinary dashboard that can be edited freely.
There is one view per vehicle, with sections for Now, Location, Driving, Range estimate, Charging, Costs and Settings, stacked into a single column on a phone.
Privacy by design
- The integration makes no network calls of its own. It reads only FordConnect Query’s entities and the temperature, weather, price and solar entities the owner selects. No vehicle data leaves the Home Assistant instance.
- The diagnostics download removes the VIN, the entity IDs that contain it, and the notification targets, so it can be attached to a public issue.
- Tests run against fake vehicles with fake VINs.
Testing and CI
Every push runs:
- hassfest, Home Assistant’s own integration validator;
- HACS validation;
- ruff for linting;
- pytest with
pytest-homeassistant-custom-component, against fake FordConnect Query entities registered in a real Home Assistant test instance; - Node tests for the dashboard strategy.
The calculations (energy accounting, period rollover, trip energy, the calibration fit, unit conversion) are pure functions with no Home Assistant dependency, so they are tested in isolation. The suite also covers the awkward cases: data going unavailable mid-trip, a restart with a trip or charging session still open, an odometer going backwards, and instances configured for miles.
Getting started
Requirements: a Ford battery-electric vehicle supported by FordConnect Query (EU, UK and North America), Home Assistant 2026.5 or newer, and FordConnect Query set up and showing the vehicle.
- In HACS, add
https://github.com/mihaics/fordev4haas a custom repository of type Integration, download Ford EV, and restart Home Assistant. - Add the Ford EV integration, pick the vehicle, enter the usable battery capacity, and choose an outside temperature sensor or a weather entity.
- Create the dashboard: Settings > Dashboards > Add dashboard > Community dashboards > Ford EV.
- Charge to 100 % once. Every full charge is one calibration of the range model.
Source code, full documentation and releases: github.com/mihaics/fordev4ha. Issues and pull requests are welcome.
What carries over to production systems
Nothing here is specific to cars. The same principles apply to any system that turns unreliable telemetry into numbers people make decisions on:
- Account in deltas against the last known value, so outages delay figures instead of corrupting them.
- Keep domain logic in pure functions that can be tested without the platform around them.
- Separate cash flow from consumption when reporting cost.
- Validate a self-learning model against ground truth whenever ground truth is available, and bound what it is allowed to learn.
- Gate every release on automated checks, and keep personal data out of the repository by design.
Building a platform that has to turn noisy telemetry into reliable reporting? Contact us to discuss how SysOP Consulting can help.