How to leverage c-preprocessor directives in esphome yaml #6123
maartenSXM
started this conversation in
General
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
It turns out it is possible to leverage c-preprocessor (cpp) directives in yaml. Once hash-style comments are removed from the yaml while leaving cpp directives, it can be run through the c-preprocessor to generate a yaml file that esphome can grok. This gives us the ability to have #if ... #endif to map blocks of yaml in and out based on configuration definitions that are set via #define. And also, we get block-style comments using #if 0 ... #endif or /* ... */, which are handy. Also, this technique enables the sharing of pin definitions between yaml and C or C++ code using #define of pin numbers instead of using esphome substitutions.
I have been using this to generate multiple esphome image variants from the same yaml sources using a config.h. If you like this idea, have a boo at the example project here. Happy esphome-ing! :-)
Cheers, Maarten
Beta Was this translation helpful? Give feedback.
All reactions