---
title: "Count"
description: "The count helper counts the entities that match a rule, picked by hand or by area, floor, label, device, domain or device class. A sensor with the number, and a binary sensor for any."
canonical_url: "https://spook.boo/count"
---
# Count

> The count helper counts the entities that match a rule, picked by hand or by area, floor, label, device, domain or device class. A sensor with the number, and a binary sensor for any.

The count helper gives you one number: how many lights are on, how many windows are open, how many things are unavailable. It counts the entities you select that match a rule, and keeps up as they change.

What to count, you pick the way you pick the target of an action: entities by hand, or everything on a device, in an area, on a floor or with a label. Narrow that down by domain or device class, or count a domain in the whole home. Move a lamp to another room, or give a sensor a label, and the count follows right away.

## Creating a count helper

Add one directly to your own instance by selecting the My Home Assistant button below:

[![Open your Home Assistant instance and start setting up a new integration.](https://my.home-assistant.io/badges/config_flow_start.svg)](https://my.home-assistant.io/redirect/config_flow_start/?domain=spook_count)

Or add one by hand:

1. Go to **Settings** > **Devices & services**, and select the **Helpers** tab.
2. Select **+ Create helper**.
3. Search for **count**, and select **Count 👻**.

![The Create helper dialog, searched for the ghost, listing the helpers Spook adds.](https://spook.boo/images/screenshots/en/light/helpers-ghost-search.webp)

4. Give it a **Name**, like "Lights on".
5. Under **What to count**, pick entities, devices, areas, floors or labels. Or leave it empty, and pick a domain in the next step to count it in the whole home.
6. Optionally, narrow it down under **Only these domains**, like `light`, and **Only these device classes**, like `window`.
7. Under **Counts when it**, pick the rule:
   - **Is one of these states**: fill in the states under **States**, like `on` or `open`.
   - **Is above a number** or **Is below a number**: fill in the **Number**. A state that is not a number, like `unavailable`, is never above or below anything.
   - **Is unavailable**: counts the entities that are `unavailable`.

![The count helper dialog, filled in to count the lights that are on in the living room.](https://spook.boo/images/screenshots/en/light/helper-count.webp)

8. Select **Submit**. Done! 🎉

Changed your mind later? Open the helper from the **Helpers** tab, and change what it counts and when in its options.

## A few to start with

| You want | What to count | Only these domains | Only these device classes | Counts when it |
| --- | --- | --- | --- | --- |
| Lights on in the kitchen | Kitchen (area) | `light` |  | Is one of these states: `on` |
| Windows open |  | `binary_sensor` | `window` | Is one of these states: `on` |
| Batteries low |  | `sensor` | `battery` | Is below a number: `20` |
| Flaky things unavailable | A label |  |  | Is unavailable |
| People home |  | `person` |  | Is one of these states: `home` |

## How it works

You get two entities, both with the name you gave the helper:

- A **sensor** with the count. It keeps long-term statistics, so you can see how many lights were on last week.
- A **binary sensor** that is on when at least one entity counts: any window open.

Both keep up as things change. An entity changing state, getting a label, moving to another area or another floor, or being added or removed: the count follows right away. Only the entity that changed is looked at, so a count over a big home stays cheap.

- **Restarts:** while Home Assistant starts, entities come in one by one. The helper waits until Home Assistant has started, and is unknown until then. That way, a restart does not count up from zero, and does not turn "any" from off to on as if a window was opened just now. It does go from unknown to on when a window is open: an automation that triggers on `to: "on"` alone runs then. Add `from: "off"` to the trigger to only act on a window that opens.
- **Unavailable:** an entity that is unavailable does not count as on, open, above or below. It drops out of the count, and comes back in when it is back. To count those, make a helper with **Is unavailable**.
- **Renames:** an entity you picked by hand that gets a new entity ID stays picked.

## What counts, and what does not

The selection means the same as the target of an action. On top of that:

- **Excluded** never counts. Use **Exclude target** under **What to count** to leave out an entity, a device, an area or a label, like the one lamp in the living room you never want to see in the count. Exclude a group, and its members stay out too.
- **Picked by hand** always counts, hidden or not. You picked it on purpose.
- **Found through a device, area, floor, label or domain**, hidden entities are left out, and so are config and diagnostic entities. The same rule Home Assistant uses when an action targets an area.
- **Disabled entities** never count. They have no state.
- **Groups never count twice.** A group never counts as itself, only its members do. A group is an old style group, a group from the group helper, a Hue group, or a group an integration like ZHA or MQTT makes. A sensor that only lists its inputs, like min/max, is no group: it counts as itself.
  - A group stands for its members, whether you picked it by hand or it was found through an area, label or domain. Its members count in its place, even when the group helper hides them, and the count follows them as members join or leave.
- **Counts** never count: not the helper itself, and not another count. A count of sensors above 0 skips every count sensor, so two counts never chase each other.

## Attributes

| Attribute | Description |
| --- | --- |
| `entities` | The entities that count right now, on both the sensor and the binary sensor. Not kept in history, only the count. |

![The details of a count sensor for the lights on in the living room: a count of 3, and the three lights that are on under Entities.](https://spook.boo/images/screenshots/en/light/count-sensor.webp)

The lights that are on in the living room: how many, and which.


## Sitemap

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