ESPHome configuration files are written in YAML — a human-friendly data serialization format designed to be easy to read and edit. The order of top-level configuration blocks in an ESPHome YAML file is generally unimportant, since the entire file is parsed before any validation or processing begins. YAML is a superset of JSON, so valid JSON is also valid YAML.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/esphome/esphome.io/llms.txt
Use this file to discover all available pages before exploring further.
YAML is highly sensitive to indentation. Tabs are not allowed — use spaces consistently throughout your file. Incorrect indentation is the most common source of configuration errors in ESPHome.
Standard YAML Features
ESPHome supports the full YAML 1.1 specification. The following features are used most often in ESPHome configurations.Comments
Any text after a# symbol is treated as a comment and ignored by the parser. If you need a literal # character inside a value, wrap the value in quotes.
Scalars
A scalar is any single value: a string, number, boolean, or null. Unquoted sequences that are not valid numbers or booleans are treated as strings (e.g.,23times). Standard escape sequences such as \n are interpreted inside double-quoted strings only.
Boolean values accept true / false (case-insensitive). ESPHome also maps several additional strings:
Evaluates to true | Evaluates to false |
|---|---|
yes, on, enable | no, off, disable |
Sequences
A sequence is an ordered list. ESPHome supports both block style (one item per line with a- prefix) and flow style (comma-separated inside [ ]).
When a sequence item is itself a mapping (the common case for component lists), the keys sit at the same indent level as the
-. When a sequence item is a key whose value is a mapping, the next level must be indented further.Mappings
A mapping is a set of key-value pairs (also called a dictionary). Keys must be unique within a single mapping. Values can be any YAML type — scalars, sequences, or nested mappings.{ key: value } are also valid and useful for compact inline notation:
Anchors, Aliases, and Merge Keys
YAML anchors (&name) mark a block for reuse; aliases (*name) insert a copy of that block elsewhere. The merge key <<: *name merges an anchored mapping into another, with local keys taking precedence.
platform, device_class, unit_of_measurement, accuracy_decimals, and state_class from the anchor, while each overrides name and pin.
Multi-line Strings
YAML provides several ways to embed multi-line text. The two most useful styles in ESPHome are block literal (|) and block folded (>).
| Style | Character | Newlines | Trailing newline | |
|---|---|---|---|---|
| Literal | ` | ` | Preserved | One newline added |
| Literal strip | |- | Preserved | Removed | |
| Folded | > | Collapsed to space | One newline added | |
| Folded strip | >- | Collapsed to space | Removed |
|- style (literal strip) is the most common choice inside ESPHome because it keeps internal newlines and removes the trailing newline:
ESPHome YAML Extensions
ESPHome adds several non-standard tags and top-level keys on top of standard YAML.Secrets — !secret
The !secret tag pulls a value from a separate secrets.yaml file in the same directory. This lets you share configuration files without exposing passwords, API keys, or other sensitive values.
Substitutions
Thesubstitutions: block lets you define named values that can be referenced anywhere in the configuration with ${name} or $name syntax. Substitutions are expanded before validation, making them ideal for device-specific values in shared templates.
${ }, enabling arithmetic and conditional logic:
-s flag:
!include
The !include tag inserts the contents of another YAML file at the current position. Variables can be passed to the included file using vars:, and they take precedence over any global substitutions defined in the including file.
Packages
Thepackages: feature merges one or more partial configurations into your main file. Values in the main configuration take precedence over values in the package. This is the recommended approach for sharing a common base configuration across many devices.
Hidden Items
Any top-level key that starts with a. is silently ignored by ESPHome. This is useful for defining YAML anchors that should not appear in the final configuration:
Lambdas
ESPHome allows embedding C++ code using the!lambda tag. Lambdas are evaluated at runtime and provide dynamic values or logic not expressible in YAML. See Templates for details.