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.

Black & White Path
Black & White Path
Black & White Path
Open‑Source MQTT WeChat Mini‑Program v5.2 Adds Battery Monitoring

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:speedometer

After 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.

Card view
Card view
Weekly data change with one mid‑period charge
Weekly data change with one mid‑period charge
Weekly voltage trend
Weekly voltage trend
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.

Mini‑program battery view
Mini‑program battery view

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.

Edit utils/api.js
Edit utils/api.js
Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

WeChat Mini ProgramOpen SourceMQTTHome AssistantBattery MonitoringESP8266
Black & White Path
Written by

Black & White Path

We are the beacon of the cyber world, a stepping stone on the road to security.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.