ESP32墨水屏喂奶计时器 本地接入米家智能家居全流程指南ESP32 E-Ink Nursing Timer: A Full Guide to Local Integration with Xiaomi Mijia Smart Home


AI free token/AI免费积分

ESP32墨水屏喂奶计时器 本地接入米家智能家居全流程指南

本文来源:http://www.hqwc.cn/news/974849.html
若有版权问题,请来信告知:13951431913#139.com 或在右方提交评论。

ESP32墨水屏喂奶计时器:本地接入米家智能家居全流程指南

这次我们来看一个非常实用的物联网DIY项目:用ESP32主控搭配墨水屏,制作一个能接入米家智能家居的喂奶计时器。对于有新生儿的家庭来说,记录喂奶时间是个高频且容易遗忘的任务,这个项目将硬件、固件和智能家居平台打通,提供了一个低成本、低功耗、信息常显的本地化解决方案。

项目的核心思路很清晰:利用ESP32的Wi-Fi和计算能力,运行一个简单的HTTP服务器,并通过Home Assistant(HA)这个开源家庭自动化平台作为桥梁,最终将计时器的状态和控制接入米家App。墨水屏的特性决定了它只在刷新时耗电,显示喂奶间隔时间等信息非常直观且省电。整个方案不依赖复杂的云服务,数据在本地流转,响应快且隐私性好。

本文将带你从零开始,完成这个喂奶计时器的硬件搭建、固件烧录、Home Assistant配置以及米家接入的全过程。无论你是ESP32的初学者,还是想深入了解如何将自制设备融入现有智能家居生态的开发者,这篇文章都能提供一套可落地的操作指南。我们会重点关注ESP32的HTTP服务器实现、Home Assistant的MQTT或RESTful传感器配置,以及通过Xiaomi Miot Auto插件实现米家控制的关键步骤。

在动手之前,我们先快速了解这个项目的关键特性和要求。

这个喂奶计时器项目主要服务于特定场景,明确其边界能帮助你更好地判断是否适合自己。

新生儿家庭 :父母需要频繁、准确地记录每次喂奶的起始时间,以掌握喂养规律。

物联网学习与实践 :对于想学习ESP32联网、HTTP服务器、传感器数据上报以及Home Assistant集成的开发者,这是一个功能完整且贴近生活的练手项目。

智能家居深度用户 :已经部署Home Assistant,并希望将更多自制、非标设备统一管理并接入常用App(如米家)的用户。

低功耗显示需求 :需要长时间显示固定信息,且不希望频繁充电或更换电池的场景,墨水屏的优势明显。

非商业产品 :这是一个DIY项目,在稳定性、安全性和耐用性上无法与成熟商业产品相比,适合技术爱好者。

依赖家庭网络 :ESP32和Home Assistant需要处于同一局域网(LAN)下。网络不稳定会导致计时器状态同步延迟或失败。

需要基础部署能力 :你需要能够烧录ESP32固件、安装配置Home Assistant(通常以HASSOS、Docker等方式部署),并安装第三方插件。

功能相对单一 :核心是计时和状态显示,不具备视频监控、奶量记录等复杂功能。扩展需要二次开发。

隐私与数据安全 :项目设计为本地运行,数据不出家门。但需确保Home Assistant实例本身的安全配置(如设置强密码、不随意暴露到公网)。

开始制作前,请确保你已准备好以下软硬件环境。

ESP32开发板 :如ESP32 DevKitC、NodeMCU-32S等,任何带有Wi-Fi功能的ESP32模块均可。

墨水屏(E-Paper) :建议选择与常用驱动库兼容的型号,例如: GDEH0154D67 (1.54英寸) GDEW029T5 (2.9英寸) 购买时请确认其接口(通常是SPI)和电压(3.3V)与ESP32兼容。

购买时请确认其接口(通常是SPI)和电压(3.3V)与ESP32兼容。

连接线 :杜邦线(母对母或公对母),用于连接ESP32与墨水屏。

电源 :为ESP32供电,可使用USB线连接电脑或手机充电器,或使用3.7V锂电池配合充放电模块实现便携。

可选 :按键或触摸传感器,用于本地手动触发计时开始/结束。

开发环境 : 方案一(推荐) :Visual Studio Code + PlatformIO IDE插件。它提供了更好的库管理和项目结构。 方案二 :Arduino IDE。需要安装ESP32开发板支持包。

