Home Assistant进阶|零代码搞定ESP8266接入HA!ESPHome入门+图文教程(下)Home Assistant Advanced | Zero-Code ESP8266 Integration with HA! ESPHome Beginner's Guide + Tutorial (Part 2)


AI free token/AI免费积分

很多玩智能家居的新手,都在纠结该选哪种中控,我还是强烈建议Home Assistant,因为它成本很低,而且完全处于家中的局域网,不受其它厂商、云端、app的限制。我在搭建自己的智能家居系统时也跳了很多坑,遇到小厂商跑路的,遇到大厂商云端多个设备要收费的,自己也尝试从零写过中控,其实最终归根到底就一个原因:“我控制自己家里的设备,凭什么还要被别人限制和收钱?”,最后还是选择了Home Assistant,入坑后才发现Home Assistant如此强大,生态也很好,ESP8266+ESPHome真的是太香了。这篇文章主要是给新手抛砖引玉,展示一下Home Assistant的自动化场景。我在智能家居控制方面不喜欢华而不实的,更喜欢简单实在的,例如:我希望夏天花园里的花每天晚上能够自动浇水,不需要我去下浇水的指令;我希望晚上打开门时,如果家里没开灯,夜灯能自动亮起。更倾向于设备能互相协同自动完成某些任务,而不需要有人在某个app里点一下或者在某个中控屏上点一下,因为如果需要人工干预,那物理开关岂不是更有质感,为什么还要叫做智能家居呢?智能家居是为了解放自己,而不是简单的改变控制方式,从墙壁开关控制换成app控制这不叫智能,只能算遥控。接下来我以上篇文章里的控制led为例,来简单演示下Home Assistant的场景自动化如何使用,作为Home Assistant新手部署系列的最后一篇。后续文章我会出一些进阶的教程,例如:如何改造其它厂商的智能插座接入Home Assistant;如何不用智能门锁就能精确感知到门被从外边打开等系列教程。一、准备工作在开始设置自动化之前,先确认2个关键前提,避免后续操作踩坑:

  • Home Assistant已正常运行:确保你的Home Assistant主机(玩客云3)处于正常启动状态,能通过浏览器访问Home Assistant界面(默认地址:http://玩客云3主机IP:8123),并已登录管理员账号。
  • 设备状态正常:有一个在线的开关类设备,如果没有可以按照上篇的教程用ESP8266快速做一个。

二、检查设备是否在线1、检查设备是否集成到了Home Assistant中以上篇文章里的esp8266-led设备为例,在Home Assistant的「配置」→「设备与服务」→「设备」,能找到设备esp8266-led,点击esp8266-led能够进入设备详情页。你也可以使用自己其它在线的开关类设备进行尝试。图片2、确认设备在线设备如果在线,“开关”那个图标是彩色的,后边的开关可以鼠标点击切换,同时在右边“日志”区域也会实时显示当前状态。如果设备不在线“开关”那个图标是灰色的,也无法点击切换状态,如果不在线需要检查下设备是否上电、有没有成功接入同一个路由器等等。图片三、核心步骤:创建场景自动化Home Assistant的场景自动化核心是「触发器→动作」(新手无需理解复杂逻辑,跟着步骤点就行,随着使用会慢慢理解),我们要实现的也是最常用到的“定时触发”,让ESP8266开关在指定时间自动打开/关闭,分为两个自动化任务:定时开启、定时关闭,步骤完全一致,可直接复制操作。步骤1:进入Home Assistant自动化设置界面在Home Assistant网页端,点击左侧菜单栏「配置」,在右边找到「场景与自动化」,点击进入(这是Home Assistant所有自动化任务的管理中心)。图片进入后,点击右下角「创建自动化」,在弹出的选项中选择「创建新自动化」,就会进入空白自动化编辑页面——这里就是我们设置定时规则的核心界面。图片步骤2:设置「触发条件」(什么时候执行)触发条件就是通过什么来触发启动自动化,点击“添加触发条件”可以看到有很多类型,你能想到的在这里都有,除了常见的语音、时间、设备就连“地理位置”都可以作为触发条件。图片我们以“时间模式”作为触发器,有点类似于linux里的定时任务,比如每小时的0分开启开关。图片步骤3:设置「环境条件」(什么情况执行)环境条件是指当前所处环境情况,如在什么时间?什么地点?什么温度等信息,这里演示一下在多个时间点都能触发,选择“或者”,类似于编程语言的或者(OR)。图片选择“或者”后,就可以添加多个并行条件了。图片这里还是添加时间图片添加一个时间范围,第一个范围是每天21:25~22:50时间段,每小时的0分,也就是整点时会触发。图片按照刚才的步骤,在“或者”条件里增加多个时间段。图片步骤4:设置「动作」(谁执行)点击「添加动作」,就会有多种选项可以选择,新手先选择“设备”吧,等到用的多了再来慢慢尝试摸索每一个的作用。图片找到要控制的设备,esp8266-led,如果你时控制其它设备,找到对应的设备就可以。具体的动作选择“切换开关”,意思就是触发后,Home Assistant判断当前开关状态,如果是打开状态就执行关闭,如果是关闭状态就执行打开。类似与编程里的取反操作。图片步骤5:保存点击右下角的保存按钮,根据自己实际用途输入一个名称就可以了。图片四、验证调试:确认场景自动化是否如期触发这里主要讲调试Home Assistant场景自动化,其实也很简单,打开Home Assistant的日志,里面会有自动化触发的详细日志。我为了方便调试,将触发时间改成了每小时的第50分钟。从日志里可以看到已经成功触发,并将开关状态设置未开启状态。图片

五、新手避坑指南(必看!少走弯路)很多新手第一次设置会踩坑,整理了3个最常见的问题,提前规避:

  • 坑1:找不到开关实体 → 检查ESP8266设备是否正常接入Home Assistant,确认设备状态为“在线”,如果显示“不可用”,先重新连接设备,重启ESP8266、检查网络,进行ping操作确认网络是否有问题。
  • 坑2:自动化不执行 → ① 检查Home Assistant主机时间是否正确(时间错误会导致定时不准);② 检查触发器和动作是否设置正确(比如动作选错“打开/关闭”,实体选错);③ 点击「运行」测试,排除设备本身问题,场景自动化也可以手工触发执行。
  • 坑3:定时只执行一次 → 忘记勾选星期里的具体哪一天,在触发器设置中,默认是工作日,工作日有可能是西方工作日。

注意:ESP8266插座涉及220V强电,DIY和使用过程中务必注意安全,确保电路连接正确、绝缘到位,非专业人士请勿随意拆解改造;如果Home Assistant断网,本地定时自动化仍可正常执行(Home Assistant本地优先特性),但ESP8266需保持网络连接,才能接收Home Assistant的控制指令。六、总结其实Home Assistant的自动化并没有想象中复杂,新手入门最关键的是“聚焦核心需求”,先搞定一个简单的定时控制,再逐步尝试进阶功能。这是Home Assistant部署系列教程的最后一篇了,相信小伙伴们都是有实力的。后续会分享更多智能设备DIY的实战,例如:市面上的智能插座如何通过简单改造接入Home Assistant;不依赖智能门锁如何感知门从外边被打开等等实用的小制作。关注我,新手也能轻松玩转智能家居~如果操作过程中遇到问题,评论区留言,一起交流解决!

 

Many smart home beginners struggle with choosing which central controller to use, and I still strongly recommend Home Assistant because it has very low cost and runs entirely on your local home network, free from restrictions by other manufacturers, cloud services, or apps. When I was building my own smart home system, I fell into many traps—dealing with small manufacturers going out of business, large manufacturers charging fees for multiple cloud-connected devices, and even attempting to write a central controller from scratch. Ultimately, it all boiled down to one reason: "Why should someone else restrict and charge me for controlling my own devices?" I ended up choosing Home Assistant, and only after diving in did I realize how powerful it is and how robust its ecosystem is. ESP8266 + ESPHome is truly fantastic. This article is mainly intended to give beginners a starting point, showcasing Home Assistant automation scenarios. I prefer practical, no-nonsense smart home control over flashy gimmicks. For example: I want the flowers in my garden to be automatically watered every night without me having to issue a command; when I open the door at night, if the lights aren't already on, the night light should turn on automatically. I lean toward devices working together to complete tasks autonomously, rather than requiring someone to tap a button in some app or on some smart control panel. Because if manual intervention is needed, why not just use a physical switch—it has more tactile quality—and why call it "smart home"? Smart home is meant to free you, not simply change the control method from wall switches to app taps; that's not intelligence, it's just remote control. Next, using the LED control example from my previous article, I'll briefly demonstrate how to use Home Assistant's scene automation. This is the final article in the Home Assistant新手部署系列. Subsequent articles will cover advanced tutorials, such as: how to integrate other brands' smart plugs into Home Assistant; how to precisely detect when a door is opened from the outside without a smart door lock, and more. I. Preparation Before setting up automation, confirm two key prerequisites to avoid pitfalls later:

Home Assistant is running normally: Make sure your Home Assistant host (玩客云3) is booted up properly and can be accessed via browser at the Home Assistant interface (default address: http://<玩客云3主机IP>:8123), and that you've logged in with an admin account.

Device status is normal: Have an online switch-type device ready. If you don't have one, follow the previous tutorial to quickly build one using ESP8266.

III. Core Steps: Creating Scene Automation The core of Home Assistant scene automation is"Trigger → Action"(beginners don't need to understand complex logic—just follow the steps, and you'll gradually understand as you use it). What we're implementing here is the most commonly used"timer trigger,"automatically turning the ESP8266 switch on/off at specified times, divided into two automation tasks: scheduled on and scheduled off. The steps are identical and can be directly copied. Step 1: Enter the Home Assistant Automation Settings Interface On the Home Assistant web interface, click「Configuration」in the left menu bar, then find「 Scenes & Automations」on the right and click to enter (this is the management center for all Home Assistant automation tasks). Once inside, click「Create Automation」in the bottom-right corner, select「Create new automation」from the popup options, and you'll enter a blank automation editing page—this is the core interface for setting up timed rules. Step 2: Set the「Trigger Condition」(when to execute) Trigger conditions determine what initiates the automation. Click"Add Trigger Condition"to see many types—all the scenarios you can imagine are available here, including common ones like voice, time, and devices, as well as"Geolocation." We'll use the"time pattern"as the trigger, somewhat similar to Linux cron jobs, e.g., turning the switch on at the 0th minute of every hour. Step 3: Set the「Condition」(under what circumstances to execute) Conditions refer to the current environment—such as what time, what location, what temperature, etc. Here we'll demonstrate triggering at multiple time points, selecting"Or,"which is analogous to the OR operator in programming languages. After selecting"Or,"you can add multiple parallel conditions. Still add a time condition. Add a time range: the first range is 21:25–22:50 every day, triggering at the 0th minute of each hour (i.e., on the hour). Following the same steps as before, add multiple time ranges under the"Or"condition. Step 4: Set the「Action」(who executes) Click「Add Action」to see various options. Beginners should start with"Device,"and gradually explore the purpose of each option as you gain more experience. Find the device you want to control—esp8266-led. If you're controlling a different device, find the corresponding one. For the specific action, choose"Toggle Switch,"meaning that after triggering, Home Assistant checks the current switch state and turns it off if it's on, or turns it on if it's off—similar to a bitwise NOT operation in programming. Step 5: Save Click the save button in the bottom-right corner and enter a name according to your actual use case. IV. Verification & Debugging: Confirming Whether Scene Automation Triggers as Expected This section mainly covers debugging Home Assistant scene automation, which is actually quite simple. Open the Home Assistant logs, where detailed logs of automation triggers will be recorded. For easier debugging, I changed the trigger time to the 50th minute of every hour. From the logs, you can see that it triggered successfully and set the switch state to on.图片图片图片图片图片图片图片图片图片图片图片图片图片图片图片

V. Beginner Pitfall Guide (Must Read! Save Yourself Trouble) Many beginners encounter pitfalls on their first attempt at setting things up. I've compiled the 3 most common issues to help you avoid them in advance:

Pitfall 1: Can't find the switch entity → Check whether the ESP8266 device is properly connected to Home Assistant and confirm the device status shows"online."If it displays"unavailable,"reconnect the device first, restart the ESP8266, check the network, and perform a ping test to confirm there are no network issues.

Pitfall 2: Automation doesn't execute → ① Check whether the Home Assistant host time is correct (incorrect time will cause timing inaccuracies); ② Check whether the trigger and action are set correctly (e.g., wrong action selected as"on/off,"wrong entity chosen); ③ Click「Run」to test and rule out device-level issues—scene automation can also be manually triggered.

Pitfall 3: Timer only executes once → Forgot to select specific days of the week. In the trigger settings, the default is"weekdays,"which may follow Western workday conventions.

Note: The ESP8266 plug involves 220V mains electricity. Always prioritize safety during DIY and usage—ensure circuits are correctly connected and properly insulated. Non-professionals should not casually dismantle or modify the device. If Home Assistant loses internet connection, local scheduled automation can still execute normally (due to Home Assistant's local-first feature), but the ESP8266 must remain network-connected to receive control commands from Home Assistant. VI. Summary Actually, Home Assistant automation isn't as complex as it seems. The key for beginners is to"focus on core needs"—start by mastering a simple timed control, then gradually try advanced features. This is the final article in the Home Assistant deployment series, and I believe all of you are capable. I'll share more practical smart device DIY tutorials in the future, such as: how to integrate commercially available smart plugs into Home Assistant through simple modifications; how to detect when a door is opened from the outside without relying on a smart door lock, and other useful projects. Follow me, and even beginners can easily master smart home! If you encounter any issues during operation, leave a comment below, and let's solve them together!

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

📮 需求咨询📮 Inquiry