li3: add Lithionics Li3 house battery BMS -> Home Assistant MQTT
Publishes the RV's 12V LiFePO4 house battery to HA via MQTT discovery (pack voltage, 4 cell voltages, current, SOC, BMS/battery temp, status). Connects over the battery's BLE HM-10 UART module (service ffe0/char ffe1, no pairing) using bleak; protocol reverse-engineered from the com.lithionics.bms Android app's own BLE/parsing code. Deliberately named li3/ and van-li3-battery, not battery/van-battery — that name is reserved for the host's own AC/UPS power-supply monitor (different hardware, unrelated concern). Self-heals a bluetoothd discovery-state wedge (Discovering stuck "yes", connects failing with le-connection-abort-by-local) that shows up after repeated failed connects to this device on the Pi's onboard adapter: the daemon retries scan/connect internally (MQTT session and HA entities stay up across retries) and restarts bluetooth.service itself after 3 consecutive scan failures, rate-limited to once per 5 min.
This commit is contained in:
@@ -143,6 +143,16 @@ This directory is the source of truth. The live system files live under `/etc`,
|
||||
The `hbc` binary itself (venv at `~/venvs/hbd`, symlink `~/bin/hbc`) is installed once via the
|
||||
heartbeat project's own installer — see §4. `deploy.sh` only starts the service once it exists.
|
||||
|
||||
### `li3/` — RV house battery (BLE BMS → MQTT/HA)
|
||||
| file | → installs to | purpose |
|
||||
|---|---|---|
|
||||
| `van-li3-battery` | `/usr/local/sbin/van-li3-battery` | BLE→MQTT daemon (Python, bleak + paho-mqtt): reads the Lithionics Li3 BMS, publishes HA MQTT discovery + state |
|
||||
| `config.json.example` | → `/etc/van-li3/config.json` (seeded if absent) | BLE address, broker, MQTT topic/discovery **template**; real file is 0600, **not** in the repo |
|
||||
| `van-li3-battery.service` | `/etc/systemd/system/van-li3-battery.service` | `Restart=always` |
|
||||
|
||||
Not to be confused with `power/van-battery` — that's the host's own AC/battery power
|
||||
supply (laptop UPS-style monitor), unrelated hardware and purpose.
|
||||
|
||||
### `ha/` — Home Assistant (native container)
|
||||
| file | → installs to | purpose |
|
||||
|---|---|---|
|
||||
@@ -256,6 +266,31 @@ paho 2.x callback API.
|
||||
- Note: the broker holds an ancient *retained* message on this topic from a 2023
|
||||
OwnTracks device (tid `RV`, Winegard SSID); our publishes are not retained.
|
||||
|
||||
### Li3 battery monitor (`van-li3-battery`)
|
||||
Publishes the RV's 12V LiFePO4 house battery (Lithionics Li3, BLE HM-10 UART module —
|
||||
service `ffe0`/char `ffe1`, no pairing) to Home Assistant as 10 sensor entities (pack
|
||||
voltage, 4 cell voltages, current, SOC, BMS/battery temperature, status) via MQTT
|
||||
discovery. Protocol (CSV telemetry lines after sending `$traceon`+`$info`) reverse-
|
||||
engineered from the `com.lithionics.bms` Android app's own BLE/parsing code — see the
|
||||
script's docstring for the full field layout.
|
||||
- Not the same battery as `power/van-battery` (host's own AC/UPS power supply) —
|
||||
different hardware, different concern, deliberately different naming.
|
||||
- Broker credentials live only in `/etc/van-li3/config.json` (0600, seeded from
|
||||
`li3/config.json.example` — edit after first deploy, same pattern as `van-gps`).
|
||||
- **Self-healing BLE**: scan/connect retries happen *inside* the running process (MQTT
|
||||
session and HA entities stay up across them, no flapping) rather than relying on
|
||||
systemd restarts. This Pi's onboard Bluetooth adapter (Cypress/CYW43) occasionally
|
||||
wedges bluetoothd's discovery state after a run of failed connects to this specific
|
||||
device (`Discovering` stays `yes` forever, every subsequent connect fails with
|
||||
`le-connection-abort-by-local`) — after 3 consecutive scan failures the daemon
|
||||
restarts `bluetooth.service` itself to clear it, rate-limited to once per 5 min so it
|
||||
doesn't repeatedly disrupt the AP's other BLE gear (motion sensors, IR remote).
|
||||
- This BLE module accepts only **one central connection at a time** — while
|
||||
`van-li3-battery` holds it, the Li3 phone app can't connect simultaneously.
|
||||
`systemctl stop van-li3-battery` to free it up for the app.
|
||||
- Verify: `journalctl -u van-li3-battery -f` (look for `connected` / `published: {...}`),
|
||||
or `mosquitto_sub -h localhost -u homeassistant -P <pw> -t van/li3_battery/state`.
|
||||
|
||||
### ZeroTier managed DNS
|
||||
- `wrede.pvt` resolves over ZeroTier when off the home LAN. Mechanism: `allowDNS=1` (prereq) + `zerotier-systemd-manager` writes `99-ztuga7c2kh.network`, networkd applies it to resolved.
|
||||
- Verify: `resolvectl status ztuga7c2kh` shows `DNS` scope + the two servers + `wrede.pvt`.
|
||||
|
||||
Reference in New Issue
Block a user