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.
18 lines
638 B
Desktop File
18 lines
638 B
Desktop File
# /etc/systemd/system/van-li3-battery.service
|
|
[Unit]
|
|
Description=Publish Li3 BMS battery telemetry to Home Assistant via MQTT
|
|
After=network-online.target bluetooth.target mosquitto.service
|
|
Wants=network-online.target
|
|
|
|
[Service]
|
|
ExecStart=/usr/local/sbin/van-li3-battery
|
|
# The script retries BLE scan/connect internally (including self-healing a
|
|
# wedged bluetoothd discovery state — see the script's docstring) and only
|
|
# exits on MQTT-level failure, which shouldn't happen in normal operation.
|
|
# Restart=always is a backstop for that case, matching van-gps-owntracks.
|
|
Restart=always
|
|
RestartSec=10
|
|
|
|
[Install]
|
|
WantedBy=multi-user.target
|