How do I use a service

So I’ve been reading a bunch and doing a bunch, but I’m still missing something. So if I go into developer tools and set up a service call, and call it successfully, what do I do with that yaml? How do I USE or REFERENCE a service? All I can find just shows running it in the Developer Tools. Seems like I should be able to give it a name and invoke it from something.

In an automation:

  action:
    - service: switch.toggle
      target:
        entity_id: switch.mechanical_bench

In a script:

  sequence:
    - service: switch.toggle
      target:
        entity_id: switch.mechanical_bench

Thanks so much. It is so simple and yet I couldn’t find it. So apparently it is sort of an “in-line” kind of thing and not something that can be named and reused. Although I guess once it is in a script or automation, then you can used that named thingee.

If you have a bunch of services you use regularly in different places, put the sequence in a script. You can pass variables to scripts.

All of that script syntax can be used in automations too (automations are just scripts with triggers).

For example you could create a script to make announcements and pass the message and where to announce it to to the script.