方案一(推荐) :Visual Studio Code + PlatformIO IDE插件。它提供了更好的库管理和项目结构。

方案二 :Arduino IDE。需要安装ESP32开发板支持包。

Home Assistant (HA) :一个已安装并运行在你的家庭网络中的Home Assistant实例。这可以是运行在树莓派、旧电脑、NAS或虚拟机上的HASSOS、Docker容器等。

网络 :稳定的家庭Wi-Fi网络。你需要知道Wi-Fi的SSID(名称)和密码。

首先,我们将ESP32与墨水屏连接起来,并配置好开发环境。

大多数小尺寸墨水屏使用SPI接口。以下是典型的连接方式,请根据你的屏幕具体引脚定义进行调整:

注意 :GPIO引脚编号可根据你的板子布局和代码定义进行修改,避免冲突。

安装VS Code,然后在扩展商店搜索并安装“PlatformIO IDE”。

新建一个Project,选择Board为“Espressif ESP32 Dev Module”,Framework为“Arduino”。

打开项目根目录下的 platformio.ini 文件,在 [env] 部分添加依赖库。对于常用的GxEPD2墨水屏驱动库,添加如下内容: lib_deps = olikraus/U8g2_for_Adafruit_GFX @ ^1.8.0 zinggjm/GxEPD2 @ ^1.5.6

PlatformIO会自动下载这些库。

添加ESP32开发板支持:文件 -> 首选项 -> 附加开发板管理器网址,添加 https://espressif.github.io/arduino-esp32/package_esp32_index.json 。

工具 -> 开发板 -> 开发板管理器,搜索“esp32”并安装。

项目 -> 加载库 -> 管理库,搜索并安装“GxEPD2”和“U8g2 for Adafruit GFX”库。

5. ESP32固件开发:HTTP服务器与计时逻辑

这是项目的核心代码部分。ESP32将同时扮演两个角色:一个简单的HTTP服务器,用于接收来自Home Assistant的命令;一个计时器,控制墨水屏的显示。

我们将编写一个Arduino Sketch,主要包含以下功能模块:

墨水屏驱动初始化与显示 :使用GxEPD2库驱动屏幕,绘制计时界面。

HTTP服务器 :创建一个Web服务器,监听特定端口(如80),提供简单的API端点。

计时逻辑 :记录“开始喂奶”的时间点,计算距离当前时间的间隔,并格式化显示。

与Home Assistant交互 :通过HTTP端点,接收HA发来的“开始计时”指令,也可以将当前状态(如“已计时XX分钟”)通过HA暴露给米家。

以下是一个高度简化的代码框架,展示了关键逻辑:

ESP32启动后连接Wi-Fi,并启动一个Web服务器。

提供了三个简单的API端点: /start :GET请求此地址,计时器开始。 /stop :停止计时。 /status :返回一个JSON,包含当前状态和持续时间。

/start :GET请求此地址,计时器开始。

/status :返回一个JSON,包含当前状态和持续时间。

updateDisplay 函数负责在墨水屏上绘制内容,包括计时状态和ESP32的IP地址(便于调试)。

计时逻辑基于 millis() 函数,避免了使用阻塞的 delay() 。

将上述代码根据你的屏幕型号和引脚定义修改后,保存为 .ino 文件。

在开发环境(PlatformIO或Arduino IDE)中选择正确的端口和开发板型号。

打开串口监视器,查看输出日志,确认Wi-Fi连接成功并获取到IP地址(如 192.168.1.100 )。记下这个IP。

6. Home Assistant配置:创建传感器与自动化

现在,我们需要让Home Assistant认识这个ESP32计时器,并与之通信。

Home Assistant可以通过RESTful传感器( rest )来获取ESP32的状态。编辑HA的 configuration.yaml 文件,添加如下配置:

value_template : 从返回的JSON中提取 state 字段的值(“feeding”或“idle”)作为传感器状态。

json_attributes : 将 duration_minutes 字段作为传感器的属性存储,可以在前端显示。

保存并重启Home Assistant。在HA的前端,你应该能看到一个名为“Feeding Timer Status”的传感器实体。

为了向ESP32发送“开始”/“停止”命令,我们可以在HA中创建一个脚本或直接使用“开关”实体。这里以创建一个“开关”为例,它实际上调用的是 rest_command 服务。

