Counter

The Counter integrationIntegrations connect and integrate Home Assistant with your devices, services, and more. [Learn more] lets you track how many times something has happened in Home Assistant. Use it when you want to count events over time, like how often a door opens, how many reminders have been sent, or how many times a routine has run.

Configuration

The preferred way to configure counter helpersA helper is a virtual entity you create inside Home Assistant. It is not backed by a physical device. Helpers store values, track state, or do calculations that your automations and dashboards need. [Learn more] is through the user interface. To add one, go to Settings > Devices & services > Helpers and select Create helper. Then, select Counter.

To add helpers from the user interface, default_config: must be present in your configuration.yamlThe configuration.yaml file is the main configuration file for Home Assistant. It lists the integrations to be loaded and their specific configurations. In some cases, the configuration needs to be edited manually directly in the configuration.yaml file. Most integrations can be configured in the UI. [Learn more] file. It is included by default unless you removed it. If you removed default_config:, add counter: to your configuration.yamlThe configuration.yaml file is the main configuration file for Home Assistant. It lists the integrations to be loaded and their specific configurations. In some cases, the configuration needs to be edited manually directly in the configuration.yaml file. Most integrations can be configured in the UI. [Learn more] file first.

Counters can also be configured in configuration.yamlThe configuration.yaml file is the main configuration file for Home Assistant. It lists the integrations to be loaded and their specific configurations. In some cases, the configuration needs to be edited manually directly in the configuration.yaml file. Most integrations can be configured in the UI. [Learn more]:

# Example configuration.yaml entry
counter:
  my_custom_counter:
    initial: 30
    step: 1

Configuration Variables

[alias] map Required

Alias for the counter. Multiple entries are allowed. alias should be replaced by the user for their actual value.

name string (Optional)

Friendly name of the counter.

initial integer (Optional, default: 0)

Initial value (0 or positive integer) when Home Assistant starts or the counter is reset.

restore boolean (Optional, default: true)

Try to restore the last known value when Home Assistant starts.

step integer (Optional, default: 1)

Incremental/step value for the counter.

minimum integer (Optional)

Minimum value the counter will have.

maximum integer (Optional)

Maximum value the counter will have.

icon icon (Optional)

Icon to display for the counter.

Pick an icon from Material Design Icons and prefix it with mdi:. For example, mdi:car, mdi:ambulance, or mdi:motorbike.

Restore state

This integration restores the previous counter value when Home Assistant starts as long as restore is set to true, which is the default. To disable this behavior, set restore to false.

If restore is set to true, the initial value is only used when no previous state is found or when the counter is reset.

List of triggers

The Counter integrationIntegrations connect and integrate Home Assistant with your devices, services, and more. [Learn more] provides the following triggers. Each link below opens a dedicated page with examples, fields, and a step-by-step UI walkthrough.

For an overview of every trigger across all integrations, see the triggers reference.

List of conditions

The Counter integrationIntegrations connect and integrate Home Assistant with your devices, services, and more. [Learn more] provides the following conditions. Each link below opens a dedicated page with examples, fields, and a step-by-step UI walkthrough.

  • Counter value (counter.is_value) Tests the value of one or more counters.

For an overview of every condition across all integrations, see the conditions reference.

Actions

Available actions: increment, decrement, reset, and set_value.

Action: Increment

The counter.increment action allows you to increment the counter with 1 or the given value for the steps.

Data attribute Optional Description
entity_id no Name of the entity to take action, for example, counter.my_custom_counter.

Action: Decrement

The counter.decrement action allows you to decrement the counter with 1 or the given value for the steps.

Data attribute Optional Description
entity_id no Name of the entity to take action, for example, counter.my_custom_counter.

Action: Reset

The counter.reset action allows you to reset the counter to its initial value.

Data attribute Optional Description
entity_id no Name of the entity to take action, for example, counter.my_custom_counter.

Action: Set value

The counter.set_value action allows you to set the counter to a specific value.

Data attribute Optional Description
entity_id no Name of the entity to take action, for example, counter.my_custom_counter.
value yes Set the counter to the given value.

Use the action

Go to Settings > Developer tools > Actions. Choose counter from the list of Domains, select the Actions, enter something like the sample below into the data field, and select Perform action.

{
  "entity_id": "counter.my_custom_counter"
}

Counter automation examples

If you use a counter helperA helper is a virtual entity you create inside Home Assistant. It is not backed by a physical device. Helpers store values, track state, or do calculations that your automations and dashboards need. [Learn more] in automations, create the helper separately before using these examples. Here are a few ways to use counter triggers, conditions, and actions together.

Tip

You don’t need to edit YAML to use these examples. Copy a YAML snippet from this page, open the automation editor in Home Assistant, and press Ctrl+V (or Cmd+V on Mac). Home Assistant automatically converts the pasted YAML into the visual editor format, whether it’s a full automation, a single trigger, a condition, or an action.

Automation: send a reminder when a counter reaches its limit

If you have created a counter helper to track missed chores, you can send a reminder as soon as it reaches its maximum and then reset it for the next cycle.

  • Trigger: Counter reached maximum
    • Target: Chore reminder counter
  • Action: Send a notification message
    • Target: My Device (notify.my_device)
  • Action: Reset counter
YAML example for a maximum reminder counter
AutomationAutomations in Home Assistant allow you to automatically respond to things that happen in and around your home. [Learn more]
alias: "Notify when the chore counter reaches its limit"
triggers:
  - trigger: counter.maximum_reached
    target:
      entity_id: counter.chore_reminders
actions:
  - action: notify.send_message
    target:
      entity_id: notify.my_device
    data:
      message: "The chore reminder counter reached its limit."
  - action: counter.reset
    target:
      entity_id: counter.chore_reminders

Automation: stop counting after the daily target is met

If you use a counter helper to track short exercise breaks, you can stop incrementing it once the counter reaches your daily target.

  • Trigger: Input button pressed
  • Condition: Counter value
    • Target: Exercise break counter
    • Threshold type: Below 5
  • Action: Increment counter
YAML example for capping a daily counter
AutomationAutomations in Home Assistant allow you to automatically respond to things that happen in and around your home. [Learn more]
alias: "Count exercise breaks until the daily target is met"
triggers:
  - trigger: state
    entity_id: input_button.exercise_break_done
conditions:
  - condition: counter.is_value
    target:
      entity_id: counter.exercise_breaks
    options:
      threshold:
        type: below
        value:
          number: 5
actions:
  - action: counter.increment
    target:
      entity_id: counter.exercise_breaks