Support per-car charging plan time and max price for multi-car setups
Predbat already supports multiple cars via num_cars, with per-car settings such as car_charging_limit, car_charging_planned, car_charging_battery_size and car_charging_exclusive, plus a separate charging-slot sensor per car (binary_sensor.predbat_car_charging_slot, ..._slot_1, etc.).
However, select.predbat_car_charging_plan_time and car_charging_plan_max_price appear to be single, shared settings rather than per-car lists. This means two cars can have different target SOCs, but they are always planned against the same charge-by time and the same price cap.
In most setups both cars charge together overnight during the cheapest hours, so this isn't a blocker day to day. But it would be a useful improvement for cases where the cars have different battery sizes and finish at different times, one car needs to be ready by a specific time while the other doesn't, or only one car is present on a given night.
Would it be feasible to make car_charging_plan_time and car_charging_plan_max_price accept per-car lists (same pattern as car_charging_limit), so each of the num_cars cars can have its own independent schedule and price cap?
For context, discussion #3001 ("My setup to charge 2 cars with Predbat") shows another user working around the same limitation with manual input_select/template-sensor logic, suggesting there's real demand for native per-car scheduling.
Thanks for the detailed write-up, and for pointing at the discussion. This is an automated first-pass triage — a maintainer will review before any action is taken.
Classification: enhancement
What I found on current main (v9.10.3)
You have read the code correctly, and the good news is that most of what you are asking for already exists inside the planner.
plan_car_charging()is already per-car: it readsself.car_charging_plan_max_price[car_n]and parsesself.car_charging_plan_time[car_n]for the car it is planning, and each car already gets its own slot sensor. No planner change would be needed.- The Octopus Intelligent path already fills the ready time per car from your
octopus_ready_timeentries, so cars on IOG are not affected by this limitation. The gap is the Predbat-led path. - What is shared is only the config read.
get_car_charging_planned()fills both arrays the same way for every car, withself.get_arg("car_charging_plan_max_price", 0.0)andself.get_arg("car_charging_plan_time", "07:00:00")— noindex=car_n, and no_1,_2… siblings inCONFIG_ITEMS. Comparecar_charging_battery_size,car_charging_limitandcar_charging_exclusive, which a few lines earlier are read withindex=car_n, which is why those work per car. - Both settings are single Home Assistant entities (
select.predbat_car_charging_plan_time,input_number.predbat_car_charging_plan_max_price), so a plain list on those keys inapps.yamlis not a usable workaround today: there is no per-car read to consume it, and an invalid plan-time entry is caught inplan_car_charging()and every car falls back to 07:00 with a warning.
Shape a fix would probably take (my reading of the code, not a decision)
Follow the car_charging_rate family: add car_charging_plan_time_1…_7 and car_charging_plan_max_price_1…_7 config items, and read them in get_car_charging_planned() by the suffixed name, the way car_charging_rate already is. That family machinery is in place: UserInterface.car_list_families() / car_list_arg() split a base-name list in apps.yaml across a _1, _2… family, added for car_charging_rate in PR #5383, so car_charging_plan_time: ["06:00:00", "08:00:00"] would then work with only the siblings added. A maintainer will want to weigh that (seven more selects and seven more input_numbers, which every existing install would inherit) against an apps.yaml-only list; I have not decided anything here.
Related
- #662 ("Start time and charge rate for more than one car", opened Jan 2024, still open) is the earlier request for the per-car ready time half of this, and the maintainer answered "certainly doable" at the time. The per-car rate half of it did land later, as the
car_charging_ratefamily. Your request adds the per-car price cap, which #662 does not mention, so I have not closed this as a duplicate — but the ready-time part is the same ask and a fix should close both. - PR #5383 (merged) is the precedent for a car setting becoming per-car, and its notes mention the same trap you would hit:
apps.yamlvalues only seed the item default, so anyone who already hasinput_number.predbat_car_charging_plan_max_pricesitting at a value will need to set the per-car entities once after the change. - #3890 (and PRs #3891, #3892) is about a related but different ready-time limitation — a charge target more than 24 hours away — not per-car times.
Bot, can you develop a PR for this functionality please, adding additional select.predbat_car_charging_plan_time and car_charging_plan_max_price sensors as requested.
I believe the existing pattern is that car_charging_limit_1, _2, etc are only created based upon num_cars, so users do not get 7 sensors unnecessarily created, they only get the num_cars sensors created.
Changes will be required to code, tests and documentation to describe the new features.
@janipoussu-ui we have a draft change to implement the multi-car functionality you asked for
Could you please test by copying the following changed files from the PR https://github.com/springfall2008/batpred/pull/6432 over the top of these files in your Predbat directory? Take a copy of the existing ones first