---
title: "Counter"
description: "Spook adds actions to create and delete counter helpers in Home Assistant from your automations and scripts, without a trip to the helper settings."
canonical_url: "https://spook.boo/counter"
---
# Counter

> Spook adds actions to create and delete counter helpers in Home Assistant from your automations and scripts, without a trip to the helper settings.

The counter helper in Home Assistant keeps count: it goes up or down by a step, can be reset, and can be kept between a minimum and a maximum. Handy for counting how often something happened.

Spook adds actions to create and delete these helpers from your automations and scripts.

## Actions

Spook adds two actions for counters. You find them wherever you add an action, marked with a 👻.

### Create a counter

Creates a new counter helper, the same as adding one on the helpers page.

Great for a script that needs to count something only for itself: it makes a counter, counts, and deletes it again when it is done. Or for setting up a new installation with the counters you always want, in one go.

**How to use it**

1. Open the automation or script that should create the counter, and select **Add action**.
2. Search for **create a counter**, and select **Counter: Create a counter 👻**.
3. Fill in **Name**, like `Coffee cups`.
4. Fill in whatever else you want to set: **Initial value**, **Minimum**, **Maximum**, **Step**, **Restore** or **Icon**. To pick the entity ID yourself, fill in **Counter entity ID**.
5. Select **Save**.

Just want to see it work? [Try this action](https://my.home-assistant.io/redirect/developer_call_service/?service=counter.create) opens it in your Home Assistant, ready to run once.

![The Actions tool with Create a counter 👻 picked and filled in with an example.](https://spook.boo/images/screenshots/en/light/action-counter-create.webp)

What **Try this action** opens, filled in with an example.

**Technical details**

| Action properties |
| --- |
| Action | Counter: Create a counter 👻 |
| Action name | `counter.create` |
| Action targets | No targets |
| Action response | Optional, the `entity_id` of the new counter |
| Spook's influence | Newly added action |
| Tools | [Try this action](https://my.home-assistant.io/redirect/developer_call_service/?service=counter.create) [![Open your Home Assistant instance and show the Actions tool with a specific action selected.](https://my.home-assistant.io/badges/developer_call_service.svg)](https://my.home-assistant.io/redirect/developer_call_service/?service=counter.create) |

| Action data parameters |
| --- |
| Attribute | Type | Required | Default / Example |
| `name` | string | Yes | `Coffee cups` |
| `counter_id` | string | No | `coffee_cups` |
| `initial` | integer | No | `0` |
| `minimum` | integer | No | `0` |
| `maximum` | integer | No | `10` |
| `step` | integer | No | `1` |
| `restore` | boolean | No | `true` |
| `icon` | string | No | `mdi:coffee` |

Without a `counter_id`, the entity ID follows the name, as it does in the UI, and gets a number at the end if that name is already taken. With a `counter_id`, you get exactly that entity ID or an error: one that is already taken is refused, and does not get a number at the end.

**Example actions in YAML**

Create a counter for coffee cups, and keep its entity ID for the next steps:

```yaml
action: counter.create
data:
  name: "Coffee cups"
  counter_id: coffee_cups
  maximum: 10
response_variable: created
```

The new counter's entity ID is then in `{{ created.entity_id }}`.

### Delete a counter

Deletes one or more counter helpers, disabled ones included.

The other half of [Create a counter](#create-a-counter): a script cleaning up the counter it made, or you clearing out the counters that piled up over the years. Everything in the list is checked first: if one of them cannot be deleted, none of them are.

**How to use it**

1. Open the automation or script that should delete the counter, and select **Add action**.
2. Search for **delete a counter**, and select **Counter: Delete a counter 👻**.
3. Under **Entity ID**, choose the counters to delete.
4. Select **Save**.

Just want to see it work? [Try this action](https://my.home-assistant.io/redirect/developer_call_service/?service=counter.delete) opens it in your Home Assistant, ready to run once. Mind you: running it deletes the counter for real.

![The Actions tool with Delete a counter 👻 picked and filled in with an example.](https://spook.boo/images/screenshots/en/light/action-counter-delete.webp)

What **Try this action** opens, filled in with an example.

**Technical details**

| Action properties |
| --- |
| Action | Counter: Delete a counter 👻 |
| Action name | `counter.delete` |
| Action targets | No targets |
| Action response | No response |
| Spook's influence | Newly added action |
| Tools | [Try this action](https://my.home-assistant.io/redirect/developer_call_service/?service=counter.delete) [![Open your Home Assistant instance and show the Actions tool with a specific action selected.](https://my.home-assistant.io/badges/developer_call_service.svg)](https://my.home-assistant.io/redirect/developer_call_service/?service=counter.delete) |

| Action data parameters |
| --- |
| Attribute | Type | Required | Default / Example |
| `entity_id` | string \| list of strings | Yes | `counter.coffee_cups` |

**Example actions in YAML**

Delete the coffee cups counter:

```yaml
action: counter.delete
data:
  entity_id: counter.coffee_cups
```

**Known limitations**

- Only counters made in the UI or with [Create a counter](#create-a-counter) can be deleted. Counters set up in YAML can only be removed from the YAML.

## Use cases

What people use this for:

- Let a script make the counter it needs, and clean it up again afterwards, so the helpers page only has counters you actually use.


## Sitemap

See the full [sitemap](https://spook.boo/sitemap.md) for all pages.
