Send notification if shell_command failed

Is there any way to get the return code from the shell_command, so that I can send a notification if it failed?

I don’t think you can get the return code, but an exception should be logged if anything goes wrong: source code.
I guess you could use that as a trigger for your automation: System Log – Conditional Messages.

You could use a command_line binary sensor, like (from the doc):

  - platform: command_line
    name: Printer
    command: 'ping -W 1 -c 1 > /dev/null 2>&1 && echo success || echo fail'
    device_class: connectivity
    payload_on: "success"
    payload_off: "fail"

Thanks a lot! For this use case I’ll use the solution @ondras12345 suggested, but the binary_sensor solution might be useful some other time as well.