brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: the stop action ends a Home Assistant run and can mark it as failed

Yaml
~/tips/tip-home-assistant-stop-action-error

- stop: "Nobody is home, nothing left to do"

stop ends the whole automation or script run, and error: true marks it as failed.

Stopping an automation halfway with a condition and some hope only goes so far. Home Assistant has a real stop action, and the optional error flag makes the run show up as failed, which is what you want when something went wrong.

The simplest form is a reason as text:

- stop: "Nobody is home, nothing left to do"

To mark the run as failed in the trace, add error:

- stop: "Well, that was unexpected!"
  error: true

stop is required, but the text can be empty, stop: "". For scripts that return data there is a third option, response_variable, which has to contain a mapping of keys and values.

A few caveats from the docs. Stop ends the whole run, not just the block it sits in. To stop only the steps after it in the current sequence, the docs point to a condition instead. Inside a parallel block, actions that already started still finish. You cannot combine response_variable with error. And the script has to be called directly from an automation to hand back a response, because script.turn_on does not wait for the script and returns nothing.

I’d use error: true inside an if or a choose branch for the can’t-happen case. A failed run is easier to spot in the traces than a quiet one.

Further reading: Stop, Home Assistant docs

More Yaml tips yamllint -f parsable config.yaml yamllint -d relaxed docker-compose.yml iif(condition, if_true, if_false, if_none) Sensor is available Today_at() makes time-of-day checks in Home Assistant templates easy All Yaml tips (10) All topics

Link