wallmonitor 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- wallmonitor/__init__.py +3 -0
- wallmonitor/__main__.py +81 -0
- wallmonitor/alert_codes.json +70 -0
- wallmonitor/config.py +163 -0
- wallmonitor/db.py +675 -0
- wallmonitor/poller.py +630 -0
- wallmonitor/simulator.py +215 -0
- wallmonitor/static/__init__.py +1 -0
- wallmonitor/static/app.js +2050 -0
- wallmonitor/static/index.html +35 -0
- wallmonitor/static/style.css +181 -0
- wallmonitor/thermal.py +911 -0
- wallmonitor/web.py +378 -0
- wallmonitor-0.1.0.dist-info/METADATA +117 -0
- wallmonitor-0.1.0.dist-info/RECORD +17 -0
- wallmonitor-0.1.0.dist-info/WHEEL +4 -0
- wallmonitor-0.1.0.dist-info/entry_points.txt +3 -0
wallmonitor/web.py
ADDED
|
@@ -0,0 +1,378 @@
|
|
|
1
|
+
"""aiohttp web application: JSON API + Server-Sent Events + static UI.
|
|
2
|
+
|
|
3
|
+
Everything is served locally; the page loads no external assets, fonts, or
|
|
4
|
+
scripts, consistent with the project's local-network-only requirement.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from __future__ import annotations
|
|
8
|
+
|
|
9
|
+
import asyncio
|
|
10
|
+
import json
|
|
11
|
+
import logging
|
|
12
|
+
import time
|
|
13
|
+
from importlib import resources
|
|
14
|
+
|
|
15
|
+
from aiohttp import web
|
|
16
|
+
|
|
17
|
+
from . import thermal
|
|
18
|
+
from .db import Database
|
|
19
|
+
from .poller import EventBus, Poller
|
|
20
|
+
|
|
21
|
+
log = logging.getLogger("wallmonitor.web")
|
|
22
|
+
|
|
23
|
+
STATIC_PKG = "wallmonitor.static"
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def _float_q(request: web.Request, name: str, default: float) -> float:
|
|
27
|
+
"""Float query parameter, silently falling back on absent/garbage input
|
|
28
|
+
— range endpoints prefer a default window over a 400."""
|
|
29
|
+
try:
|
|
30
|
+
return float(request.query[name])
|
|
31
|
+
except (KeyError, ValueError):
|
|
32
|
+
return default
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def make_app(db: Database, bus: EventBus, poller: Poller | None) -> web.Application:
|
|
36
|
+
"""Assemble the HTTP app: static UI, JSON API, SSE stream, two ingests.
|
|
37
|
+
|
|
38
|
+
Conventions shared by every handler: range endpoints take from/to/... as
|
|
39
|
+
UTC epoch seconds with sensible default windows; all SQLite work hops to
|
|
40
|
+
a thread (the handlers themselves never block the loop); responses are
|
|
41
|
+
plain JSON dicts ready for app.js. Nothing here talks to the charger —
|
|
42
|
+
reads come from the DB, live data from the poller's EventBus. poller is
|
|
43
|
+
None only in tests that exercise the API without a device.
|
|
44
|
+
"""
|
|
45
|
+
app = web.Application()
|
|
46
|
+
|
|
47
|
+
# Without cache headers browsers cache heuristically, so after an update
|
|
48
|
+
# they may keep running stale UI code until a manual hard refresh.
|
|
49
|
+
# no-cache forces revalidation on every load — trivial cost on a LAN.
|
|
50
|
+
no_cache = {"Cache-Control": "no-cache"}
|
|
51
|
+
|
|
52
|
+
async def index(_request: web.Request) -> web.Response:
|
|
53
|
+
html = resources.files(STATIC_PKG).joinpath("index.html").read_text()
|
|
54
|
+
return web.Response(text=html, content_type="text/html", headers=no_cache)
|
|
55
|
+
|
|
56
|
+
async def static_file(request: web.Request) -> web.Response:
|
|
57
|
+
"""Serve app.js/style.css from the package, allowlisted by name —
|
|
58
|
+
read per-request from disk, so frontend-only changes deploy with a
|
|
59
|
+
git pull and a browser refresh, no service restart."""
|
|
60
|
+
name = request.match_info["name"]
|
|
61
|
+
if name not in ("app.js", "style.css"):
|
|
62
|
+
raise web.HTTPNotFound()
|
|
63
|
+
content = resources.files(STATIC_PKG).joinpath(name).read_text()
|
|
64
|
+
ctype = "application/javascript" if name.endswith(".js") else "text/css"
|
|
65
|
+
return web.Response(text=content, content_type=ctype, headers=no_cache)
|
|
66
|
+
|
|
67
|
+
async def api_alert_codes(_request: web.Request) -> web.Response:
|
|
68
|
+
data = resources.files("wallmonitor").joinpath("alert_codes.json").read_text()
|
|
69
|
+
return web.Response(text=data, content_type="application/json", headers=no_cache)
|
|
70
|
+
|
|
71
|
+
async def api_status(_request: web.Request) -> web.Response:
|
|
72
|
+
"""One-call snapshot for the header/tiles: newest sample from every
|
|
73
|
+
table, poller health, active alerts, the open session, row counts."""
|
|
74
|
+
now = time.time()
|
|
75
|
+
latest = await asyncio.to_thread(db.latest_vitals)
|
|
76
|
+
wifi = await asyncio.to_thread(db.latest_wifi)
|
|
77
|
+
lifetime = await asyncio.to_thread(db.latest_lifetime)
|
|
78
|
+
version = await asyncio.to_thread(db.latest_version)
|
|
79
|
+
alerts = await asyncio.to_thread(db.active_alerts)
|
|
80
|
+
counts = await asyncio.to_thread(db.counts)
|
|
81
|
+
session = None
|
|
82
|
+
sid = latest.get("session_id") if latest else None
|
|
83
|
+
if sid:
|
|
84
|
+
session = await asyncio.to_thread(db.session, int(sid))
|
|
85
|
+
return web.json_response(
|
|
86
|
+
{
|
|
87
|
+
"server_ts": now,
|
|
88
|
+
"poller": poller.status() if poller else None,
|
|
89
|
+
"vitals": latest,
|
|
90
|
+
"wifi": wifi,
|
|
91
|
+
"lifetime": lifetime,
|
|
92
|
+
"version": version,
|
|
93
|
+
"active_alerts": alerts,
|
|
94
|
+
"active_session": session,
|
|
95
|
+
"counts": counts,
|
|
96
|
+
}
|
|
97
|
+
)
|
|
98
|
+
|
|
99
|
+
async def api_vitals(request: web.Request) -> web.Response:
|
|
100
|
+
now = time.time()
|
|
101
|
+
t_from = _float_q(request, "from", now - 3600)
|
|
102
|
+
t_to = _float_q(request, "to", now)
|
|
103
|
+
max_points = int(_float_q(request, "points", 1500))
|
|
104
|
+
rows = await asyncio.to_thread(db.vitals_range, t_from, t_to, min(max_points, 5000))
|
|
105
|
+
return web.json_response({"from": t_from, "to": t_to, "samples": rows})
|
|
106
|
+
|
|
107
|
+
async def api_wifi(request: web.Request) -> web.Response:
|
|
108
|
+
now = time.time()
|
|
109
|
+
t_from = _float_q(request, "from", now - 24 * 3600)
|
|
110
|
+
t_to = _float_q(request, "to", now)
|
|
111
|
+
rows = await asyncio.to_thread(db.wifi_range, t_from, t_to)
|
|
112
|
+
return web.json_response({"from": t_from, "to": t_to, "samples": rows})
|
|
113
|
+
|
|
114
|
+
async def api_lifetime(request: web.Request) -> web.Response:
|
|
115
|
+
now = time.time()
|
|
116
|
+
t_from = _float_q(request, "from", now - 90 * 24 * 3600)
|
|
117
|
+
t_to = _float_q(request, "to", now)
|
|
118
|
+
rows = await asyncio.to_thread(db.lifetime_range, t_from, t_to)
|
|
119
|
+
return web.json_response({"from": t_from, "to": t_to, "samples": rows})
|
|
120
|
+
|
|
121
|
+
async def api_sessions(request: web.Request) -> web.Response:
|
|
122
|
+
now = time.time()
|
|
123
|
+
t_from = _float_q(request, "from", now - 90 * 24 * 3600)
|
|
124
|
+
t_to = _float_q(request, "to", now)
|
|
125
|
+
rows = await asyncio.to_thread(db.sessions_range, t_from, t_to)
|
|
126
|
+
return web.json_response({"sessions": rows})
|
|
127
|
+
|
|
128
|
+
async def api_session_detail(request: web.Request) -> web.Response:
|
|
129
|
+
"""One session with its samples and events. The 1 s pad around the
|
|
130
|
+
window catches boundary samples; the filter then drops any padded-in
|
|
131
|
+
rows that belong to a *different* session (back-to-back plug-ins)."""
|
|
132
|
+
try:
|
|
133
|
+
sid = int(request.match_info["id"])
|
|
134
|
+
except ValueError:
|
|
135
|
+
raise web.HTTPBadRequest(text="bad session id") from None
|
|
136
|
+
session = await asyncio.to_thread(db.session, sid)
|
|
137
|
+
if session is None:
|
|
138
|
+
raise web.HTTPNotFound(text="no such session")
|
|
139
|
+
end = session["end_ts"] or time.time()
|
|
140
|
+
samples = await asyncio.to_thread(db.vitals_range, session["start_ts"] - 1, end + 1, 2000)
|
|
141
|
+
samples = [
|
|
142
|
+
sample
|
|
143
|
+
for sample in samples
|
|
144
|
+
if sample.get("session_id") == sid or sample["ts"] >= session["start_ts"]
|
|
145
|
+
]
|
|
146
|
+
events = await asyncio.to_thread(db.events_range, session["start_ts"] - 1, end + 1)
|
|
147
|
+
return web.json_response({"session": session, "samples": samples, "events": events})
|
|
148
|
+
|
|
149
|
+
async def api_alerts(request: web.Request) -> web.Response:
|
|
150
|
+
now = time.time()
|
|
151
|
+
t_from = _float_q(request, "from", now - 90 * 24 * 3600)
|
|
152
|
+
t_to = _float_q(request, "to", now)
|
|
153
|
+
active = await asyncio.to_thread(db.active_alerts)
|
|
154
|
+
history = await asyncio.to_thread(db.alerts_range, t_from, t_to)
|
|
155
|
+
return web.json_response({"active": active, "history": history})
|
|
156
|
+
|
|
157
|
+
async def api_forecasts(request: web.Request) -> web.Response:
|
|
158
|
+
"""Recorded derate-forecast snapshots — what the model said at each
|
|
159
|
+
30 s charging tick, i.e. exactly what the amp controller saw. Seeds
|
|
160
|
+
the live chart's prediction history across reloads and tab switches."""
|
|
161
|
+
now = time.time()
|
|
162
|
+
t_from = _float_q(request, "from", now - 24 * 3600)
|
|
163
|
+
t_to = _float_q(request, "to", now)
|
|
164
|
+
rows = await asyncio.to_thread(db.forecast_range, t_from, t_to)
|
|
165
|
+
return web.json_response({"from": t_from, "to": t_to, "samples": rows})
|
|
166
|
+
|
|
167
|
+
async def api_events(request: web.Request) -> web.Response:
|
|
168
|
+
"""Event log, newest first; ?kinds=a,b,c filters server-side so the
|
|
169
|
+
timeline's category chips don't pull thousands of unwanted rows."""
|
|
170
|
+
now = time.time()
|
|
171
|
+
t_from = _float_q(request, "from", now - 7 * 24 * 3600)
|
|
172
|
+
t_to = _float_q(request, "to", now)
|
|
173
|
+
kinds = request.query.get("kinds")
|
|
174
|
+
kind_list = [kind for kind in kinds.split(",") if kind] if kinds else None
|
|
175
|
+
rows = await asyncio.to_thread(db.events_range, t_from, t_to, kind_list)
|
|
176
|
+
return web.json_response({"events": rows})
|
|
177
|
+
|
|
178
|
+
# The BLE amp controller acts on this monitor's forecasts but runs as a
|
|
179
|
+
# separate process; these are the only kinds it may write, so the timeline
|
|
180
|
+
# stays curated rather than becoming a generic log sink.
|
|
181
|
+
AMP_EVENT_KINDS = ("amp_capped", "amp_restored", "amp_adjust_failed")
|
|
182
|
+
|
|
183
|
+
async def api_event_ingest(request: web.Request) -> web.Response:
|
|
184
|
+
"""Record an amp-controller action as a first-class event.
|
|
185
|
+
|
|
186
|
+
Timestamp is server-side on receipt, like every other ingest path."""
|
|
187
|
+
try:
|
|
188
|
+
body = await request.json()
|
|
189
|
+
except ValueError:
|
|
190
|
+
return web.json_response({"error": "invalid json"}, status=400)
|
|
191
|
+
kind = body.get("kind")
|
|
192
|
+
if kind not in AMP_EVENT_KINDS:
|
|
193
|
+
return web.json_response({"error": "unknown kind"}, status=400)
|
|
194
|
+
detail = body.get("detail")
|
|
195
|
+
if detail is not None and not isinstance(detail, dict):
|
|
196
|
+
return web.json_response({"error": "detail must be an object"}, status=400)
|
|
197
|
+
if detail is not None and len(json.dumps(detail)) > 2048:
|
|
198
|
+
return web.json_response({"error": "detail too large"}, status=400)
|
|
199
|
+
ts = time.time()
|
|
200
|
+
await asyncio.to_thread(db.add_event, ts, kind, detail)
|
|
201
|
+
bus.publish({"type": "event", "ts": ts, "kind": kind, "detail": detail})
|
|
202
|
+
return web.json_response({"ok": True, "ts": ts, "kind": kind})
|
|
203
|
+
|
|
204
|
+
# Model parameters change only as new sessions land, so the (SQLite-heavy)
|
|
205
|
+
# history fit is cached; the live prediction is computed on every call.
|
|
206
|
+
thermal_fit: dict = {"params": None, "fits": [], "ts": 0.0}
|
|
207
|
+
|
|
208
|
+
async def api_thermal(request: web.Request) -> web.Response:
|
|
209
|
+
"""The full thermal picture: fitted model, live forecast, per-segment
|
|
210
|
+
fits, drift verdict, baseline anchor. Also what the BLE amp
|
|
211
|
+
controller polls every 30 s. ?refit busts the 6 h fit cache."""
|
|
212
|
+
now = time.time()
|
|
213
|
+
if (
|
|
214
|
+
thermal_fit["params"] is None
|
|
215
|
+
or now - thermal_fit["ts"] > 6 * 3600
|
|
216
|
+
or "refit" in request.query
|
|
217
|
+
):
|
|
218
|
+
fits = await asyncio.to_thread(thermal.fit_sessions, db, now)
|
|
219
|
+
thermal_fit["fits"] = fits
|
|
220
|
+
thermal_fit["params"] = thermal.fit_history(db, now, fits=fits)
|
|
221
|
+
thermal_fit["ts"] = now
|
|
222
|
+
result = await asyncio.to_thread(thermal.predict, db, now, thermal_fit["params"])
|
|
223
|
+
anchor = await asyncio.to_thread(thermal.baseline_anchor, db)
|
|
224
|
+
return web.json_response(
|
|
225
|
+
{
|
|
226
|
+
"server_ts": now,
|
|
227
|
+
**result,
|
|
228
|
+
"drift": thermal.detect_drift(thermal_fit["fits"], anchor_ts=anchor),
|
|
229
|
+
"session_fits": thermal_fit["fits"],
|
|
230
|
+
"baseline_anchor_ts": anchor,
|
|
231
|
+
}
|
|
232
|
+
)
|
|
233
|
+
|
|
234
|
+
def _num(fields: dict, *keys: str) -> float | None:
|
|
235
|
+
"""First key that parses as a float, in priority order — how the
|
|
236
|
+
ambient ingest prefers metric fields over the Ecowitt imperial ones."""
|
|
237
|
+
for key in keys:
|
|
238
|
+
value = fields.get(key)
|
|
239
|
+
if value is None or value == "":
|
|
240
|
+
continue
|
|
241
|
+
try:
|
|
242
|
+
return float(value)
|
|
243
|
+
except (TypeError, ValueError):
|
|
244
|
+
continue
|
|
245
|
+
return None
|
|
246
|
+
|
|
247
|
+
async def api_ambient_ingest(request: web.Request) -> web.Response:
|
|
248
|
+
"""Receive a garage ambient reading from a LAN sensor.
|
|
249
|
+
|
|
250
|
+
Speaks two dialects: the Ecowitt gateway "customized upload"
|
|
251
|
+
(form-encoded, Fahrenheit/inHg fields — point the gateway's custom
|
|
252
|
+
server at this path) and plain JSON ({"temp_c": ..} with optional
|
|
253
|
+
humidity_pct/pressure_hpa) for anything else on the network (Shelly
|
|
254
|
+
action URLs, a curl in a cron job). Metric wins when both appear.
|
|
255
|
+
|
|
256
|
+
JSON may also carry "source" naming the reporter. "car" is special:
|
|
257
|
+
it marks a mobile sensor (a vehicle parked in the garage), which the
|
|
258
|
+
thermal model uses only when no stationary sensor is reporting."""
|
|
259
|
+
if request.content_type == "application/json":
|
|
260
|
+
try:
|
|
261
|
+
fields = dict(await request.json())
|
|
262
|
+
except json.JSONDecodeError:
|
|
263
|
+
return web.json_response({"error": "invalid JSON"}, status=400)
|
|
264
|
+
source = str(fields.pop("source", "") or "").strip().lower()[:32] or "json"
|
|
265
|
+
else:
|
|
266
|
+
fields = dict(await request.post())
|
|
267
|
+
source = "ecowitt"
|
|
268
|
+
fields.pop("PASSKEY", None) # gateway auth token; not ours to keep
|
|
269
|
+
temp_c = _num(fields, "temp_c")
|
|
270
|
+
if temp_c is None:
|
|
271
|
+
# Ecowitt: tempinf is the gateway's own (indoor) sensor — the one
|
|
272
|
+
# in the garage; tempf/temp1f are add-on RF channels.
|
|
273
|
+
temp_f = _num(fields, "tempinf", "tempf", "temp1f")
|
|
274
|
+
temp_c = (temp_f - 32.0) * 5.0 / 9.0 if temp_f is not None else None
|
|
275
|
+
if temp_c is None or not (-40.0 <= temp_c <= 85.0):
|
|
276
|
+
return web.json_response({"error": "no usable temperature"}, status=400)
|
|
277
|
+
humidity = _num(fields, "humidity_pct", "humidityin", "humidity", "humidity1")
|
|
278
|
+
pressure = _num(fields, "pressure_hpa")
|
|
279
|
+
if pressure is None:
|
|
280
|
+
inhg = _num(fields, "baromrelin", "baromabsin")
|
|
281
|
+
pressure = inhg * 33.8639 if inhg is not None else None
|
|
282
|
+
now = time.time()
|
|
283
|
+
await asyncio.to_thread(db.insert_ambient, now, temp_c, humidity, pressure, fields, source)
|
|
284
|
+
return web.json_response(
|
|
285
|
+
{"ok": True, "ts": now, "temp_c": round(temp_c, 2), "source": source}
|
|
286
|
+
)
|
|
287
|
+
|
|
288
|
+
async def api_ambient_history(request: web.Request) -> web.Response:
|
|
289
|
+
now = time.time()
|
|
290
|
+
t_from = _float_q(request, "from", now - 24 * 3600)
|
|
291
|
+
t_to = _float_q(request, "to", now)
|
|
292
|
+
rows = await asyncio.to_thread(db.ambient_range, t_from, t_to)
|
|
293
|
+
latest = await asyncio.to_thread(db.latest_ambient)
|
|
294
|
+
return web.json_response({"samples": rows, "latest": latest})
|
|
295
|
+
|
|
296
|
+
async def api_baseline_anchor(request: web.Request) -> web.Response:
|
|
297
|
+
"""Set (POST {"ts": ...}, default now) or clear (DELETE) the
|
|
298
|
+
verified-baseline anchor. Fits before the anchor stay on the chart
|
|
299
|
+
but leave the drift comparison: set it after the hardware has been
|
|
300
|
+
inspected and verified so the baseline means "verified healthy".
|
|
301
|
+
|
|
302
|
+
Either change re-evaluates the drift verdict right away — the alert
|
|
303
|
+
otherwise only updates when a session ends, which can latch a
|
|
304
|
+
no-longer-justified alert for as long as the vehicle stays plugged
|
|
305
|
+
in (or hide a re-justified one after the anchor is cleared)."""
|
|
306
|
+
if request.method == "DELETE":
|
|
307
|
+
await asyncio.to_thread(db.delete_setting, thermal.BASELINE_ANCHOR_KEY)
|
|
308
|
+
await asyncio.to_thread(db.add_event, time.time(), "baseline_anchor_cleared", None)
|
|
309
|
+
if poller is not None:
|
|
310
|
+
await poller.recheck_thermal_drift(time.time())
|
|
311
|
+
return web.json_response({"baseline_anchor_ts": None})
|
|
312
|
+
try:
|
|
313
|
+
body = await request.json() if request.can_read_body else {}
|
|
314
|
+
except json.JSONDecodeError:
|
|
315
|
+
return web.json_response({"error": "invalid JSON"}, status=400)
|
|
316
|
+
ts = body.get("ts", time.time())
|
|
317
|
+
if not isinstance(ts, (int, float)):
|
|
318
|
+
return web.json_response({"error": "ts must be a number"}, status=400)
|
|
319
|
+
await asyncio.to_thread(db.set_setting, thermal.BASELINE_ANCHOR_KEY, repr(float(ts)))
|
|
320
|
+
await asyncio.to_thread(db.add_event, time.time(), "baseline_anchor_set", {"ts": float(ts)})
|
|
321
|
+
if poller is not None:
|
|
322
|
+
await poller.recheck_thermal_drift(time.time())
|
|
323
|
+
return web.json_response({"baseline_anchor_ts": float(ts)})
|
|
324
|
+
|
|
325
|
+
async def api_stream(request: web.Request) -> web.StreamResponse:
|
|
326
|
+
"""Server-Sent Events: one EventBus subscription per connection.
|
|
327
|
+
|
|
328
|
+
Protocol: every message is an unnamed `data: <json>` frame whose
|
|
329
|
+
`type` field discriminates (vitals | wifi | lifetime | event |
|
|
330
|
+
thermal); `: connected` / `: keepalive` comment frames keep proxies
|
|
331
|
+
and EventSource happy. No event ids, so reconnects start fresh —
|
|
332
|
+
clients re-seed history over the JSON API, which app.js does on
|
|
333
|
+
view mount anyway."""
|
|
334
|
+
response = web.StreamResponse(
|
|
335
|
+
headers={
|
|
336
|
+
"Content-Type": "text/event-stream",
|
|
337
|
+
"Cache-Control": "no-cache",
|
|
338
|
+
"Connection": "keep-alive",
|
|
339
|
+
}
|
|
340
|
+
)
|
|
341
|
+
await response.prepare(request)
|
|
342
|
+
queue = bus.subscribe()
|
|
343
|
+
try:
|
|
344
|
+
await response.write(b": connected\n\n")
|
|
345
|
+
while True:
|
|
346
|
+
try:
|
|
347
|
+
msg = await asyncio.wait_for(queue.get(), timeout=15.0)
|
|
348
|
+
except TimeoutError:
|
|
349
|
+
await response.write(b": keepalive\n\n")
|
|
350
|
+
continue
|
|
351
|
+
payload = json.dumps(msg).encode()
|
|
352
|
+
await response.write(b"data: " + payload + b"\n\n")
|
|
353
|
+
except (ConnectionResetError, asyncio.CancelledError):
|
|
354
|
+
pass
|
|
355
|
+
finally:
|
|
356
|
+
bus.unsubscribe(queue)
|
|
357
|
+
return response
|
|
358
|
+
|
|
359
|
+
app.router.add_get("/", index)
|
|
360
|
+
app.router.add_get("/static/{name}", static_file)
|
|
361
|
+
app.router.add_get("/api/alert-codes", api_alert_codes)
|
|
362
|
+
app.router.add_get("/api/status", api_status)
|
|
363
|
+
app.router.add_get("/api/vitals", api_vitals)
|
|
364
|
+
app.router.add_get("/api/wifi", api_wifi)
|
|
365
|
+
app.router.add_get("/api/lifetime", api_lifetime)
|
|
366
|
+
app.router.add_get("/api/sessions", api_sessions)
|
|
367
|
+
app.router.add_get("/api/sessions/{id}", api_session_detail)
|
|
368
|
+
app.router.add_get("/api/alerts", api_alerts)
|
|
369
|
+
app.router.add_get("/api/thermal", api_thermal)
|
|
370
|
+
app.router.add_post("/api/thermal/baseline-anchor", api_baseline_anchor)
|
|
371
|
+
app.router.add_delete("/api/thermal/baseline-anchor", api_baseline_anchor)
|
|
372
|
+
app.router.add_post("/api/ambient", api_ambient_ingest)
|
|
373
|
+
app.router.add_get("/api/ambient", api_ambient_history)
|
|
374
|
+
app.router.add_get("/api/forecasts", api_forecasts)
|
|
375
|
+
app.router.add_get("/api/events", api_events)
|
|
376
|
+
app.router.add_post("/api/events", api_event_ingest)
|
|
377
|
+
app.router.add_get("/api/stream", api_stream)
|
|
378
|
+
return app
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
Metadata-Version: 2.3
|
|
2
|
+
Name: wallmonitor
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Local-only monitoring and recording UI for a Tesla Wall Connector Gen 3
|
|
5
|
+
Keywords: tesla,wall-connector,ev-charging,monitoring,self-hosted,thermal-model
|
|
6
|
+
Author: Fernando Gonzalez
|
|
7
|
+
License: MIT
|
|
8
|
+
Classifier: Development Status :: 4 - Beta
|
|
9
|
+
Classifier: Environment :: Web Environment
|
|
10
|
+
Classifier: Intended Audience :: End Users/Desktop
|
|
11
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
14
|
+
Classifier: Topic :: Home Automation
|
|
15
|
+
Classifier: Topic :: System :: Monitoring
|
|
16
|
+
Requires-Dist: aiohttp>=3.13.5,<4
|
|
17
|
+
Requires-Dist: tesla-wall-connector>=1.2.0,<2
|
|
18
|
+
Requires-Python: >=3.11
|
|
19
|
+
Project-URL: Homepage, https://github.com/zebraengine/wallmonitor
|
|
20
|
+
Project-URL: Repository, https://github.com/zebraengine/wallmonitor
|
|
21
|
+
Project-URL: Issues, https://github.com/zebraengine/wallmonitor/issues
|
|
22
|
+
Description-Content-Type: text/markdown
|
|
23
|
+
|
|
24
|
+
# wallmonitor
|
|
25
|
+
|
|
26
|
+
A **local-only** companion for the Tesla Wall Connector Gen 3 that grew well
|
|
27
|
+
beyond reading data off the charger: it records everything the device
|
|
28
|
+
reports, turns that history into a thermal model fitted to *your* install,
|
|
29
|
+
forecasts derates before they happen (with the charge-current cap that
|
|
30
|
+
avoids them), watches for connector degradation with honest statistics, and
|
|
31
|
+
pushes actionable warnings to your browser or phone.
|
|
32
|
+
|
|
33
|
+
Everything stays on your machine and your LAN: the only network traffic is
|
|
34
|
+
HTTP GETs to the charger's local API, storage is a local SQLite file, and the
|
|
35
|
+
web UI serves no external assets (no CDNs, fonts, or analytics).
|
|
36
|
+
|
|
37
|
+
## Try it in 30 seconds
|
|
38
|
+
|
|
39
|
+
No hardware needed — demo mode runs a built-in charger simulator:
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
uvx wallmonitor --demo
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
Then open <http://127.0.0.1:8480>.
|
|
46
|
+
|
|
47
|
+
Against your real Wall Connector (find its IP in your router, or use the
|
|
48
|
+
`TeslaWallConnector_XXXXXX.local` hostname; add `--split-phase` on a North
|
|
49
|
+
American split-phase install):
|
|
50
|
+
|
|
51
|
+
```bash
|
|
52
|
+
uvx wallmonitor --host 192.168.1.50 --split-phase
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
All history lands in a single `wallmonitor.db` SQLite file — back up that
|
|
56
|
+
one file and you have everything. For every option, and for running it as a
|
|
57
|
+
systemd service on an always-on box, see [Running wallmonitor](https://github.com/zebraengine/wallmonitor/blob/main/docs/running.md).
|
|
58
|
+
|
|
59
|
+
## At a glance
|
|
60
|
+
|
|
61
|
+
- Full-fidelity recording — every response stored with its complete raw JSON
|
|
62
|
+
- Live dashboard (SSE) with rolling charts, an active-alert banner, and a
|
|
63
|
+
live derate-forecast chart: measured handle temperature against the
|
|
64
|
+
model's projected plateau and the trip threshold, projection drawn
|
|
65
|
+
forward so the predicted trip intercept is visible on the chart
|
|
66
|
+
- Session review: energy, peak/average power, per-phase telemetry, drillable charts
|
|
67
|
+
- Event timeline with range presets, category filters, and paging
|
|
68
|
+
- Alert decoding and EVSE-state labels, each marked verified vs community-reported
|
|
69
|
+
- Wi-Fi health history and connectivity events
|
|
70
|
+
- **Thermal derate forecast** — a per-install fitted model predicts alert 40
|
|
71
|
+
live and suggests the highest current that avoids the 50% foldback
|
|
72
|
+
- **Automatic derate prevention** — an optional daemon caps the vehicle's
|
|
73
|
+
charge current through a least-privilege BLE pairing when the forecast
|
|
74
|
+
firms up, and restores it once the risk clears
|
|
75
|
+
- **Degradation watch** — ambient-corrected heat-rise trend with confidence
|
|
76
|
+
intervals and a verified-baseline anchor, so "getting worse" is a
|
|
77
|
+
statistical claim, not a vibe
|
|
78
|
+
- **Actionable notifications, local-only** — browser push and LAN
|
|
79
|
+
webhook/self-hosted ntfy for phones, with a systemd + Docker deploy recipe
|
|
80
|
+
- Resilience: seamless restarts, downtime recorded as explicit gap events,
|
|
81
|
+
sensor-glitch quarantine
|
|
82
|
+
|
|
83
|
+
## Works out of the box — everything else is additive
|
|
84
|
+
|
|
85
|
+
The core needs nothing but the charger. Integrations are optional, degrade
|
|
86
|
+
gracefully when absent, and the absence paths are covered by the test suite:
|
|
87
|
+
without an ambient sensor the charger doubles as its own thermometer, with
|
|
88
|
+
no webhook configured notifications are a tested no-op, and TeslaMate /
|
|
89
|
+
ntfy / ESP32-BLE each plug into a generic interface (`POST /api/ambient`, a
|
|
90
|
+
plain LAN webhook, a REST call) rather than being wired into the core.
|
|
91
|
+
|
|
92
|
+
## Documentation
|
|
93
|
+
|
|
94
|
+
| Page | What's in it |
|
|
95
|
+
|---|---|
|
|
96
|
+
| [Running wallmonitor](https://github.com/zebraengine/wallmonitor/blob/main/docs/running.md) | Every option, systemd service install, tests |
|
|
97
|
+
| [What gets recorded](https://github.com/zebraengine/wallmonitor/blob/main/docs/recording.md) | Recording fidelity, sessions, events, alert/EVSE label verification, resilience |
|
|
98
|
+
| [Thermal model](https://github.com/zebraengine/wallmonitor/blob/main/docs/thermal-model.md) | The derate forecast and the degradation watch, in full detail |
|
|
99
|
+
| [Amp control](https://github.com/zebraengine/wallmonitor/blob/main/docs/amp-control.md) | Automatic derate prevention over BLE: design, guards, backtesting |
|
|
100
|
+
| [Ambient sensing](https://github.com/zebraengine/wallmonitor/blob/main/docs/ambient-sensors.md) | Garage sensors (Ecowitt or any JSON poster), placement, contamination checks, the TeslaMate car bridge |
|
|
101
|
+
| [Notifications](https://github.com/zebraengine/wallmonitor/blob/main/docs/notifications.md) | Browser push and self-hosted ntfy phone alerts |
|
|
102
|
+
| [Measured charging efficiency](https://github.com/zebraengine/wallmonitor/blob/main/docs/efficiency.md) | What three cross-referenced meters say about wall-to-battery efficiency |
|
|
103
|
+
|
|
104
|
+
## Tests
|
|
105
|
+
|
|
106
|
+
```bash
|
|
107
|
+
uv run pytest
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
The suite runs the full pipeline against the simulator — polling, session
|
|
111
|
+
detection, alert lifecycle, the web API, and the thermal model end to end.
|
|
112
|
+
|
|
113
|
+
## License
|
|
114
|
+
|
|
115
|
+
[MIT](https://github.com/zebraengine/wallmonitor/blob/main/LICENSE). Built on the
|
|
116
|
+
[`tesla-wall-connector`](https://github.com/einarhauks/tesla-wall-connector)
|
|
117
|
+
library (MIT, by Einar Bragi Hauksson).
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
wallmonitor/__init__.py,sha256=l8H0QOIIui7WivJNcEtbw4u77qyAZyJaoNIBpXGnNeE,102
|
|
2
|
+
wallmonitor/__main__.py,sha256=i-4lXxtNvnhTQOieNXzWUW8OLacFUWp55iee48HfUrE,2508
|
|
3
|
+
wallmonitor/alert_codes.json,sha256=ukPUj49obMcGX35noaNKsimlQmolwJAAHqHGUT3veZE,3739
|
|
4
|
+
wallmonitor/config.py,sha256=HCRPNhB302TV0hD-VG3FeB9KPaJHFb4RcTh6erjEy9s,6621
|
|
5
|
+
wallmonitor/db.py,sha256=jb2X3iGPocGjqPQjPLZ8mBNTttBBtZyrfIiLajmsdhc,28924
|
|
6
|
+
wallmonitor/poller.py,sha256=TKU4BIVvy8eaJYplivD0OIBrubkqJdRLuY9IBhwRzW8,31104
|
|
7
|
+
wallmonitor/simulator.py,sha256=hZJhYj5GoKpaxC0gQaqxJuUDocTaKqE-v4dlMoFpOCM,8935
|
|
8
|
+
wallmonitor/static/__init__.py,sha256=RWzrpc52x5bDXjIjOmxox-KoXxS2QiGhBpp7ieQ2AIQ,83
|
|
9
|
+
wallmonitor/static/app.js,sha256=a_A5etfG-fjp1T4hv1Y3MOd3h86YqpiOK-GJ7rszMzM,105265
|
|
10
|
+
wallmonitor/static/index.html,sha256=I_TU1U4e752eulbRXHnkcpvAVIvVVQWzhBGPPcfcC5w,1343
|
|
11
|
+
wallmonitor/static/style.css,sha256=YmfPGrTtSFdGp4hpW2AigIrNX2Ko1rezRXMZvWQg8UU,8418
|
|
12
|
+
wallmonitor/thermal.py,sha256=peDZapqsi-nD0YbNZOXA7wwv774t3fLm-eYqMhIDLcU,42209
|
|
13
|
+
wallmonitor/web.py,sha256=w52rrDeu1VvLgl-6c6H020jrmhhX5sjFfCRmogVWlPc,18442
|
|
14
|
+
wallmonitor-0.1.0.dist-info/WHEEL,sha256=4OL6Foqnnp3xRY5wMkjgc25_i5YJC6dKsC6LPcjqEoU,80
|
|
15
|
+
wallmonitor-0.1.0.dist-info/entry_points.txt,sha256=YcLCCpSBM1H8gLPKG-1hhZQcTfOK9IAXa-o1dG_6yzc,59
|
|
16
|
+
wallmonitor-0.1.0.dist-info/METADATA,sha256=cMHfQtyjcku2urrLY_Z-CXNSwmvQvh051sQmiKyZqa0,5884
|
|
17
|
+
wallmonitor-0.1.0.dist-info/RECORD,,
|