I’m trying to modularize my ESPHome .yaml files. I’ve got lots of devices and some of them are meant to react in a special way. I’m looking for a way to execute scripts (call methods) that may or may not be declared. Consider this example:
I’ve got a common .yaml that defines via “on_multi_click” what a “triple click” is (all of the devices have at least one button). It executes a script named “button_triple_click”.
In my device-specific .yaml, when I declare this script, everything works as it should. However many of my devices should not react to a triple click in a special way. I don’t want to define empty scripts for all of them. But if I don’t, I get a compile error from “esphome compile…”
I can see two options to solve this problem:
- Execute a script in a way that the existance of it is optional. Do nothing if it doesn’t exist. I investigated but did not find a way to declare a script/execution like that.
- Declare an empty script stub in the common yaml, but override that script in the cases where I do want a special reaction. If I try this, I get an “ID button_triple_click redefined!” compile error.
If ESPHome were object oriented, I’d declare an empty stub method in a superclass and override it in subclasses on demand. Is there something like this in ESPHome?
This is just a simple example. I’ve got this problem in many places, threatening to bloat my configuration by an unsustainable factor.