Commit 0f10be4
Ravi Singh
feat: smartghar HA integration contract — /api/v1/* endpoints
AmbiSense now speaks the smartghar device protocol so the
smartghar-homeassistant custom integration auto-discovers it on the
network. Same protocol TankSync (aqualevel) already uses; the
integration PR adding presence-kind support is at
Techposts/smartghar-homeassistant#1
Discovery (netmgr.c):
- New mDNS service _smartghar._tcp on port 80 with TXT records
(hub_id, product=ambisense, manufacturer=SmartGhar, schema=1.0,
path=/api/v1/info). hub_id is ambisense_<MAC> so multiple
AmbiSense units on one network show up as distinct HA devices.
- Legacy _ambisense._http._tcp service kept for older tools.
REST contract (webui.c, +152 lines):
- GET /api/v1/info — hub identity (manufacturer, product, model,
fw_version, hub_id, host, ip, uptime_s, wifi_rssi, free_heap,
capabilities). Mirrors aqualevel hub schema so the integration
treats AmbiSense as another smartghar hub.
- GET /api/v1/devices — returns {devices: [...]} with one entry of
kind="presence" for AmbiSense's standalone-hub topology
(single-ESP32-doing-everything is exposed as a hub with one
virtual sub-device).
- PUT /api/v1/devices/0 — config writes (vacancy_secs, radar_kind);
returns updated device object so the integration reflects
changes immediately. Auth-gated by admin password cookie.
- POST /api/v1/hub/identify — flash status LED for ~3 s at 5 Hz
using status_led_oneshot(STATUS_LED_OTA, 3000). Auth-gated.
- POST /api/v1/hub/reboot — alias to /api/reboot, kept under the
contract path so future legacy /api refactors don't break the
integration.
Web UI (screens.tsx):
- System tab: removed the MQTT card (we explicitly chose the
WS+mDNS path over MQTT — see commit log) and replaced with a
SmartGhar HA integration card explaining auto-discovery + linking
the integration repo + the protocol doc.
- Presence tab HA card: leads with smartghar integration as
recommended; the RESTful /api/presence YAML recipe is moved
behind a <details> as the no-MQTT-no-custom-component fallback.
Cross-product spec (docs/SMARTGHAR-PROTOCOL.md, NEW):
- Protocol contract every Techposts IoT device honors so future
products (RidgeSync fingerprint lock, etc.) integrate with one
small additive PR to smartghar-homeassistant.
- Documents both topology models: standalone hub (AmbiSense,
mains-powered single ESP32) and hub+TX (TankSync, multi-sensor
with battery-powered TX nodes via short-range RF).
- Wire details: mDNS TXT keys, all /api/v1 endpoints + JSON
schemas, WS push contract, auth model, schema versioning rules.
- Adding a new product checklist + entity-builder template patches
for the integration repo.
- Per-kind device JSON templates (presence, tank, lock for
RidgeSync's design-ahead).
Build:
- ambisense.bin 0x1207a0 (~1.16 MB), 18% partition free.
Recovered ~150 KB by dropping the MQTT component (was at 9% free
in the v6.2.0-alpha.1 dev branch with mqtt + cJSON pulled in).
- UI bundle 98.5 KB raw, 28.8 KB gzipped.
Bench-tested clean-flash on ESP32-C3 d8:3b:da:35:06:f0:
- mDNS _smartghar._tcp advertises with all 5 TXT records.
- /api/v1/info, /api/v1/devices return valid JSON.
- /api/v1/devices/0 PUT round-trips vacancy_secs.
- /api/v1/hub/identify flashes the onboard LED visibly.
- Existing /api/* (web UI) endpoints unchanged.1 parent 9582cea commit 0f10be4
7 files changed
Lines changed: 619 additions & 11 deletions
File tree
- docs
- firmware/components
- netmgr
- webui
- frontend/src
0 commit comments