# Timing

When creating automation scripts, you often need to wait for a train to arrive at a certain position or to let it drive for a specific amount of time. Model Train Script provides actions for both.

## Wait <a href="#wait" id="wait"></a>

Pauses script execution for a configured amount of time.

| Setting          | Description                                                                                                                                                               |
| ---------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **Time**         | The wait duration in seconds.                                                                                                                                             |
| **Random**       | When enabled, the actual wait time is randomly chosen between a minimum and maximum value. This adds variation to your scripts — for example, random station dwell times. |
| **Minimum time** | The shortest possible wait duration (only available when random is enabled).                                                                                              |

{% hint style="warning" %}
While this action is sometimes necessary, try to minimise its use and rely on sensors instead. Due to the mechanical nature of model trains, you cannot guarantee the precise position of a train after a timed wait. Use "wait for condition" whenever possible.
{% endhint %}

## Wait for condition <a href="#wait-for-feedback-module" id="wait-for-feedback-module"></a>

Pauses execution until a specified condition on your layout becomes true. This is the most reliable way to synchronise your script with the physical state of the layout.

| Setting       | Description                                                                                                                                                                                |
| ------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| **Condition** | The condition to wait for. Can be based on accessories, feedback sensors, vehicle state, flags, variables, or camera detection.                                                            |
| **Timeout**   | Optional confirmation time in milliseconds. When set, the condition must remain true for this duration. If the condition goes false during the timeout, the action resets and waits again. |

The condition is evaluated in an event-driven way — it does not poll. As soon as the layout state changes, the condition is re-evaluated.

{% hint style="info" %}
The **timeout** setting is useful for filtering transient sensor readings. For example, if a feedback sensor briefly activates due to electrical noise, the timeout ensures the action only continues when the sensor stays active for the configured duration.
{% endhint %}

### Condition types

Conditions used in "wait for condition" — and also in [section](/docs/manual/automation/scripts/section.md) and [action](/docs/manual/automation/scripts/action.md) execute conditions — can be based on:

| Type                | Description                                                                                        |
| ------------------- | -------------------------------------------------------------------------------------------------- |
| **Accessory**       | An accessory matches a specific state (e.g., a turnout is thrown).                                 |
| **Feedback sensor** | A sensor is active or inactive, optionally occupied by a specific vehicle or the selected vehicle. |
| **Vehicle**         | A vehicle's speed, direction, function state, or profile matches an expected value.                |
| **Flag**            | A [flag](/docs/manual/automation/flags.md) is enabled or disabled.                                 |
| **Variable**        | A [variable](/docs/manual/automation/variables.md) equals a specific value.                        |
| **Camera**          | A [camera](/docs/manual/automation/cameras.md) detects a vehicle at a specific detection point.    |

All condition types support **negation** — you can check that a condition is *not* true.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://modeltrainscript.gitbook.io/docs/manual/automation/scripts/action/timing.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
