# Automations

Source: https://docs.lightair.app/desktop/control-and-automate/automations

> Make Lightair act on its own with automations, from a trigger, conditions and steps, with templates, ready-made recipes, Streamer.bot import and smart lights.

In short:
- An automation is a trigger (**When**), optional conditions, and steps (**Do**). Build them in **Window › Automations**.
- **New** starts from a recipe, such as a raid welcome or a death counter, or imports actions from Streamer.bot.
- Text in a step can use templates: `{{ name }}`, `{{ message }}`, `{{ amount }}`, `{{ vars.deaths }}`.
- Steps can switch scenes, show objects, go live, talk in chat, speak, play sounds, set Philips Hue and Key Light lights and press VTube Studio hotkeys.

In the app: Window › Automations; Settings › Connections › Devices

Automations do things for you while you stream: thank raiders, read donations aloud, run chat
commands, show an overlay on a follow, switch scenes from a game controller. Each one is a
trigger, the conditions it must meet, and the steps it runs.

## Make an automation

1. Open **Window › Automations**.
2. Click **New** and choose a recipe, or **Blank** to start from nothing.
3. Give it a **Name**.
4. Under **When**, choose its trigger and fill in the fields that appear (a command's name, a
   timer's minutes, a hotkey's keys).
5. Under **Do**, click **Add step** and choose what it does. Repeat for each step; they run in
   order.
6. Click **Run now** to try it.

Changes are saved as you make them. The switch beside each automation in the list turns it on or
off. The buttons beside **Run now** copy its web address, **Duplicate** it and **Delete** it.

**Latest runs**, at the bottom, shows when it ran and what each step did, or why it stopped.

### Recipes

| Recipe | What it does |
|---|---|
| **!so shoutout** | Moderators type `!so @name` to point chat at another streamer. |
| **Death counter** | `!death` adds one (moderators), `!deaths` says how many. |
| **Timed message** | Posts a message every 15 minutes while chat is active. |
| **Read donations aloud** | Says the message of every donation, cheer or Super Chat on stream. |
| **Raid welcome** | Thanks raiders in chat and says who raided. |
| **First-time chatter greeting** | Welcomes people the first time they chat. |
| **!points** | Tells people how many points they have. |
| **Giveaway** | `!join` enters, moderators `!draw` a winner. |
| **!lurk** | Thanks people for lurking. |
| **Follow → show an object** | Shows a scene object for a few seconds on every follow. |
| **Blank** | Starts from nothing. |

A recipe is an ordinary automation once made: change anything in it.

## Triggers

| Trigger | Runs when |
|---|---|
| **Follows**, **Subscriptions**, **Donations and cheers**, **Raids** | That alert comes in, from any platform. **At least** sets a minimum amount (or number of raiders). |
| **Channel-points redemptions (Twitch)** | A viewer redeems a channel-points reward. |
| **Any alert** | Any of the alerts above. |
| **A chat command** | Someone types the command, such as `!lurk`. A second menu sets who may use it: **Anyone**, **Subscribers and up**, **VIPs and up**, **Moderators and up** or **Only you**. |
| **A chat message** | A message arrives, or one containing the text you give. |
| **A first-time chatter** | Someone chats for the first time. |
| **A timer** | Every so many minutes, optionally only after a number of chat messages. |
| **The stream starts**, **The stream stops**, **Recording starts**, **Recording stops** | That happens. |
| **Lightair starts** | Lightair opens. |
| **A hotkey (any app)** | You press its keys in any app, written like `cmd-alt-1` or `ctrl-shift-f5`. |
| **A file changes** | Another app saves the file (its full path; `~/` for your home folder). |
| **A MIDI pad or key**, **A MIDI knob or fader** | A MIDI control is used. Set which note or control (−1 for any) and channel (0 for any). |
| **A game controller button** | A button is pressed: **South**, **East**, **Start**, **DPadUp**, **LeftTrigger** and so on, or any button when left empty. |
| **A phrase you say** | Your microphone hears the phrase, recognised on this Mac. macOS only. |
| **Only by hand** | Run now, another automation, a Stream Deck key, the remote API or its web address runs it. |

Alert triggers also run for the test events you send from Lightair, so you can try them before
going live.

### Cooldowns and queues

- **Cooldown (s)**: seconds before it can run again, for anyone.
- **Per person (s)**: seconds before the same viewer can set it off again.
- **Queue**: automations with the same queue name wait for each other and run one at a time.
  Without one, an automation runs at once, alongside anything else.

## Steps

