pdf-icon

Station-Bat Home Assistant Integration

SKU:K124-B

Introduction

Station-Bat is a versatile industrial-grade programmable embedded controller. It uses the Espressif ESP32 as the main control chip, integrates a Wi-Fi solution, and is equipped with a dual-core low-power Xtensa® 32-bit LX6 microprocessor with a main frequency of up to 240MHz. It comes with 16MB Flash, a 1.14-inch full-color HD IPS display panel with a resolution of 240×135, a physical button panel, rich peripherals, two sets of six expansion interfaces, and features low-power sleep/timed wake-up functionality. It also integrates the IMU MPU6886.

It supports both USB Type-C and internal rechargeable 18650 battery power supply methods. The onboard high-power-density fully integrated boost DC/DC converter SCT12A0DHKR ensures the stability of electrical equipment operation in complex application scenarios.

This controller can be used in industrial field control, smart buildings, multi-channel data acquisition nodes, and developer prototype design, among other application scenarios.

Preparations

  • A Home Assistant host
  • Install and enable the ESPHome Builder add-on in Home Assistant
Tip
In this tutorial, the firmware is compiled and uploaded with ESPHome 2026.2.4. If you encounter compile/upload issues, consider switching ESPHome to this version.

Step 1. Create New Device

  • Click the green button in the lower right corner to create a device.

Step 2. Create Device Name

  • Click CONTINUE.

  • Click New Device Setup.

  • Enter the name of the device and click NEXT.

Step 3. Choose Device Type

  • Click ESP32.

  • Click SKIP.

Step 4. Start Edit YAML File

  • Click EDIT. We can customize device functionality through YAML files.

Device Setup

The following is the core part of the code. Relevant references and explanations are provided below.

Boot Configuration

  • Add the boot initialization to ensure the RTC time is read on startup.
esphome:
  name: station-bat
  friendly_name: station-bat
  on_boot:
    - priority: 600
      then:
        - bm8563.read_time:

External Components

  • Add the External Components components. The m5station_axp192 component provides power management and battery level support for Station-Bat.
external_components:
  - source: github://m5stack/esphome-yaml/components
    components: [m5station_axp192]
    refresh: 0s

I2C Bus Configuration

  • Add the I2C components. The I2C bus is shared by the IMU, power management IC, and current/voltage monitors.
i2c:
  - id: i2c_bus
    sda: GPIO21
    scl: GPIO22

SPI Bus Configuration

  • Add the SPI components. The SPI bus is used by the ST7789V display.
spi:
  clk_pin: GPIO18
  mosi_pin: GPIO23

Sensor Configuration

  • Add the Sensor components
  • Add the MPU6886 IMU sensor for accelerometer, gyroscope, and temperature readings
  • Add the INA3221 current/voltage monitors — two chips are used to cover all 6 channels (A1/A2, B1/B2, C1/C2)
  • The m5station_axp192 sensor is provided by the external component added above
sensor:
  - platform: mpu6886
    i2c_id: i2c_bus
    accel_x:
      name: "MPU6886 Accel X"
      id: imu_ax
    accel_y:
      name: "MPU6886 Accel Y"
      id: imu_ay
    accel_z:
      name: "MPU6886 Accel z"
      id: imu_az
    gyro_x:
      name: "MPU6886 Gyro X"
    gyro_y:
      name: "MPU6886 Gyro Y"
    gyro_z:
      name: "MPU6886 Gyro z"
    temperature:
      name: "MPU6886 Temperature"
      id: imu_temp
    update_interval: 5s

  - platform: m5station_axp192
    id: pmu
    i2c_id: i2c_bus
    battery_level:
      name: "M5Station Battery Level"
      id: bat_level
    update_interval: 60s
    brightness: 0.8

  - platform: ina3221
    id: ina1
    i2c_id: i2c_bus
    address: 0x40
    update_interval: 1s
    channel_1:
      shunt_resistance: 0.01
      bus_voltage:
        name: "P.A1 Bus Voltage"
        id: v_a1
      current:
        name: "P.A1 Current"
        id: i_a1
    channel_2:
      shunt_resistance: 0.01
      bus_voltage:
        name: "P.A2 Bus Voltage"
        id: v_a2
      current:
        name: "P.A2 Current"
        id: i_a2
    channel_3:
      shunt_resistance: 0.01
      bus_voltage:
        name: "P.B1 Bus Voltage"
        id: v_b1
      current:
        name: "P.B1 Current"
        id: i_b1

  - platform: ina3221
    id: ina2
    i2c_id: i2c_bus
    address: 0x41
    update_interval: 1s
    channel_1:
      shunt_resistance: 0.01
      bus_voltage:
        name: "P.B2 Bus Voltage"
        id: v_b2
      current:
        name: "P.B2 Current"
        id: i_b2
    channel_2:
      shunt_resistance: 0.01
      bus_voltage:
        name: "P.C1 Bus Voltage"
        id: v_c1
      current:
        name: "P.C1 Current"
        id: i_c1
    channel_3:
      shunt_resistance: 0.01
      bus_voltage:
        name: "P.C2 Bus Voltage"
        id: v_c2
      current:
        name: "P.C2 Current"
        id: i_c2

