esphome / esphome/feature-requests
Script Triggers
- Dominant language
- No language data
- Stars
- 450
- Forks
- 29
- PR merge metrics
- No merged PRs in 30d
Description
**Describe the problem you have/What new integration you would like**
I'd like to be able to define a trigger for any script. Any trigger that is supported by a component should be able to be referenced.
So this:
```yaml
light:
- platform: cwww
id: my_light
[...]
on_state:
- script.execute: my_script
```
Could optionally be written like this:
```yaml
script:
- id: my_script
triggers:
- light.on_state:
id: my_light
then:
[...]
```
**Please describe your use case for this integration and alternatives you've tried:**
I like to make my configs as modular and reusable as possible, making frequent use of packages. So I have one package that defines the pins, and settings for a light. Then I have another package that does automatons based on the light state. Using substitutions this automations package can be applied to multiple lights with different IDs. This is difficult because the automatons need to be triggered by `on_state` in the light configuration. So the light package is no longer independent cause it's config references a script in the automatons package.
I've tried setting a default noop script in the light package, referenced with a substitution. Then when the main config combines the packages, it substitutes the `on_light_state` variable with the automation script. This is okay, but it's not the cleanest. And I need a second noop script and variables like `on_light_state_2` to be able to trigger multiple scripts from the same light event.
**Additional context**
Contributor guide
No contributing guide indexed for this repository
Research direction
Start by tracing the YAML examples for light.on_state, script.execute, and script.triggers, then review how component-supported triggers are currently connected to scripts. Done means a script can reference supported triggers from a component, while package configurations remain independent and multiple scripts can respond to the same light event.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- yaml
- Domain
- embedded-iot
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100