Lately I’ve been keeping my ESPHome configs separated into a generic device file (in this example, a certain model of smart plug) and a file with substitutions specific to the item I’ll be installing it on. This works great for things like the name, but I’m stuck on trying to use this for something like the linear_calibration values where there are multiple lines in the substitution.
I have been trying to use the | symbol as the YAML standard specifies, which almost works but I get various errors. For example, this is the closest I’ve gotten to a working config:
(in the generic yaml)
power:
name: ${device_name} Power
id: power
filters:
- delta: 0.01
- calibrate_linear:
- ${power_calibration}
(in the item-specfic yaml)
power_calibration: |
0.0 -> 0.0
- 1.0 -> 1.2
This generates errors when trying to compile:
while parsing a block mapping
in "/config/esphome/coffee_maker_plug.yaml", line 2, column 3:
id_name: coffee_maker_plug
^
expected <block end>, but found '-'
in "/config/esphome/coffee_maker_plug.yaml", line 7, column 3:
- 1.0 -> 2.0
^
I wish yaml had support for lambdas, something like:
somestuff_tmpl: &somestuff
- thing: {param1}
- thing: {param2}
thingie_with_param2: some_literal
something1: *somestuff_tmpl{
param1: too
param2: bar
}
but then again, this would make it turing complete, and it’d be only a matter of time when someone would propose standard libraries and built-ins
perhaps jsonnet could output yaml for you, but you’d lose some of the tooling that exists for yaml, and perhaps ESPhome could be improved (debatable) by allowing for more than one config language…