惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

F
Full Disclosure
WordPress大学
WordPress大学
小众软件
小众软件
Cloudbric
Cloudbric
AWS News Blog
AWS News Blog
腾讯CDC
量子位
人人都是产品经理
人人都是产品经理
大猫的无限游戏
大猫的无限游戏
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
V
Vulnerabilities – Threatpost
Scott Helme
Scott Helme
Hugging Face - Blog
Hugging Face - Blog
博客园_首页
C
CXSECURITY Database RSS Feed - CXSecurity.com
The Hacker News
The Hacker News
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
IT之家
IT之家
Jina AI
Jina AI
Attack and Defense Labs
Attack and Defense Labs
S
SegmentFault 最新的问题
Simon Willison's Weblog
Simon Willison's Weblog
The Cloudflare Blog
阮一峰的网络日志
阮一峰的网络日志
T
Tailwind CSS Blog
Last Week in AI
Last Week in AI
博客园 - 【当耐特】
Google Online Security Blog
Google Online Security Blog
美团技术团队
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
V
Visual Studio Blog
罗磊的独立博客
L
LINUX DO - 最新话题
博客园 - Franky
博客园 - 叶小钗
Apple Machine Learning Research
Apple Machine Learning Research
The Last Watchdog
The Last Watchdog
J
Java Code Geeks
AI
AI
C
Cisco Blogs
酷 壳 – CoolShell
酷 壳 – CoolShell
C
Cyber Attacks, Cyber Crime and Cyber Security
Cisco Talos Blog
Cisco Talos Blog
博客园 - 三生石上(FineUI控件)
雷峰网
雷峰网
Help Net Security
Help Net Security
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
云风的 BLOG
云风的 BLOG
I
Intezer
S
Securelist

Simply Explained

Converting a Tuya Thermostat to ESPHome Bringing Foam Monsters to Life: How I Wrote and Illustrated a Children's Book Using AI How I Built an NFC Movie Library for my Kids Analyzing Link Rot in My Newsletter (After 31 Editions) How I Use Alfred to Search My Obsidian Notes Faster (with Spotlight!) Year in review: 2022 Smart lights behind a wall switch (Shelly, Z-Wave, ESPHome) Serverless Anagram Solver with Cloudflare R2 and Pages Integrate Home Assistant with Apple Reminders How WebP Images Reduced My Bandwidth Usage by 50% Tracking gas usage with ESPHome, Home Assistant, and TCRT5000 My Sixth Year as YouTube Creator (statistics + retrospective) EZStore: a tiny serverless datastore for IoT data (DynamoDB + Lambda) ESP-IDF: Storing AWS IoT certificates in the NVS partition (for OTA) How to securely access your home network with Cloudflare Tunnel and WARP I Built a CO2 Sensor and It Terrifies Me Filtering spam on YouTube with TensorFlow & AI Building a killer NAS with an old Rackable Server Howto Virtualize Unraid on a Proxmox host MAX17043: Battery Monitoring Done Right (Arduino & ESP32) Preventing Cumulative Layout Shifts with lazy loaded images (Eleventy + markdown-it) Migrating This Blog From Jekyll to Eleventy Good Home Automation Should be Boring ESP32 Cam: cropping images on device Retrospective: My Fifth Year on YouTube Secure Home Assistant Access with Cloudflare and Ubiquiti Dream Machine Shelly 2.5 + ESPHome: potential fire hazard + fix Impact of Adblockers on Google Analytics (vs. Plausible) Shelly 2.5: Flash ESPHome Over The Air! Tuya IR Hub: control Daikin AC (Home Assistant + ESPHome) Building Air Quality Sensor: Luftdaten + Home Assistant HEIC to JPG: Build a Quick Action with Automator Make Your Garage Door Opener Smart: Shelly 1, ESPHome and Home Assistant Static webhosting benchmark: AWS, Google, Firebase, Netlify, GitHub & Cloudflare Why I don't take sponsorships Monitoring my 3D printer with a Pi Zero, Home Assistant and TinyCore Linux ESP32: Keep WiFi connection alive with a FreeRTOS task Home Energy Monitor: V2 Retrospective: 4 years on YouTube
How I Structure My ESPHome Config Files
Xavier Decuy · 2021-05-27 · via Simply Explained

