Hi
Does the esphome yaml have conditional compile functionality?
I have several LD2450 sensors. They can count the number of people in up to three zones.
Everything regarding these is defined in a file include/ld2450.yaml.
For some of them I need all three zones, but for some one is enough. Today I have separate include files for this.
To avoid unnecessary/confusing sensors and stuff, I would like to add something like this to my include file (where zones could be defined in substitutions):
I was about to suggest this too. Put the additional zones in a separate package. You can even pass parameters to packages with some effort. This comes straight from some of my yaml files:
Some of these packages add parameters to preexisting sections like ble:
The package files contain yaml with sensors etc. just like you would put it in the esp yaml.
Packages is the only way you can somehow compose your files.
There is no real condition, if/then logic in yaml.
It is purely declarative.
The only thing you could do is to add a step with Jinja templates and add conditionals in there.
But then you have to generate the yaml files from templates and then compile the yaml for your device.
Quite cumbersome.
Thanks! I’ll give it a try!
I’ve seen that some yaml files can contain conditional compilation, but they are for very proprietary solutions.
I guess it should be possible in esphome too, but it’s not extremely important.
Yeah another thing I noticed is you can’t conditionally load a module. For example this does not work.
substitutions:
libary_folder: "/my_library"
packages:
# If your touch screen has a backlight include this
backlight: !include ${libary_folder}/modules/base/backlignt.yaml
I agree, but in esphome as well as in other environments, yaml is being used as a preprocessor for c++ or other languages.
Or, even as something resembling a scripting language in it’s own right.
This is an example from some microsoft product, where the “${{ if” decides whether to include the following section or not.
Something like that would be helpful in esphome as well.
- ${{ if eq(parameters.paramA, 'true') }}:
- powershell: |
"Conditional insertion from parameter whose value came from a variable"
displayName: conditionally inserted task from variable