# Reason Codes and Lookups

Operators pick from lists when they give a reason for a stop or for scrap. This lesson shows how to add to those lists and
how to retire a reason you no longer want, for both downtime and scrap.

## Downtime Reasons

A downtime reason is a **state**. Each state has a state type that decides how it counts in OEE: **Running**, **Planned
Downtime** or **Unplanned Downtime**. Categories, such as *Mechanical*, group states for analysis.

### Add a Downtime Reason

1. Open **Configuration → Ops → Assets** and go to the **States** tab.
2. Add a new state. Give it a unique **State Name** and a **State Type**.
3. Choose a **Category** if you want one, and leave **Enabled** ticked.
4. Link the state to the assets where operators should see it.

![State configuration](https://docs.kanoa.ai/img/asset-config/state-config.png)

To link a state, select the assets in the asset tree, select the states, and click **Link**. Each link needs a numeric
state code. If the state comes from a PLC tag, the code must match the tag value.

:::note
Linking a state to an asset needs a state code that matches the machine. Ask your engineer for the right code before you
link states on a machine that sets its state from a PLC tag.
:::

{/*
TODO: confirm on a gateway which security function the States tab needs (Configure Assets is likely, as the other asset
views use it), and the exact names of the tabs under Configuration → Ops → Assets. The Developer Training lesson uses
States, State Editor and Asset Links.
*/}

### Retire a Downtime Reason

Untick **Enabled** to take a state out of use, or unlink it from the assets that shouldn't use it. If a state has event
history, Kanoa won't remove its link. It disables the link instead, so past downtime keeps its reason.

:::warning
Retiring a reason changes the list for every operator on the linked assets. Kanoa's built-in states, such as **Running**,
**Idle**, **Faulted** and **Offline**, are reserved. Don't retire them.
:::

::embed-section{src="../../configuration/states.md#configuring-states" collapsed="true" summary="Reference Materials: Configuring States - Add, edit, link and unlink states."}

## Scrap Reasons

A scrap reason is an **item state**. It says why a waste count happened, such as *Damaged Parts* or *Bad Coating*.

1. Open **Configuration → Ops → Item States**.
2. Add the item state under a category, such as *Quality\Handling*.
3. Associate it with the **Waste** counter type, so it appears as a scrap reason.
4. Open the **Item State Links** tab and link the reason, or its category, to the assets that should offer it.
5. Save.

![Item state configuration](https://docs.kanoa.ai/img/asset-operation/itemStatesConfig.png)

Item states need the **Configure Items** function. Linking them to assets needs **Configure Assets**.

{/*
TODO: confirm on a gateway how to retire an item state. The docs describe adding and linking item states but don't
mention an Enabled option or unlinking. Confirm whether unlinking from the Item State Links tab is the way to hide a
reason from operators.
*/}

::embed-section{src="../../kanoa-ops/items/item-states.md" collapsed="true" summary="Reference Materials: Item States - Classify scrap reasons with categories, counter types and links."}

## Check Your Understanding

1. What is a downtime reason called in Kanoa, and what is a scrap reason called?
2. A state has past downtime recorded against it, and you unlink it. What happens?
3. Which function do you need to add a new scrap reason?

<details>
<summary>Answers</summary>

1. A downtime reason is a **state**. A scrap reason is an **item state**.
2. Kanoa won't remove the link. It disables it, so past downtime keeps its reason.
3. **Configure Items**.

</details>
