EV-03: car charger seam, Alfen HA driver, read-only Car card
Read-only: nothing in this change writes to the charger. - app/chargers.py: ChargerDriver, AlfenHaDriver, UnavailableCharger, ChargerReading, CarTracker - options ev_charger/ev_current_entity/ev_max_a/ev_phases (default off), Settings group, validator, census - Car card on Home, unreachable row and notification, two-writer info row, MQTT sensors - car out of the House tile and the house profile - tools/chargersim.py charger model, test_ev03.py Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -36,7 +36,7 @@ sys.path.insert(0, os.path.join(HERE, "tools"))
|
||||
|
||||
from aiohttp import web as aioweb # noqa: E402
|
||||
|
||||
from app import homeview, packmode, web # noqa: E402
|
||||
from app import chargers, freshness, homeview, packmode, web # noqa: E402
|
||||
from app.main import Controller # noqa: E402
|
||||
from app.maintenance import DRAIN # noqa: E402
|
||||
from app.setuponly import SetupOnly # noqa: E402
|
||||
@@ -44,6 +44,7 @@ from app.peakguard import PeakDecision # noqa: E402
|
||||
from app.price import PricePoint, PriceProduct, PriceRead # noqa: E402
|
||||
from app.static_tariff import TariffPlan # noqa: E402
|
||||
import translations_lint as TL # noqa: E402
|
||||
from chargersim import SimCharger # noqa: E402
|
||||
|
||||
PRICES = [.24, .22, .21, .20, .21, .22, .24, .27, .26, .22, .18, .16, .15,
|
||||
.14, .16, .19, .23, .28, .33, .36, .34, .29, .26, .24]
|
||||
@@ -104,6 +105,61 @@ class Hass:
|
||||
return STATES
|
||||
|
||||
|
||||
# EV-03: the car states. A charger model behind the demo's Home Assistant; the
|
||||
# real `Controller._read_charger()` reads it, so the card is what the add-on
|
||||
# draws, not a picture.
|
||||
CAR_STATES = ("car", "car_none", "car_waiting", "car_full", "car_unreach",
|
||||
"car_setup")
|
||||
CAR_ENTITY = "number.wallbox_power_connector_max_current_socket_1"
|
||||
SIM = SimCharger()
|
||||
|
||||
|
||||
class CarHass(Hass):
|
||||
async def state(self, e):
|
||||
return SIM.states().get(e) or await super().state(e)
|
||||
|
||||
async def states(self):
|
||||
return list(STATES) + list(SIM.states().values())
|
||||
|
||||
|
||||
def car_setup(state):
|
||||
"""Put the model in the state's situation."""
|
||||
global SIM
|
||||
SIM = SimCharger(name="other" if state == "car_setup" else "wallbox")
|
||||
if state in ("car", "car_unreach"):
|
||||
SIM.plug_in()
|
||||
SIM.set_phases(3)
|
||||
SIM.set_current(16)
|
||||
elif state == "car_waiting":
|
||||
SIM.plug_in()
|
||||
SIM.set_current(0)
|
||||
elif state == "car_full":
|
||||
SIM.plug_in()
|
||||
SIM.set_current(10)
|
||||
SIM.car_full()
|
||||
SIM.tick(12)
|
||||
|
||||
|
||||
async def car_feed(c, state):
|
||||
"""The cycle's own read, once a second, like the control loop."""
|
||||
backdated = False
|
||||
n = 0
|
||||
while True:
|
||||
n += 1
|
||||
if state == "car_unreach" and n == 4:
|
||||
SIM.go_unavailable()
|
||||
SIM.tick(1)
|
||||
await c._read_charger(freshness.monotonic())
|
||||
if state == "car_unreach" and c.car.bad_since is not None \
|
||||
and not backdated:
|
||||
backdated = True # 12 minutes in, so the row and the note show
|
||||
c.car.bad_since -= 720.0
|
||||
c.car.bad_since_utc -= timedelta(seconds=720)
|
||||
if state == "car_full" and c.car.b_since is not None and n < 3:
|
||||
c.car.b_since -= 120.0 # the full dwell has passed
|
||||
await asyncio.sleep(1.0)
|
||||
|
||||
|
||||
KETTLE_READS = (-10, 1990, 1990, -10)
|
||||
KETTLE_COUNT = [0]
|
||||
|
||||
@@ -244,7 +300,13 @@ def controller(state):
|
||||
opts = dict(OPTS, shadow_mode="on" if state == "shadow" else "off")
|
||||
if state in P3:
|
||||
opts["battery_modes_enabled"] = True
|
||||
c = Controller(opts, Hass(), Store(), Pub(), stop=asyncio.Event())
|
||||
hass = Hass()
|
||||
if state in CAR_STATES:
|
||||
car_setup(state)
|
||||
opts.update(ev_charger="alfen_ha", ev_current_entity=CAR_ENTITY,
|
||||
ev_max_a=16, ev_phases="auto")
|
||||
hass = CarHass()
|
||||
c = Controller(opts, hass, Store(), Pub(), stop=asyncio.Event())
|
||||
c.auto = True
|
||||
now = datetime.now(timezone.utc)
|
||||
day0, _day1 = homeview.local_day(now)
|
||||
@@ -264,6 +326,12 @@ def controller(state):
|
||||
inv.last_write = 0.0
|
||||
c.grid = -10.0 if state != "shadow" else -2810.0
|
||||
c.pv_w = 3900.0
|
||||
if state in CAR_STATES:
|
||||
# 11 kW to the car on top of a 1.6 kW house, all from the roof
|
||||
c.grid, c.pv_w = 0.0, (12600.0 if state == "car" else 2400.0)
|
||||
for inv in c.inverters:
|
||||
inv.batt = 0.0
|
||||
c.car.stale_s = 15.0
|
||||
if state == "alarm":
|
||||
c.inverters[0].sign_wd.tripped = True
|
||||
if state in P3:
|
||||
@@ -327,9 +395,17 @@ async def main(state, port, host="127.0.0.1"):
|
||||
battery_modes_enabled=state in P3,
|
||||
inverters=[dict(i, bms_soc_floor=10)
|
||||
for i in OPTS["inverters"]])
|
||||
runner = aioweb.AppRunner(web.build_app(c, Supervisor(stored)))
|
||||
stored.update(ev_charger=c.o.get("ev_charger", "off"),
|
||||
ev_current_entity=c.o.get("ev_current_entity", ""),
|
||||
ev_max_a=c.o.get("ev_max_a", 16),
|
||||
ev_phases=c.o.get("ev_phases", "auto"))
|
||||
app = web.build_app(c, Supervisor(stored))
|
||||
runner = aioweb.AppRunner(app)
|
||||
await runner.setup()
|
||||
await aioweb.TCPSite(runner, host, port).start()
|
||||
if state in CAR_STATES:
|
||||
asyncio.get_running_loop().create_task(car_feed(c, state))
|
||||
main.app = app
|
||||
print(f"serving {state} on http://127.0.0.1:{port}/", flush=True)
|
||||
await asyncio.Event().wait()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user