Counters are where production counts enter Kanoa. Every count event (infeed, outfeed, waste, or anything else you want to count) is stored against a counter on an asset. In this section you'll look at the counters Kanoa created for the CoreForge lines, then add one of your own.

::embed-section{src="../../../kanoa-ops/assets/counters.md" collapsed="true" summary="Reference Materials: Counters - The counters on an asset and how to add more."}

When you checked **OEE Enabled** on `Machine 1`, `Spray Line 1` and `Manual Pack 1` in [Configure Assets](./1-configure-assets.md), Kanoa created an assetOEE tag for each one. As that tag starts up it creates three counters on the asset:

| Counter | What it counts | Used for |
|---|---|---|
| `infeed` | Parts going into the asset | Performance, and quality when compared with outfeed |
| `outfeed` | Good parts coming out | Performance and quality |
| `waste` | Parts scrapped on the asset | Quality, and waste by reason (next lesson) |

The counter IDs are stored in the assetOEE tag's **Configuration** folder (`infeedCounterId`, `outfeedCounterId`, `wasteCounterId`). The **Infeed Count**, **Outfeed Count** and **Waste Count** tags in its **Inputs** folder, which you connected to the simulator in [Connect To Your Tags](./7-connect-tags.md), record their counts against these three counters. You don't need to create or connect anything else for OEE.

![The Counters tab in Asset Configuration, listing the infeed, outfeed and waste counters on an asset along with two general counters, and the Counter Editor adding a general counter named Bottle Tops with Tag ticked](https://kanoa-software.netlify.app/img/asset-config/counters.png)

:::action[Review the counters on Machine 1]

1. Open **Configuration → Ops → Assets** and select `Machine 1` in the asset tree.
2. Open the **Counters** tab.
3. Confirm `Machine 1` has an `infeed`, an `outfeed` and a `waste` counter, and note each one's **Counter Id**.
4. In Ignition Designer, open `Machine 1`'s assetOEE tag in the `Kanoa` tag provider, expand its **Configuration** folder, and check that `infeedCounterId`, `outfeedCounterId` and `wasteCounterId` match the IDs on the Counters tab.

:::

## Adding Counters

You can also add counters from the **Counters** tab. Use an extra infeed, outfeed or waste counter when an asset has more than one count source of that kind. Use a **general** counter for anything worth counting that isn't part of OEE: tool changes, label rolls, bottle caps, rejects from an inspection station. General counts are stored and reported like any other count, but they never change the asset's OEE.

When you add a counter with **Tag** ticked, Kanoa creates a counter tag for it in a `counters` folder under the asset's tags, ready to connect to a PLC or other source. A counter doesn't need a tag, though: counts can also be recorded with [`system.kanoa.event.addCounterEvent()`](../../../systemFunctions/event/addCounterEvent), from an operator screen, a gateway script or a web service.

:::action[Add a general counter to Machine 1]

1. On the **Counters** tab for `Machine 1`, click **+** (**Add a new counter**).
2. In the **Counter Editor**, set **Type** to `general` and **Name** to `Tool Changes`.
3. Tick **Tag**, then click **Save**.
4. Confirm `Tool Changes` appears in the list with type `general` and a tag path ending in `/counters/Tool Changes`.
5. In Ignition Designer, find the new tag in the `counters` folder under `Machine 1`'s tags.

:::

:::action[Record a count from a script]

Run this in the Ignition Designer Script Console (**Tools → Script Console**) to record one tool change against the new counter, without using its tag.

<details>
<summary>Show the recordToolChange script</summary>

```python title="recordToolChange.py"
# Record a count against the Tool Changes counter on Machine 1.
# Counters don't need a tag: anything that can run a script can record a count.
# Running this again records another count.

ASSET = 'CoreForge\\Philadelphia\\Machining\\Machine 1'
COUNTER = 'Tool Changes'
COUNT = 1.0

userId = system.kanoa.security.getIDPUserId({'userName': 'SYSTEM'})
counterId = system.kanoa.utilities.getFieldValue('counterId',
	system.kanoa.asset.getCounter({'assetPath': ASSET, 'counterName': COUNTER}))

if counterId is None:
	print 'No %s counter found on %s. Add it on the Counters tab first.' % (COUNTER, ASSET)
else:
	print 'Recording %g against %s (counterId %s)...' % (COUNT, COUNTER, counterId)
	eventId, msg = system.kanoa.event.addCounterEvent({
		'counterId': counterId,
		'deltaValue': COUNT,
		'itemId': None,
		'itemStateId': None,
		'workOrderId': None,
		'tStamp': system.date.now(),
	}, userId)
	if msg:
		print 'Failed: %s' % msg
	else:
		print 'Done. Counter event %s recorded.' % eventId
```
</details>
:::

:::check

Copy this script into the Ignition Designer Script Console (**Tools → Script Console**) and run it. It checks that each line has its infeed, outfeed and waste counters, that `Machine 1` has a general `Tool Changes` counter with a tag, and that a count has been recorded against it in the last 7 days. Each check prints PASS or FAIL with what to fix. It doesn't change anything.

<details>
<summary>Show the check script</summary>

::check-script{src="ops/01-base-configuration/8-counters.py" title="checkLesson-counters.py"}

</details>

:::
