Call scripts with parameters?

I have now created a script inside scripts.yaml file which I can call.

Is it possible to call this script with parameters ?

For example, this is used for turning on a light, then wait 4 minutes and then turn it off again. But my problem is that I would like to use this functionality in several light groups, but the light groups are “hardcoded” inside the turn_on and turn_off parts of the script.

So - can I call a script with some kinds of parameters ?

Yup, but it’s not very easy to explain…

Imagine an automation and your action is:

action:
  service: script.clever_script
  data:
    this_light: livingroom

Then clever_script would say:

clever_script:
  sequence:
    - service: light.turn_on 
      data_template:
        entity_id: "light.{{ 'this_light'}}"

Then you can put this_light to kitchen in another automation or whatever.

It’s very powerful when you get the hang of it, I use a much more complicated version for my notification engine, you call script.notify with some parameters and it generates a message and you can choose whether it goes to text (and whom receives it), speech via TTS over the speakers, and an on screen message via persistent notification, or any combination of the three notification methods, which in turn are scripts that receive parameters from script.notify

If any of that made sense to you, the file in my repo that makes this happen is

link removed

You’ll notice that the meat-and-bones of script.notify is in an include, which is here…

link removed

Hope this helps.

1 Like

This is exactly what I was looking for, but the full files are no longer on guthub. Any chance to still see them?

They are there, I’ve just refactored so the url’s are different.

Notifications package…

link removed

Notification engine (include)…

link removed

Hope this helps :slight_smile:

1 Like

Thanks! This is pretty much what I was trying to figure out how to do…

1 Like