然后,你可以通过HA的“开发者工具 -> 服务”手动调用 rest_command.feeding_timer_start 来测试。为了更方便,可以创建一个“虚拟开关”或“按钮”卡片来触发这些服务。

进入HA侧边栏“设置” -> “设备与服务” -> “帮助程序”。

点击“创建辅助元素”,选择“开关”。

在开关配置中,为其添加一个自动化:当开关打开时,调用服务 rest_command.feeding_timer_start ;当开关关闭时,调用 rest_command.feeding_timer_stop 。

现在,你在HA仪表盘上就有一个可以控制ESP32计时器的开关了。

7. 接入米家:通过Xiaomi Miot Auto插件

这是实现“通过米家控制”的关键一步。我们将利用Home Assistant强大的集成能力,通过第三方插件将HA中的实体暴露给米家App。

Xiaomi Miot Auto是一个HA社区插件,可以将HA中的任意实体(如开关、传感器)同步到米家App中。

在HA中,确保已安装“File editor”或“Samba share”等插件,以便编辑配置文件。

通过HACS(Home Assistant Community Store)安装“Xiaomi Miot Auto”集成。如果未安装HACS,需先安装HACS。

进入HA侧边栏“设置” -> “设备与服务” -> “集成”。

点击“添加集成”,搜索“Xiaomi Miot Auto”。

授权成功后,集成会自动同步你米家账号下的设备。但这还不够,我们需要将HA的实体添加进去。

Xiaomi Miot Auto允许你通过YAML配置,将HA的实体映射为虚拟的米家设备。编辑HA的 configuration.yaml 文件,添加如下配置:

注意 : siid , piid , aiid 的值需要根据米家设备模型的规范来定义,上述示例是一个简化版本。更可靠的做法是参考Xiaomi Miot Auto的官方文档,使用其“自定义模型”功能,或直接复制一个现有米家开关设备的模型进行修改。

在“我的设备”页面,下拉刷新。通常,稍等片刻后,一个名为“Home Assistant”或类似名称的设备会被自动添加进来。

点开这个设备,你应该能看到里面包含了我们在HA中映射的“开关”和“传感器”。

现在,你就可以直接在米家App里点击“开关”来远程启动/停止ESP32上的喂奶计时器,并查看计时状态了。

完成所有配置后,需要进行系统化测试以确保各环节工作正常。

基础显示 :ESP32启动后,墨水屏应显示初始界面(如“Ready”和IP地址)。

HTTP API测试 :在电脑浏览器或使用 curl 命令测试ESP32的API。 打开浏览器,访问 http://[ESP32_IP]/status ,应返回JSON数据。 访问 http://[ESP32_IP]/start ,屏幕应立即更新,显示计时开始。 访问 http://[ESP32_IP]/stop ,计时停止,屏幕显示“Ready”。

打开浏览器,访问 http://[ESP32_IP]/status ,应返回JSON数据。

访问 http://[ESP32_IP]/start ,屏幕应立即更新,显示计时开始。

访问 http://[ESP32_IP]/stop ,计时停止,屏幕显示“Ready”。

计时准确性 :开始计时后,观察屏幕显示的时间增量是否与真实时间基本一致(允许秒级误差)。

传感器状态 :在HA的“概览”或“开发者工具 -> 状态”中,找到 sensor.feeding_timer_status 实体,检查其状态是否随ESP32计时状态变化而更新。

服务调用 :在“开发者工具 -> 服务”中,调用 rest_command.feeding_timer_start 和 rest_command.feeding_timer_stop ,观察ESP32屏幕和HA传感器状态是否同步变化。

辅助开关 :操作在HA前端创建的“开始喂奶计时”开关,验证其能否正确控制ESP32。

设备发现 :确认米家App中出现了来自Home Assistant的虚拟设备。

控制测试 :在米家App中,点击虚拟设备里的开关。观察: HA中对应的辅助开关状态是否变化。 ESP32的墨水屏显示是否变化。

状态同步测试 :在ESP32本地通过HTTP API开始计时,等待片刻(HA的扫描间隔),查看米家App中传感器显示的状态是否变为“feeding”,并看到持续时间更新。

在部署过程中,你可能会遇到以下问题:

基础功能实现后,可以考虑以下优化和扩展,让项目更完善:

