ESPHome Meter Reader TFLite Component
A modular framework for running TensorFlow Lite Micro models on ESP32 devices within the ESPHome ecosystem. It provides specialized components for digital and analog meter reading, image processing, and active learning data collection, optimized with ESP-NN for high-performance edge AI.
Overview
The ESPHome Meter Reader TFLite Component is a robust, modular framework designed to bring machine learning capabilities to ESP32-based devices. While originally conceived for automating the reading of analog and digital utility meters, the project has evolved into a general-purpose TensorFlow Lite Micro implementation with comprehensive image processing support. By integrating directly into the ESPHome ecosystem, it allows users to deploy AI models for computer vision tasks with minimal boilerplate code.
Modular Architecture
Starting with version 2.0, the project transitioned from a monolithic structure to a collection of specialized components. This modularity allows developers to include only the features necessary for their specific use case, optimizing memory usage on resource-constrained microcontrollers.
Core components include:
- meter_reader_tflite: The primary AI engine that orchestrates image capture, TFLite inference, and reporting.
- ssocr_reader: A non-AI alternative for reading seven-segment digital displays using traditional OCR algorithms.
- analog_reader: A specialized component for reading physical dials and gauges using radial intensity algorithms.
- tflite_micro_helper: A wrapper for the TensorFlow Lite Micro runtime that manages the tensor arena and model loading while leveraging
esp-nnoptimizations.
Advanced Image Processing
Running AI models on microcontrollers like the ESP32 requires significant preprocessing. This project includes a powerful esp32_camera_utils component that handles cropping, scaling, and rotation of both JPEG and raw image formats. It utilizes the esp_new_jpeg library and TrackedBuffer for efficient memory management, ensuring that the camera frame is correctly formatted for the TFLite model’s input tensor.
One of the standout features is the support for multi-zone processing, allowing the system to extract and analyze multiple regions of interest from a single camera frame. This is particularly useful for meters with multiple dials or complex displays.
Performance and Optimization
The framework is highly optimized for the ESP32-S3, utilizing hardware acceleration through the esp-nn library. When paired with quantized (int8) models, the system can achieve impressive performance. For instance, an 8-digit inference process can be completed in less than 270 ms on an ESP32-S3, a significant improvement over the legacy ESP32 hardware.
Active Learning and Data Collection
To improve model accuracy over time, the project features a data_collector component. This tool implements an “Active Learning” workflow by automatically identifying “hard” images—those where the model has low confidence—and uploading them to a remote server. These images can then be used to retrain and refine the TensorFlow Lite models, creating a continuous improvement loop for the deployment.
Getting Started
Integrating the component into an ESPHome configuration is straightforward. Users define the external component source and then configure the specific reader and supporting utilities. Below is a basic example of an AI-powered meter reader configuration:
meter_reader_tflite:
id: my_meter_reader
model: "digit_recognizer.tflite"
camera_id: my_camera
validator: my_validator
update_interval: 60s
tensor_arena_size: 768KB
rotation: "90"
Hardware Support
The project provides pre-configured board files for popular ESP32-S3 and ESP32 camera modules, including:
- AI-On-The-Edge-Cam (ESP32-S3 with PoE/SD)
- Seeed Studio XIAO ESP32-S3 Sense
- M5Stack PSRAM
- Freenove ESP32-S3
- Standard AI-Thinker ESP32-CAM
By exposing calibration parameters, timing, and debug toggles directly to Home Assistant, the framework allows for real-time adjustments and monitoring without the need for constant firmware recompilation.