esphome / feature-requests

ESPHome Feature Request Tracker
https://esphome.io/
411 stars 26 forks source link

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

Open hippich opened 1 year ago

hippich commented 1 year ago

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.

anthonykeane commented 1 month ago

Dito,

substitutions not working in

` - platform: template

name: AC301 Button

id: ir_sw3

turn_on_action:      

- remote_transmitter.transmit_raw:

    carrier_frequency: 38kHz

    # 29deg Heat    

    code: ${set30}

`

where set30 is a list