低功耗优化 : ESP32深度睡眠 :如果使用电池供电,可以在计时结束后让ESP32进入深度睡眠模式,仅由外部按键(连接到EN或GPIO0)唤醒,极大延长续航。 墨水屏局部刷新 :如果屏幕支持,在更新计时数字时使用局部刷新( display.powerRefresh() )而非全屏刷新,速度更快、更省电、减少残影。

ESP32深度睡眠 :如果使用电池供电,可以在计时结束后让ESP32进入深度睡眠模式,仅由外部按键(连接到EN或GPIO0)唤醒,极大延长续航。

墨水屏局部刷新 :如果屏幕支持,在更新计时数字时使用局部刷新( display.powerRefresh() )而非全屏刷新,速度更快、更省电、减少残影。

本地交互 : 物理按键 :增加1-2个物理按键连接到ESP32,实现本地手动开始/停止/重置计时,不依赖网络。 触摸感应 :使用电容触摸传感器,实现更优雅的交互。

物理按键 :增加1-2个物理按键连接到ESP32,实现本地手动开始/停止/重置计时,不依赖网络。

触摸感应 :使用电容触摸传感器,实现更优雅的交互。

功能扩展 : 多计时器 :管理“左/右”喂奶或“喂奶/换尿布”等多个计时任务。 历史记录 :ESP32将每次喂奶的起止时间通过HTTP POST发送到HA,HA将其记录在数据库(如InfluxDB)中,并可通过Grafana等工具可视化喂养历史。 声音/灯光提醒 :增加蜂鸣器或LED,当计时达到一定时长(如30分钟)时发出提醒。

多计时器 :管理“左/右”喂奶或“喂奶/换尿布”等多个计时任务。

历史记录 :ESP32将每次喂奶的起止时间通过HTTP POST发送到HA,HA将其记录在数据库(如InfluxDB)中,并可通过Grafana等工具可视化喂养历史。

声音/灯光提醒 :增加蜂鸣器或LED,当计时达到一定时长(如30分钟)时发出提醒。

可靠性提升 : Wi-Fi重连机制 :在代码中添加健壮的Wi-Fi断开重连逻辑。 看门狗定时器 :启用硬件看门狗,防止程序跑飞导致设备死机。 OTA升级 :实现通过网络远程更新ESP32固件,无需插线。

Wi-Fi重连机制 :在代码中添加健壮的Wi-Fi断开重连逻辑。

看门狗定时器 :启用硬件看门狗,防止程序跑飞导致设备死机。

OTA升级 :实现通过网络远程更新ESP32固件,无需插线。

这个项目成功地将一个简单的ESP32设备,通过Home Assistant的桥梁,融入了成熟的米家智能生态。它不仅解决了喂奶计时这个具体问题,更提供了一个经典的物联网设备接入范例。你可以举一反三,将类似的思路应用于其他传感器(如温湿度计、门窗磁)或控制器(如继电器开关),打造完全自定义的智能家居设备。

ESP32 E-Ink Nursing Timer: A Full Guide to Local Integration with Xiaomi Mijia Smart Home

本文来源:http://www.hqwc.cn/news/974849.html
若有版权问题,请来信告知:13951431913#139.com 或在右方提交评论。

ESP32 E-Paper Feeding Timer: A Full Guide to Local Integration with Xiaomi Smart Home

This time we're looking at a very practical IoT DIY project: an ESP32 board paired with an e-Paper display to build a feeding timer that integrates with Xiaomi Smart Home. For families with a newborn, recording feeding times is a frequent and easily forgotten task; this project connects hardware, firmware, and a smart-home platform, offering a low-cost, low-power, always-visible local solution.

The core idea is clear: use the ESP32's Wi-Fi and computing power to run a simple HTTP server, use the open-source home automation platform Home Assistant (HA) as a bridge, and finally bring the timer's state and control into the Mi Home app. The e-Paper's characteristics mean it only draws power while refreshing, making it ideal and power-saving for showing information such as the feeding interval. The whole solution doesn't rely on complex cloud services — data flows locally, with fast response and good privacy.

This article will take you from zero through the hardware build, firmware flashing, Home Assistant configuration, and Mi Home integration. Whether you're an ESP32 beginner or a developer wanting to understand how to fit a DIY device into an existing smart-home ecosystem, this offers a practical, hands-on guide. We'll focus on the ESP32 HTTP server implementation, Home Assistant's MQTT or RESTful sensor configuration, and the key steps for Mi Home control via the Xiaomi Miot Auto plugin.