| Step | What it does |
|---|---|
| **Send a chat message** | Posts in chat, on the platform the trigger came from. |
| **Say something on stream** | Speaks the text on the Voice track ([Voices](/desktop/reference/settings#voices)). |
| **Play a sound** | Plays a sound file on stream. |
| **Wait** | Waits a number of seconds. |
| **Switch scene** | Puts a scene on air. |
| **Show or hide an object** | Shows or hides an object by name. |
| **Start recording**, **Save a clip** | Start recording, or save the last moments. |
| **Go live (every destination)**, **End the stream (every destination)** | Start or end the stream. |
| **Start one destination**, **Stop one destination** | Start or stop one destination by name. |
| **Change the stream's title or category** | Changes them on the platform. |
| **Change a variable** | Sets, adds to or clears a variable, for everyone or per viewer. |
| **Give or take points** | Changes the viewer's points (a negative number takes them). |
| **VTube Studio hotkey** | Presses a VTube Studio hotkey by name. |
| **Elgato Key Light** | Turns a Key Light on or off and sets its brightness and colour temperature. |
| **Philips Hue light** | Sets a Hue light or room: on or off, brightness, colour. |
| **Web request** | Sends a GET or POST to an address. Its answer is `{{ http }}` afterwards. |
| **JavaScript** | Runs a short script with the run's context as `ctx`. What it returns is `{{ script.… }}` afterwards; returning `{stop: true}` ends the run. Ten seconds at most. |
| **Twitch: run an ad**, **start a poll**, **start a prediction**, **raid a channel**, **shout out a channel**, **make a clip**, **add a stream marker** | Act on your Twitch channel. |
| **If… (then, otherwise)** | Runs **Then** when all its conditions hold, **Otherwise** when not. |
| **One at random** | Runs one of its choices, picked at random. **Add choice** adds another. |
| **Stop** | Ends the run here. |

The steps that change a platform (the title, Twitch's steps) use the account signed in under
**Settings › Connections**, **Official sign-in**.

Each step shows its main field (the text, the seconds, the address). To change everything else,
such as a scene's name or a light's colour, click **Edit everything as JSON (conditions, step
details)**. Plugins that are running can add steps of their own to the **Add step** menu.

A step inside an **If…** or **One at random** can be moved to another list with its move button.

### Conditions

An **If…** step lists conditions under **When all of these hold**: a left side, how to compare,
and a right side. Both sides can use templates. The comparisons are **is**, **is not**, **>**,
**>=**, **<**, **<=**, **contains**, **starts with** and **chance** (the left side is a
percentage, so `25` runs a quarter of the time). Text compares without regard to capitals.

Conditions for the whole automation (shown as **Only if:**) are set in the JSON, as `conditions`.

## Templates

Text in any step can include values in double braces, filled in when the step runs. A value
that isn't there is left empty.

| Template | Is |
|---|---|
| `{{ name }}` | Who set it off |
| `{{ message }}` | Their message |
| `{{ amount }}` | The amount, as shown (a donation's money, a raid's viewers) |
| `{{ platform }}` | Where it came from |
| `{{ arg }}`, `{{ args.0 }}` | A command's words after the command: all of them, or one by position |
| `{{ target }}` | A command's first word without the `@` |
| `{{ user.login }}` | The viewer's login name |
| `{{ vars.deaths }}` | A variable shared by everyone |
| `{{ user_vars.entered }}` | The viewer's own variable |
| `{{ viewer.points }}` | The viewer's points |
| `{{ file.text }}` | What a changed file now holds (**A file changes**) |
| `{{ random 1 6 }}` | A random whole number from 1 to 6 |

Filters change a value: `{{ name | upper }}`, `| lower`, `| trim`, `| strip_at` (drops a leading
`@`) and `| default: someone` (used when the value is empty).

## Import from Streamer.bot

1. In Streamer.bot, select the actions, right-click and choose **Export**, then copy the export
   string.
2. In Lightair, click **New** and choose **Import from Streamer.bot (copy its export first)**.

Each action becomes an automation with the closest steps Lightair has: chat messages, waits,
variables, sounds, speech, scenes, showing and hiding sources, running other actions, web
requests, If/Else and random groups. Lightair then lists what it couldn't bring over. C# code is
kept as a comment in a **JavaScript** step for you to rewrite.

## Lights, VTube Studio and heart rate

- **Philips Hue.** In **Settings › Connections**, under **Devices**, click **Pair** next to
  **Philips Hue**, then press the button on the bridge. If Lightair can't find the bridge, copy its
  address from the Hue app and click **Paste address**. Then use the **Philips Hue light** step,
  naming a light or a room.
- **Elgato Key Light.** No pairing: the **Elgato Key Light** step names the light's address on
  your network (in its JSON), with on, brightness and a colour temperature from 2900 to 7000 K.
  On a Mac, allow **Local network** when macOS asks.
- **VTube Studio.** In VTube Studio, turn on its API (**Settings › Start API**). The first time a
  **VTube Studio hotkey** step runs, VTube Studio asks whether to allow Lightair: choose
  **Allow**.
- **Heart rate (Pulsoid).** In **Settings › Connections**, under **Devices**, click **Paste token**
  next to **Heart rate (Pulsoid)** after copying a token from pulsoid.net › Keys. Automations read
  the heart rate as `{{ vars.heart_rate }}`.

## Run automations from elsewhere

An automation can be run by a [Stream Deck](/desktop/control-and-automate/stream-deck) key
(**Run automation**), by its web address (the link button), by another automation (a `run` step,
added in the JSON), or through the remote API. Its trigger doesn't have to be **Only by hand** for
that.

## Related

- [Global shortcuts](/desktop/control-and-automate/shortcuts)
- [Chat](/desktop/chat-and-widgets/chat)
- [Widgets](/desktop/chat-and-widgets/widgets)
