After banging my head against this for a while, and remembering what was said before about automations being able to run simultaneously, I realized that if you don’t care that your scripts might get run simultaneously (or, in fact, you want this), then you can write it as an automation with a custom event trigger, and call it by firing that event. I’ve re-written several of my scripts like this, and it works very well.
Define your script as an automation:
automation:
- alias: automation_name
trigger:
- platform: event
event_type: automation_name <--- I name the event after the automation
to keep it simple.
action:
- service: whatevs
data_template:
foo: "{{ trigger.event.data.param_1 }}"
bar: "{{ trigger.event.data.param_2 }}"
Then call it like this:
action:
- event: automation_name
event_data_template:
param_1: asdf
param_2: qwer