Before we start building, let's quickly look at the project's key features and requirements.

This feeding-timer project serves a specific scenario; knowing its boundaries up front helps you judge whether it's right for you.

Families with newborns: parents need to frequently and accurately record the start time of each feeding to understand feeding patterns.

IoT learning and practice: for developers who want to learn ESP32 networking, HTTP servers, sensor data reporting, and Home Assistant integration, this is a complete, life-adjacent practice project.

Smart-home power users: those who have already deployed Home Assistant and want to manage more DIY, non-standard devices in one place and connect them to common apps such as Mi Home.

Low-power display needs: scenarios that need to show fixed information for a long time without frequent charging or battery replacement — e-Paper's advantages are obvious.

Not a commercial product: this is a DIY project and can't match mature commercial products in stability, safety, or durability; it's suited to tech enthusiasts.

Depends on the home network: the ESP32 and Home Assistant must be on the same LAN (local area network). An unstable network leads to delayed or failed timer-state sync.

Requires basic deployment skills: you need to be able to flash ESP32 firmware, install and configure Home Assistant (usually deployed via HASSOS, Docker, etc.), and install third-party plugins.

Relatively single function: the core is timing and status display; it doesn't include complex features like video monitoring or milk-volume logging. Extensions require further development.

Privacy and data security: the project is designed to run locally, with data never leaving the home. But you must ensure the Home Assistant instance itself is configured securely (e.g. a strong password, not exposed to the public internet).

Before you start building, make sure you have the following hardware and software ready.

ESP32 development board: e.g. ESP32 DevKitC, NodeMCU-32S — any ESP32 module with Wi-Fi works.

E-Paper display: choose a model compatible with common driver libraries, for example: GDEH0154D67 (1.54 inch), GDEW029T5 (2.9 inch).

When buying, confirm its interface (usually SPI) and voltage (3.3V) are compatible with the ESP32.

Jumper wires: female-to-female or male-to-female, for connecting the ESP32 to the e-Paper.

Power supply: to power the ESP32, use a USB cable connected to a computer or phone charger, or a 3.7V Li-ion battery with a charge/discharge module for portability.

Optional: buttons or a touch sensor for locally triggering start/stop of the timer.

Development environment: Option 1 (recommended): Visual Studio Code + the PlatformIO IDE extension, which offers better library management and project structure. Option 2: Arduino IDE, which requires installing the ESP32 board support package.

Option 1 (recommended): Visual Studio Code + the PlatformIO IDE extension. It provides better library management and project structure.

Option 2: Arduino IDE. You need to install the ESP32 board support package.

Home Assistant (HA): an HA instance already installed and running on your home network — HASSOS, a Docker container, etc., running on a Raspberry Pi, old computer, NAS, or virtual machine.

Network: a stable home Wi-Fi network. You need to know the Wi-Fi SSID (name) and password.

First, we'll connect the ESP32 to the e-Paper and set up the development environment.

Most small e-Paper displays use an SPI interface. Here's a typical wiring scheme; adjust it according to your display's specific pinout:

Note: GPIO pin numbers can be changed according to your board layout and code definitions to avoid conflicts.

Install VS Code, then search for and install "PlatformIO IDE" in the Extensions marketplace.

Create a new Project, set Board to "Espressif ESP32 Dev Module" and Framework to "Arduino".

Open the platformio.ini file in the project root and add dependencies in the [env] section. For the common GxEPD2 e-Paper driver library, add the following: lib_deps = olikraus/U8g2_for_Adafruit_GFX @ ^1.8.0 zinggjm/GxEPD2 @ ^1.5.6

PlatformIO will download these libraries automatically.

Adding ESP32 board support: File -> Preferences -> Additional boards manager URLs, and add https://espressif.github.io/arduino-esp32/package_esp32_index.json.

Tools -> Board -> Boards Manager, search for "esp32" and install it.

Project -> Load Library -> Manage Library, search for and install the "GxEPD2" and "U8g2 for Adafruit GFX" libraries.

5. ESP32 Firmware Development: HTTP Server and Timing Logic

This is the core code section. The ESP32 plays two roles at once: a simple HTTP server that receives commands from Home Assistant, and a timer that controls the e-Paper display.

We'll write an Arduino Sketch containing the following functional modules:

E-Paper driver initialization and display: use the GxEPD2 library to drive the screen and draw the timing UI.