I'm a big fan of ESPHome. I have 24 devices running it, and I only buy new IoT devices when I know they can run ESPHome.

ESPHome is a modular firmware that you have to configure with YAML files. You define what components it should load and how it should talk to the hardware of your device (GPIO pins, LEDs, relays, sensors, Home Assistant integration...)

However, YAML files can get messy quickly. With 24 devices running, I spent a lot of time coming up with a proper structure to add new devices and change the behavior of existing ones without having to copy-paste the same things repeatedly.

Here's an overview of the structure I came up with:

My ESPHome YAML config structure

Base configuration

It starts with the base configuration, which contains settings for all my ESPHome devices, regardless of their type, function, or brand.

It contains the configuration for my WiFi network, fallback access point, API for Home Assistant, and over-the-air updates.

The .base.yaml file looks like this:

---
wifi:
  ssid: !secret wifi_iot_ssid
  password: !secret wifi_iot_password

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: ${friendly_name} AP
    password: !secret esphome_fallback_ap_password

captive_portal:

# Enable logging
logger:

# Enable Home Assistant API
api:
  password: !secret esphome_api_password

ota:
  password: !secret esphome_api_password

Base device configuration

Next up: is the base device configuration. Here, I configure all the items that are the same for one particular type of device.

For instance, here is my config file for the Shelly 1 (.base.shelly1.yaml):

---
esphome:
  name: $devicename
  platform: ESP8266
  board: esp01_1m

# Device Specific Config
output:
  - platform: gpio
    pin: GPIO4
    id: shelly_1_relay

light:
  - platform: binary
    name: $light_name
    output: shelly_1_relay
    id: lightid

binary_sensor:
  - platform: gpio
    pin:
      number: GPIO5
    name: "Switch Shelly 1"
    on_state:
      then:
        - light.toggle: lightid
    internal: true
    id: switchid

It defines which platform is used (ESP8266 or ESP32) and the type of board, and how much memory it has (esp01_1m).

It also configures the relay and input pin of the Shelly 1, and exposes this as a light to Home Assistant.

Actual configuration

And finally, we arrive at the configuration file for an actual device.

Here's the configuration for a Shelly 1 that controls my office lights (shelly1-office.yaml):

---
substitutions:
  devicename: office
  light_name: Office
  friendly_name: Office Light

<<: !include .base.yaml
<<: !include .base.shelly1.yaml

It defines the name of the device, the name of the lights, and a friendly name. At the bottom, I import the base file (with generic configuration) and the generic configuration for all Shelly 1 devices.

File structure

I'm using the ESPHome add-on for Home Assistant to manage and update my devices. All of my configuration files are stored in my Home Assistant instance, and here's what the file structure looks like:

esphome
├── .base.yaml
├── .base.shelly1.yaml
├── .base.shelly25.yaml
├── .base.sonoff-mini.yaml
├── shelly1-garage-door.yaml
├── shelly1-office-lights.yaml
├── shelly25-kitchen-lights.yaml
├── sonoff-mini-backdoor-light.yaml
└── sonoff-mini-garage-lights.yaml

I put a dot in front of the base files so that they would be grouped together at the top of a directory listing. This is just a personal preference.

I also have a naming convention for my config files to help me quickly find the file I need:

[device type]-[room in the house]-[description]

Conclusion

This structure prevents you from having to copy-paste the same config items over and over again. It's also easy to tweak the behavior of specific devices. If I want all my Shelly's to report the state of the input to Home Assistant, I can change that in the .base.shelly1.yaml file, and I'm done!

Note that this structure is rigid, and some limitations come with it. For instance: you can't define sensor items in multiple configuration files as they'll overwrite each other.