Binary Sensor Configuration

  • Add the Binary Sensor components. The three physical buttons on the panel are mapped to GPIO37, GPIO38, and GPIO39.
binary_sensor:
  - platform: gpio
    name: "Button1"
    pin:
      number: GPIO37
      inverted: true
  - platform: gpio
    name: "Button2"
    pin:
      number: GPIO38
      inverted: true
  - platform: gpio
    name: "Button3"
    pin:
      number: GPIO39
      inverted: true

Switch Configuration

  • Add the Switch components. The LCD backlight is controlled via the AXP192 power IC, and USB power output can be toggled via GPIO12.
switch:
  - platform: template
    name: "LCD Backlight"
    id: lcd_backlight
    lambda: |-
      return true;
    restore_mode: ALWAYS_ON
    turn_on_action:
      - lambda: |-
          id(pmu).set_backlight(true);
    turn_off_action:
      - lambda: |-
          id(pmu).set_backlight(false);

  - platform: gpio
    name: "USB Power"
    id: usb_power
    pin: GPIO12

Time Configuration

  • Add the Time components
  • Add the BM8563 RTC component. The BM8563 keeps time while offline; it syncs from Home Assistant when connected and restores the time on reboot.
time:
  - platform: bm8563
    id: bm8563_time
    update_interval: never

  - platform: homeassistant
    id: ha_time
    on_time_sync:
      then:
        - bm8563.write_time:

Light Configuration

  • Add the Light components. Station-Bat has 7 onboard WS2812 RGB LEDs connected to GPIO4.
light:
  - platform: esp32_rmt_led_strip
    rgb_order: GRB
    pin: GPIO4
    num_leds: 7
    chipset: ws2812
    name: "My Light"

Display Configuration

  • Add the Display components
  • Add the ST7789V driver for the 1.14-inch IPS screen. The lambda block is where you define what is drawn on the screen — see the complete example linked below for a full implementation.
display:
  - platform: st7789v
    model: CUSTOM
    width: 135
    height: 240
    offset_height: 52
    offset_width: 40
    cs_pin: GPIO5
    dc_pin: GPIO19
    reset_pin: GPIO15
    rotation: 90
    update_interval: 1s
    lambda: |-
      // Define your display content here
      // See the complete example for a full implementation

Firmware Build

  • After making changes, click SAVE and INSTALL in the top-right corner, then choose Manual Download in the popup.

  • Click INSTALL and wait for the compilation to complete.

  • After the firmware compilation is complete, click Download and select Factory format (Previously Modern).

Tip
Click Station-Bat to view the complete example configuration. The first build may take a while, depending on the performance of the Home Assistant host and network quality.

Firmware Upload

  • Connect the device to your host via a USB Type-C cable. Open ESPHome Web and click CONNECT to connect to the device.

  • Locate the corresponding serial port number.

  • Click INSTALL.

  • Select the previously compiled firmware to upload.

Tip
After the upload is complete, press the reset button on the device to apply the new firmware.

Home Assistant Integration

  • Click SettingsDevices & Services to check the device.

  • The device will appear in the Discovered section. Click CONFIGURE to add it.

  • After adding the device, the sensor data will be displayed correctly.

  • Finally, add these entities to the Dashboard. The following shows the display results.

On This Page