Trying to create a reasonably tricky config for ESPHome (on ESP32) & keep running into brick walls. Been struggling with this all day & am hoping some big-brain out there can help please.
Scenario as follows:
- Have a number, say 8-10, template switches (number is fixed at build) which can be turned on/off via HAss
- consistent naming convention, eg:
id: switch_01
...
id: switch_02
etc
- Each switch is exclusively associated with one or two GPIOs
- When a switch is turned on, the GPIO(s) need to toggle in specific patterns
- Each pattern is easily realised by a relatively simple script
- Some patterns run once & then stop
- Other patterns run in a loop for as long as that specific switch is turned on, ie:
- while:
condition:
switch.is_on: switch_01
then:
...
- The specific pattern required should be user-selectable via HAss UI
- Using one select component per switch
- If the user selects a different pattern for a switch, then that pattern should run the next time the switch is turned on
So, in configuration I have defined:
- multiple outputs (GPIOs)
- multiple template switches
- corresponding select entities - one per template switch
- multiple scripts, one per pattern
What I’m trying to achieve when a template switch is turned on is:
- Determine the pattern selected by the user for that switch, eg:
!lambda 'return id(config_switch_01).state;'
- Determine & invoke the corresponding script with references to the GPIOs & the affected switch
- The script runs, toggling the appropriate GPIO(s), either once or for long as the relevant switch is kept turned on
All of this works nicely if I hard-code everything, but where I’m struggling is to make the scripts generic by getting & passing to them references to the respective GPIOs & calling switch.
I can do this sort of thing in HAss config, but not having much luck with ESPHome.
I’m starting to dive into the world of complex lambdas & suspect I’m getting closer, but could really do with a hand.
Is anybody able to provide any hints please?