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