HTTP server: create a Web server listening on a specific port (e.g. 80) and exposing simple API endpoints.

Timing logic: record the "feeding start" timestamp, calculate the interval to the current time, and format it for display.

Interacting with Home Assistant: via HTTP endpoints, receive "start timing" commands from HA, and also expose the current state (e.g. "timed XX minutes") through HA to Mi Home.

Below is a highly simplified code skeleton showing the key logic:

After startup the ESP32 connects to Wi-Fi and starts a Web server.

It exposes three simple API endpoints: /start — GET this address to start the timer. /stop — stop the timer. /status — return a JSON containing the current state and duration.

/start — GET this address and the timer starts.

/status — returns a JSON with the current state and duration.

The updateDisplay function draws content on the e-Paper, including the timer status and the ESP32's IP address (handy for debugging).

The timing logic is based on millis(), avoiding the blocking delay().

Modify the code above for your display model and pin definitions, and save it as a .ino file.

In the development environment (PlatformIO or Arduino IDE), select the correct port and board type.

Open the Serial Monitor, check the output log, confirm that the Wi-Fi connection succeeded and an IP address was obtained (e.g. 192.168.1.100). Note this IP.

6. Home Assistant Configuration: Creating Sensors and Automations

Now we need Home Assistant to recognize this ESP32 timer and communicate with it.

Home Assistant can fetch the ESP32's state through a RESTful sensor (rest). Edit HA's configuration.yaml and add the following:

value_template: extracts the value of the state field from the returned JSON ("feeding" or "idle") as the sensor state.

json_attributes: stores the duration_minutes field as a sensor attribute, which can be displayed in the frontend.

Save and restart Home Assistant. In HA's frontend you should see a sensor entity named "Feeding Timer Status".

To send "start"/"stop" commands to the ESP32, we can create a script in HA or use a "switch" entity directly. Here we'll create a switch that actually calls the rest_command service.

You can then manually call rest_command.feeding_timer_start via HA's Developer Tools -> Services to test. For convenience, create a "virtual switch" or "button" card to trigger these services.

Go to the HA sidebar Settings -> Devices & Services -> Helpers.

Click "Create Helper" and select "Switch".

In the switch configuration, add an automation: when the switch turns on, call rest_command.feeding_timer_start; when it turns off, call rest_command.feeding_timer_stop.

Now you have a switch on the HA dashboard that can control the ESP32 timer.

7. Integrating with Mi Home: Via the Xiaomi Miot Auto Plugin

This is the key step for "control through Mi Home." We'll leverage Home Assistant's powerful integration capabilities to expose HA entities to the Mi Home app via a third-party plugin.

Xiaomi Miot Auto is an HA community plugin that can sync any entity in HA (such as switches and sensors) to the Mi Home app.

In HA, make sure a plugin such as "File editor" or "Samba share" is installed so you can edit configuration files.

Install the "Xiaomi Miot Auto" integration via HACS (Home Assistant Community Store). If HACS isn't installed, install it first.

Go to the HA sidebar Settings -> Devices & Services -> Integrations.

Click "Add Integration" and search for "Xiaomi Miot Auto".

After authorization succeeds, the integration automatically syncs the devices under your Mi Home account. But that's not enough — we need to add HA entities into it.

Xiaomi Miot Auto lets you map HA entities to virtual Mi Home devices through YAML configuration. Edit HA's configuration.yaml and add the following:

Note: the values of siid, piid, and aiid must be defined according to the Mi Home device model specification; the example above is simplified. A more reliable approach is to consult Xiaomi Miot Auto's official documentation and use its "custom model" feature, or copy an existing Mi Home switch model and modify it.

On the "My Devices" page, pull down to refresh. Usually, after a short wait, a device named "Home Assistant" or similar is added automatically.

Open this device; you should see the "switch" and "sensor" we mapped in HA inside it.

Now you can tap the switch directly in the Mi Home app to remotely start/stop the feeding timer on the ESP32 and check the timing status.

After completing all the configuration, systematic testing is needed to make sure every link works correctly.

Basic display: after the ESP32 starts, the e-Paper should show the initial UI (e.g. "Ready" and the IP address).

HTTP API test: test the ESP32's API in a browser or with curl. Open a browser and visit http://[ESP32_IP]/status — it should return JSON data. Visit http://[ESP32_IP]/start — the screen should update immediately to show that timing has begun. Visit http://[ESP32_IP]/stop — timing stops and the screen shows "Ready".

