I have a bunch of ESP32 based environmental sensors around my house that use the same code because they all use the same sensors, but also have some unique code because of unique sensors.
I’ve been trying to experiment with using !include
to make the code leaner (only need to edit one copy when making changes), but I can’t seem to find the correct formatting.
Let’s assume I have two sensors. A “abc123” sensor which is unique to that device, and a “xyz321” sensor which is common across all my devices. So I want to put xyz321’s code in a separate yaml.
Which of the following is correct?
#example 1
sensor:
- platform: abc123
...
<<: !include sensor_xyz321.yaml
with no dash or indent before the include
or
#example 2
sensor:
- platform: abc123
...
- <<: !include sensor_xyz321.yaml
with dash and indent before the include
or
#example 3
sensor:
- platform: abc123
...
<<: !include sensor_xyz321.yaml
with indent but no dash
And then should the contents of sensor_xyz321.yaml
be
#example 4
platform: xyz123
...
with no dash or indents
or
#example 5
- platform: xyz123
...
with dash and indents
or
#example 6
sensor:
- platform: xyz123
...
with a re-declaration of sensor
along with dash and indents
note: I numbered the examples to make them easier to refer to
And if multiple possibilities work, is there an advantage to one vs the other?