Closed michaelblight closed 2 years ago
Have you tried to remove the -
before the include like:
color:
<<: !include include/color/named.yaml
The dash specifies a list entry in yaml meaning you are making a list in a list with your above configuration
Dammit, you're right! All of my other uses have the "list in a list" situation - i.e. a -
before the <<:
and also in the included file, like I did with the binary_sensor
above. It's probably more surprising that they work. I also changed the binary_sensor
to remove the -
, and it's happy like that. Good that this is recorded here, for when I do the same thing again.
Now I'm confused - I did a 'Clean Build' and the error is back. So maybe closing was hasty. It seems I don't fully understand !include. It seems that the included file can only contain one list item if it's under a component. If correct, this makes it a bit useless for what I'm trying to do.
So the following both work:
<<: !include include/color/named.yaml # where the yaml contains "color:"
color: !include/color/named.yaml # not actually tested, but same as home assistant
Whereas the following will only include the first list item in the file:
color:
<<: !include include/color/named.yaml # where the yaml does not contain "color:"
#### or ####
color:
- <<: !include include/color/named.yaml # where the yaml does not contain "color:"
You can easily verify this by duplicating the id of something in an included file - you don't get an error because it picks up the first list item and ignores everything else.
In Home Assisstant you can achieve what I want using labels:
color label1: !include file1
color label2: !include file2
But this doesn't work in ESPHome. Perhaps time for a Feature Request.
EDIT: I tried various versions of include_dir_merge_list (etc), but couldn't get them to work either, although they appear supported. They seem to work, but I think it's remnants of a previous build somehow. It came unstuck with a "Clean Build".
The problem
I have a number of components stored in separate files, and tried to do the same for color.
The IDE is happy with it (no red x on line 1), but installing produces the compile error shown below. If I paste the content of the file (shown below) instead of the !include, it all works ok.
The same thing occurs if I try to do it in a file referenced in
device_base
underpackages
.Note that it works if I put the
color:
inside the file as well, and change my main yaml to:But I'm wanting to include multiple files like I do with sensors.
Which version of ESPHome has the issue?
2022.5.0
What type of installation are you using?
Home Assistant Add-on
Which version of Home Assistant has the issue?
2022.5.4
What platform are you using?
ESP32
Board
m5stick-c
Component causing the issue
color
Example YAML snippet
Anything in the logs that might be useful for us?
Additional information
No response