Open a browser and visit http://[ESP32_IP]/status; it should return JSON data.

Visit http://[ESP32_IP]/start; the screen updates immediately, showing the timer has started.

Visit http://[ESP32_IP]/stop; the timer stops and the screen shows "Ready".

Timing accuracy: after starting the timer, check that the time increments shown on screen roughly match real time (second-level error is acceptable).

Sensor state: in HA's Overview or Developer Tools -> States, find the sensor.feeding_timer_status entity and check that its state updates as the ESP32 timer state changes.

Service calls: in Developer Tools -> Services, call rest_command.feeding_timer_start and rest_command.feeding_timer_stop, and observe whether the ESP32 screen and the HA sensor state change in sync.

Helper switch: operate the "Start Feeding Timer" switch created in HA's frontend and verify it can correctly control the ESP32.

Device discovery: confirm that a virtual device from Home Assistant appears in the Mi Home app.

Control test: in the Mi Home app, tap the switch in the virtual device. Observe: does the corresponding helper switch state in HA change? Does the ESP32's e-Paper display change?

State-sync test: start timing locally on the ESP32 through the HTTP API, wait a moment (HA's scan interval), and check whether the sensor state shown in the Mi Home app changes to "feeding" with an updated duration.

During deployment you may run into the following problems:

Once the basic functions work, consider the following optimizations and extensions to make the project more complete:

Low-power optimization: ESP32 deep sleep — if running on battery, you can put the ESP32 into deep sleep mode after timing ends, waking only by an external button (connected to EN or GPIO0), greatly extending battery life. E-Paper partial refresh — if the display supports it, use partial refresh (display.powerRefresh()) instead of a full-screen refresh when updating the timer digits: faster, more power-saving, and with less ghosting.

ESP32 deep sleep: if running on battery, after timing ends put the ESP32 into deep sleep mode, waking only by an external button (connected to EN or GPIO0), drastically extending runtime.

E-Paper partial refresh: if the display supports it, use partial refresh (display.powerRefresh()) rather than a full-screen refresh when updating the timer numbers — faster, more power-saving, and with less ghosting.

Local interaction: Physical buttons — add 1–2 physical buttons connected to the ESP32 for local manual start/stop/reset of the timer without depending on the network. Touch sensing — use capacitive touch sensors for more elegant interaction.

Physical buttons: add one or two physical buttons connected to the ESP32 to start/stop/reset the timer manually, without relying on the network.

Touch sensing: use a capacitive touch sensor for more elegant interaction.

Feature extensions: Multiple timers — manage several timing tasks such as "left/right" feeding or "feeding/diaper change". History — the ESP32 sends each feeding's start/end times to HA via HTTP POST; HA records them in a database (e.g. InfluxDB), and feeding history can be visualized with tools such as Grafana. Sound/light reminders — add a buzzer or LED that alerts when the timer reaches a set duration (e.g. 30 minutes).

Multiple timers: manage several timing tasks such as "left/right" feeding or "feeding/diaper change".

History: the ESP32 sends each feeding's start/end times to HA via HTTP POST; HA records them in a database (e.g. InfluxDB), and feeding history can be visualized with tools such as Grafana.

Sound/light reminders: add a buzzer or LED that alerts when the timer reaches a set duration (e.g. 30 minutes).

Reliability improvements: Wi-Fi reconnect mechanism — add robust Wi-Fi disconnect-and-reconnect logic in code. Watchdog timer — enable the hardware watchdog to prevent a runaway program from freezing the device. OTA upgrade — update the ESP32 firmware remotely over the network with no cable needed.

Wi-Fi reconnect mechanism: add robust Wi-Fi disconnect-and-reconnect logic in the code.

Watchdog timer: enable the hardware watchdog to prevent a runaway program from freezing the device.

OTA upgrade: implement remote updates of the ESP32 firmware over the network, with no cable required.

This project successfully integrates a simple ESP32 device into the mature Mi Home smart ecosystem via the Home Assistant bridge. It not only solves the specific problem of feeding timing, but also provides a classic example of IoT device integration. You can extend the same thinking to other sensors (e.g. temperature/humidity meters, door/window magnets) or controllers (e.g. relay switches) to build fully custom smart-home devices.

暂无评论,快来发表第一条评论吧!No comments yet. Be the first!

📮 需求咨询📮 Inquiry