当前位置: 首页 > news >正文

使用ESPHome烧录固件到ESP32-C3并接入HomeAssistant

文章目录

  • 一、安装ESPHome
  • 二、配置ESP32-C3控制灯
    • 1.主配置文件esp32c3-luat.yaml
    • 2.基础通用配置base.yaml
    • 3.密码文件secret.yaml
    • 4.围栏灯four_light.yaml
    • 5.彩灯rgb_light.yaml
    • 6.左右柱灯left_right_light.yaml
  • 三、安装固件
  • 四、HomeAssistant配置ESPHome
    • 1.直接访问
    • 2.配置ESPHome地址
    • 3.接入成功

一、安装ESPHome

uv init
uv add esphome
uv run esphome dashboard ./esphome

二、配置ESP32-C3控制灯

注意事项
1. id和name要用英文,不要用中文
2. wifi连接要用2.4GHz,不要用5GHz
3. i2c要注意frequency的设置

文件目录如下
在这里插入图片描述
ESP32-C3开发板
在这里插入图片描述

1.主配置文件esp32c3-luat.yaml

# https://wiki.luatos.com/chips/esp32c3/board.html
esphome:name: esp32c3-luatfriendly_name: esp32c3-luat
#  name_add_mac_suffix: trueplatformio_options:board_build.flash_mode: dioboard_build.mcu: esp32c3esp32:# HARDWARE: ESP32C3 160MHz, 320KB RAM, 4MB Flashboard: esp32-c3-devkitm-1variant: esp32c3framework:type: esp-idf# Enable logging
logger:hardware_uart: USB_SERIAL_JTAGpackages:# MAC: 60:55:f9:73:59:68base: !include common/base.yaml
#  luat_light: !include common/light/luat_light.yaml
#  luat_switch: !include common/switch/luat_switch.yamlfour_light: !include common/light/four_light.yamlrgb_light: !include common/light/rgb_light.yamlleft_right_light: !include common/light/left_right_light.yaml
captive_portal:
#<<: !include common/mechanical/matrix_keypad.yaml#WARNING GPIO2 is a strapping PIN and should only be used for I/O with care.
#WARNING GPIO8 is a strapping PIN and should only be used for I/O with care.
#WARNING GPIO9 is a strapping PIN and should only be used for I/O with care.
#Attaching external pullup/down resistors to strapping pins can cause unexpected failures.
#See https://esphome.io/guides/faq.html#why-am-i-getting-a-warning-about-strapping-pins
#12 13 This pin cannot be used on ESP32-C3s and is already used by the SPI/PSRAM interface (function: SPIHD).

2.基础通用配置base.yaml

# https://esphome.io/components/wifi
wifi:ssid: !secret wifi_ssidpassword: !secret wifi_passwordfast_connect: true# https://esphome.io/components/ota
ota:platform: esphomepassword: !secret ota_password# https://esphome.io/components/api
api:encryption:key: !secret api_encryption_key# 没有连接HA,默认15min会重启一次,设置为0s,将不再重启reboot_timeout: 0s# https://esphome.io/components/web_server
web_server:port: 80# https://esphome.io/components/mdns
mdns:disabled: falsetext_sensor:# https://esphome.io/components/text_sensor/version- platform: versionname: "Version"# https://esphome.io/components/text_sensor/wifi_info- platform: wifi_infomac_address:name: "Mac"ip_address:name: "IP"update_interval: 1mindns_address:name: "DNS"update_interval: 1minssid:name: "SSID"update_interval: 1minbssid:name: "BSSID"update_interval: 1min

3.密码文件secret.yaml

上面base.yaml中!secret wifi_ssid就是引用secret.yaml里面的wifi_ssid的值

# Your Wi-Fi SSID and password
wifi_ssid: "xxx"
wifi_password: "xxx"api_encryption_key: "xxx"
ota_password: "xxx"
ap_password: "xxx"

4.围栏灯four_light.yaml

# https://esphome.io/components/light/binary
light:- platform: binaryname: four_lightoutput: four_light_outputoutput:- id: four_light_outputplatform: gpiopin: 0

5.彩灯rgb_light.yaml

