Threshold
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
- Open the automation or script that should change the limits, and select Add action.
- Search for set limits, and select Threshold: Set limits 👻.
- Choose the threshold helpers.
- Turn on the limits you want to change, and fill in the new values.
- Select Save.
To take a limit away, switch the action to YAML with the three dots menu, and set that limit to null.
| 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 |
| 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.
Raise the upper limit of a threshold helper:
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:
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:
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:
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:
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 }}"
- 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
unavailablefor a moment. An automation triggered on it turningonfires again when it comes back on. Addfrom: "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.
Missing something here?
An action, an entity or a repair this integration should have? Say so. Stuck, or found a bug? There is help.
Z-Wave
Spook adds actions to Z-Wave that rebuild the routes of a device or of the whole network, and re-interview devices, so an automation can do the upkeep the Z-Wave pages ask you to do by hand.
Times of the Day
Spook adds an action to the Times of the Day helper that changes when it turns on and off, so an automation can move the times without a trip to the helper's options.
