Shell_command returned state

Hello.
I am working with the “shell command” component service.
Obviously ALL commands has an output at least indicating if command was executed.
I want to call a service in HA depending on output of the shell command, but I cant figure how to do this.

I suppose that I missing something because its absoutely impossible that HA hasn`t an option to do this.

Execute an external command an make some thing or other depending on result of the execution of the command its a so basic thing that sure is more simple that I figure.

Please help me because I am searching a lot, and sure it has to be more simple that I figure.

1 Like

You should use command_line component (instead of shell_command), store its output as sensor state and have several automations triggering on state changes for the above sensor with conditions on the different output values of the sensor invoking different services for different values.

But I dont want a sensor, that execute a command every minute.

I want to execute something ( a shell script) once, and get the inmeditate result, to make one thing or another.

Its really simple.

1 Like

Maybe you can use this:

Publish the output of your shell scripts to mqtt and then automations can trigger on the payload.

2 Likes

Thanks VDRainer, but I cant wait 2 minutes to get the output and react to it: suppose you want to press a button to connect an alarm and need to wait 30, 45, 60 seconds or more to hear a sound if the alarm was really armed sucessfully.

Really I cant belive that Home Assistant have not this so simple feature:

  1. Execute an external command
  2. Get the output
  3. Make one thing or other depending on the result inside output.

I recognized that Home Assistant project surpised me gracefully due to their architectural model (python, modular design, async, massive components, releases speed, community, etc.)

But with lacks like this, I have to say that Home Assistant developers needs to revise soriously their base code.

If anyone reach this thread seaching for the same as me, I was solving this with:

  • modifying my script to “curl” to HA API to change a new sensor with state of the result of the original script (less elegant as possible).

The other solution: code your script/commandline as a new python component in HA.

1 Like

You might also use appdaemon, which would enable you to do whatever your script does in Python.

In fairness to HA, I have been watching the forums for over 2 years, and I can’t remember seeing anyone else asking for this, which is why I was following the thread to see if anyone had a solution. I guess HA is basically a home automation tool that expects to get its input from the real world, rather than computer scripts.

1 Like

Was just an example.
You don’t have to use crontab for starting your script.

@ VDRainer
Sorry. I understand now.
Yes. Seems a similar aproximation to my proposing “curl” to HA API (without mosquitto requirement). But I think both are complicated solution to solve a very simple question.
Thanks

Thank you gpbenton. I have been seen appdaemon but this seems similar complex to the second solution (code a new python component), for me, now.

I was trying to integrate a Verisure Alarm in Spain, that is incompatible with actual Verisure component (only for US).

I have created a bash script to interact with my alarm (“sure absolutely a real world”;), and I was trying to integrate this with HA with only configuration (sensor, service and automations). See Securitas Direct (Verisure EU) Custom Component [TESTERS WANTED]

But I have found this missed feature and I cant understand how something so simple cant be configured with a so great automation tool.

The two paradigms available for adding an external interface are what has been discussed - an HA component or through a standard protocol like MQTT or REST.

Using a bash script probably wouldn’t be generic enough for a program that was intended (at least originally) to be run on many different platforms. Using a bash script probably doesn’t fit into the hassio world either, as an addon with a bash script running would have to communicate outside its container.

So while I was surprised there was no solution when you asked about handling return codes, I can see why it has never been a priority to add such an interface.