---
title: "Threshold"
description: "Spook adds an action to the threshold helper that changes its lower limit, upper limit and hysteresis, so an automation can move the limits without a trip to the helper's options."
canonical_url: "https://spook.boo/threshold"
---
# Threshold

> Spook adds an action to the threshold helper that changes its lower limit, upper limit and hysteresis, so an automation can move the limits without a trip to the helper's options.

The threshold helper watches a sensor and turns on when its value crosses a limit: above an upper limit, below a lower limit, or between the two. Humidity in the bathroom above 70%, the freezer warmer than -15 °C, a battery below 20%.

The limits are set in the helper's options, and only there. An automation cannot move them: not a higher humidity limit at night when the shower runs anyway, not a limit you set with a slider on your dashboard. People have asked for that since 2017.

Spook adds an action for that: set the limits.

## Actions

Spook adds one action to the threshold integration. You find it wherever you add an action, marked with a 👻.

### Set limits

Changes the lower limit, the upper limit or the hysteresis of one or more threshold helpers, like the options of the helper do. What you leave out stays as it is, the sensor it watches too.

The change goes through the helper's own options, so Home Assistant checks it the same way it checks what you fill in there. Then Home Assistant reloads the helper, as it does after you save its options. The action returns once the helper is reloaded, so the next step of your automation already sees the new limits. A helper that already has the limits you give is left alone, without a reload.

A threshold can have only a lower limit, only an upper limit, or both. To take one away, give it `null` in YAML: `lower: null` leaves the helper with only its upper limit. Taking away the only limit a helper has is refused: a threshold without any limit has nothing to compare with.

Every entity is checked before the first helper changes. An entity that is not a threshold helper, or one set up in YAML, is refused with an error, and nothing changes. The helpers change one at a time, in the order you give them. When Home Assistant refuses the new limits of one, like taking away its only limit, the action stops with an error that names that helper. The helpers before it in the list did change; the ones after it did not.

Run by hand, the action takes an administrator, like the options of a helper do. Your automations can always run it. So can your scripts, unless a user who is not an administrator starts one.

**How to use it**

1. Open the automation or script that should change the limits, and select **Add action**.
2. Search for **set limits**, and select **Threshold: Set limits 👻**.
3. Choose the threshold helpers.
4. Turn on the limits you want to change, and fill in the new values.
5. Select **Save**.

To take a limit away, switch the action to YAML with the three dots menu, and set that limit to `null`.

**Technical details**

| Action properties |
| --- |
| Action | Threshold: Set limits 👻 |
| Action name | `threshold.set_limits` |
| Action targets | No targets |
| Action response | No |
| Spook's influence | Newly added action |
| Tools | [Try this action](https://my.home-assistant.io/redirect/developer_call_service/?service=threshold.set_limits) [![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=threshold.set_limits) |

| Action data parameters |
| --- |
| Attribute | Type | Required | Default / Example |
| `entity_id` | string or list | Yes | `binary_sensor.bathroom_humid` |
| `lower` | float or `null` | No | `40` |
| `upper` | float or `null` | No | `70` |
| `hysteresis` | float | No | `2` |

Give at least one of `lower`, `upper` and `hysteresis`. `null` takes a limit away. The hysteresis cannot be taken away; set it to `0` for none.

**Example actions in YAML**

Raise the upper limit of a threshold helper:

```yaml
action: threshold.set_limits
data:
  entity_id: binary_sensor.bathroom_humid
  upper: 75
```

Take the lower limit away, so only the upper limit is left:

```yaml
action: threshold.set_limits
data:
  entity_id: binary_sensor.bathroom_humid
  lower: null
```

A template works too. One that renders `none` takes the limit away:

```yaml
action: threshold.set_limits
data:
  entity_id: binary_sensor.bathroom_humid
  upper: "{{ states('input_number.bathroom_humidity_limit') | float }}"
```

The bathroom fan turns on above 65% humidity. At night, after the evening showers, the bathroom is humid for hours anyway, and the fan keeps everybody awake. A higher limit from 22:00, and back at 07:00:

```yaml
alias: Bathroom humidity limit for the night
triggers:
  - trigger: time
    at: "22:00:00"
    id: night
  - trigger: time
    at: "07:00:00"
    id: day
actions:
  - action: threshold.set_limits
    data:
      entity_id: binary_sensor.bathroom_humid
      upper: "{{ 80 if trigger.id == 'night' else 65 }}"
```

The limit set with a number helper on your dashboard. The automation waits until the number has stayed put for five seconds, so somebody tapping the plus a few times reloads the helper once, not five times:

```yaml
alias: Bathroom humidity limit from the dashboard
triggers:
  - trigger: state
    entity_id: input_number.bathroom_humidity_limit
    for: "00:00:05"
actions:
  - action: threshold.set_limits
    data:
      entity_id: binary_sensor.bathroom_humid
      upper: "{{ trigger.to_state.state | float }}"
```

**Known limitations**

- Every change reloads the helper. Do not drive the limits from something that changes every few seconds, like the temperature outside: change them when it matters, like at a set time or when a mode changes.
- While the helper reloads, its state is `unavailable` for a moment. An automation triggered on it turning `on` fires again when it comes back on. Add `from: "off"` to that trigger to skip the reload.
- A reload starts the helper fresh: it forgets whether it was on. With a hysteresis, a value within the hysteresis of a limit no longer remembers which side it came from. A helper with one limit starts off there; one with both limits starts on.
- When Home Assistant refuses the change of one helper, the helpers before it in the list keep their new limits.
- Threshold helpers set up in YAML are refused. Their limits are in your configuration: change them there.


## Sitemap

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