Executing a script in Automations

So, I’m trying to get a Xiaomi Smart Switch to work with my Home Assistant configuration and, I get as far as turning switches/lights on or off, using automations linked to the button, but I can’t get it working with the script I use to turn my TV On/Off via my Broadlink RM Pro.

- alias: Turn On Xiaomi Switch 2
  trigger:
    platform: state
    entity_id: light.light_8
    to: 'off'
  action:
    service: switch.turn_on
    entity_id: switch.xiaomi_smart_plug_2

The above code works turning my smart plug on, so conceptually, it works.

I’ve tried just substituting the entity_id with my script entity, but I imagine I need to change the service (under action) as well. Any help on how to get this working?

See this doc page for details on how to invoke scripts.

You just need to use script.turn_on as the service name:

action:
  service: script.turn_on
  entity_id: script.NAME_OF_YOUR_SCRIPT

Awesome, now it works. Thank you so much.

I feel the simplest way to call a script is to … call the script.

  action:
    service: script.whatever

If the script accepts parameters, you just list them under the data section:

  action:
    service: script.whatever
    data:
       message: 'Hello world!'
       priority: 5