Open‑Source MQTT WeChat Mini‑Program v5.2 Adds Battery Monitoring
This guide shows how to use MQTT to integrate lithium‑ion battery voltage, state‑of‑charge and health data from an ESP8266 into Home Assistant and a WeChat mini‑program, providing configuration examples, JSON payloads, and links to the fully open‑source repositories.
The ESP8266 reads voltage, state‑of‑charge (SOC), charge/discharge rate and operational state from a MAX17048 lithium‑ion battery monitor and publishes them via MQTT on topic 18650 as a JSON object, e.g.:
{"voltage":4.089,"soc":87.6,"rate":0.00,"state":"Idle"}Home Assistant integration
Adding the following MQTT sensor definitions to configuration.yaml makes the four fields available as native Home Assistant sensors.
# 18650 battery sensor (MAX17048)
- unique_id: battery_18650_level
name: "18650 Battery Level"
state_topic: "18650"
value_template: "{{ value_json.soc }}"
unit_of_measurement: "%"
device_class: battery
icon: mdi:battery
- unique_id: battery_18650_voltage
name: "18650 Voltage"
state_topic: "18650"
value_template: "{{ value_json.voltage }}"
unit_of_measurement: "V"
device_class: voltage
icon: mdi:flash
- unique_id: battery_18650_state
name: "18650 State"
state_topic: "18650"
value_template: "{{ value_json.state }}"
icon: mdi:chip
- unique_id: battery_18650_rate
name: "18650 Rate"
state_topic: "18650"
value_template: "{{ value_json.rate }}"
unit_of_measurement: "%/hr"
icon: mdi:speedometerAfter four days of operation the Home Assistant UI shows a card view, weekly data changes (including a mid‑period charge) and a voltage trend, as illustrated by the screenshots below.
Latest open‑source repository: https://github.com/Priess0503/WxMQTT
WeChat mini‑program
The companion WeChat mini‑program includes a battery‑monitoring module. Users add the battery device by tapping 设备 → 添加设备 → 电池 and entering the MQTT subscription topic.
This release defaults to a database‑backed backend. The backend project and deployment instructions are hosted at:
https://github.com/Priess0503/WxMQTT/tree/main-mysql
After deploying the backend, edit utils/api.js to point to the server address.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Black & White Path
We are the beacon of the cyber world, a stepping stone on the road to security.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
