esphome / esphome/feature-requests

Substitutions feature for lists/arrays in .yaml config file?

Open
#2,346 1 comment 6 reactions 0 assignees View on GitHub
Dominant language
No language data
Stars
450
Forks
29
PR merge metrics
No merged PRs in 30d

Description

**Describe the problem you have/What new integration you would like**

I am trying to create ESPHome controller for ceiiling fans around my house using CC1101 board and https://github.com/dbuezas/esphome-cc1101 code. So far it works pretty well, but I need to configure ~10 remote's buttons multiplied by several fans. I want to avoid repeating raw code and provide some structure. ESPHome's `substitutions` feature seems like a perfect candidate, but I can't figure out how to apply it to arrays/lists.

**Please describe your use case for this integration and alternatives you've tried:**

I have something like that at the very top of my .yaml file:

```
substitutions:
cc1101_device_id: 335, -359, 648, -709, 297, -709, 295, -736, 294, -712, 294, -387, 634, -384, 632, -709, 318, -359, 658, -706, 296, -729, 301, -714, 308, -344, 665, -693, 312, -721, 291, -374, 642, -382
cc1101_button_stop: 647, -359, 649, -712, 295, -384, 654, -362, 655, -362, 654, -360, 654, -360, 657
```

And I want to define binary_sensor like this:

```
binary_sensor:
- platform: remote_receiver
name: Master Bedroom Fan Stop
raw:
code: [ ${cc1101_device_id} , ${cc1101_button_stop} ]
```

It fails to compile at `code: ` line, expecting a plain yaml list instead of what I've put into it. I think substitutions simply not applied here, since it is list/array.

Any ideas of alternative that would allow me to modularize configuration?

**Additional context**

I run ESPHome together with Home Assistant if that makes any difference.

Contributor guide

No contributing guide indexed for this repository

Research direction

No repository file, test, or entry point is named. Start by reproducing the shown ESPHome YAML with substitutions and the raw receiver code, then trace how substitutions are parsed before list validation. Done means the requested list and array values can be modularized without repeating the raw codes.

Written by the indexing model from the issue text.

Assessment

Tech stack
yaml
Domain
embedded-iot, tooling
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.