# https://esphome.io/components/light/rgb
light:- platform: rgbid: colorful_lightname: colorful_lightred: output_component_redgreen: output_component_greenblue: output_component_blue
# https://esphome.io/components/light/#pulse-effect
#    effects:
#        - pulse:
#        - pulse:
#            name: "Fast Pulse"
#            transition_length: 0.5s
#            update_interval: 0.5s
#            min_brightness: 0%
#            max_brightness: 100%
#        - pulse:
#            name: "Slow Pulse"
#            # transition_length: 1s      # defaults to 1s
#            update_interval: 2s
#        - pulse:
#            name: "Asymmetrical Pulse"
#            transition_length:
#              on_length: 1s
#              off_length: 500ms
#            update_interval: 1.5s
output:# https://esphome.io/components/output/ledc
#  - platform: ledc
#    id: output_component_red
#    pin:
#      number: 4
#      inverted: true
#  - platform: ledc
#    id: output_component_blue
#    pin:
#      number: 3
#      inverted: true
#  - platform: ledc
#    id: output_component_green
#    pin:
#      number: 2
#      inverted: true- platform: ledcid: output_component_redpin:number: 1inverted: true- platform: ledcid: output_component_bluepin:number: 18inverted: true- platform: ledcid: output_component_greenpin:number: 19inverted: true#output:
#  - platform: esp8266_pwm
#    id: output_component_red
#    pin: D1
#  - platform: esp8266_pwm
#    id: output_component_green
#    pin: D2
#  - platform: esp8266_pwm
#    id: output_component_blue
#    pin: D3

6.左右柱灯left_right_light.yaml

# https://esphome.io/components/light/binary
light:- platform: binaryname: left_lightoutput: left_light_output- platform: binaryname: right_lightoutput: right_light_output
output:- id: left_light_outputplatform: gpiopin: 6- id: right_light_outputplatform: gpiopin: 7

三、安装固件

在这里插入图片描述

四、HomeAssistant配置ESPHome

1.直接访问

在这里插入图片描述

2.配置ESPHome地址

如果配置了api_encryption_key,需要填写密钥
在这里插入图片描述

3.接入成功

在这里插入图片描述

http://www.xdnf.cn/news/343225.html

相关文章:

  • 森林生态学研究深度解析:R语言入门、生物多样性分析、机器学习建模与群落稳定性评估
  • WPF主窗体子窗体关联方法
  • WPF中解决数据绑定不匹配的问题
  • 中继器的作用
  • AI开发跃迁指南(第三章:第四维度2——weaviate cloud、weaviate docker安装配置及使用连接示例)
  • 【计算机网络】用户从输入网址到网页显示,期间发生了什么?
  • Nginx1.26.2安装包编译安装并配置stream模块
  • V型球阀材质性能深度解析:专攻颗粒、料浆与高腐蚀介质的工业利器-耀圣
  • WEB UI自动化测试之Pytest框架学习
  • RedHat磁盘的添加和扩容
  • 计数排序-详解
  • 从新手到高手:jQuery 全面进阶之路
  • 数字电子技术基础(五十六)——JK触发器
  • crawl4ai能替代scrapy等传统爬虫框架吗?
  • windows 部署 Kafka3.x KRaft 模式 不依赖 ZooKeeper
  • FPGA_Verilog实现QSPI驱动,完成FLASH程序固化
  • 学习黑客 MAC 地址深入了解
  • 解决社区录音应用横屏状态下,录音后无法播放的bug
  • 信息学奥赛一本通 1511:【SCOI2011】糖果 | 洛谷 P3275 [SCOI2011] 糖果
  • ProfiNet与CANopen:新能源时代的“语言翻译官”
  • Kotlin与Java企业级开发实战:从零到一掌握最新语法与技术精髓
  • Office宏病毒钓鱼-打点突破
  • ROS2基本操作1
  • js常用的数组遍历方式
  • HypotMAX7705771077157720HIPOT美国ASSOCIATEDRESEARCH耐压测试仪
  • 1分区 1-113 多线不起总线启
  • 使用pytorch保存和加载预训练的模型方法
  • Spring Boot 中 MongoDB @DBRef注解适用什么场景?
  • 深入理解软件测试覆盖率:从概念到实践
  • SpringBoot的自动配置和起步依赖原理