Problem with Command line switch

I have a command line switch like this

switch:
  platform: command_line
  switches:
    monitor_maverick:
      command_on: /home/pi/maverick_start.sh
      command_off: /home/pi/maverick_stop.sh

“On” works as it should but Off gives me an error message:

Stop Maverick Reporter
Terminated
2017-06-19 21:18:19 ERROR (Thread-6) [homeassistant.components.switch.command_line] Command failed: /home/pi/maverick_stop.sh

It does however what it should (kill the process and writes to file) but the switch doesn´t change status due to the error.

Running maverick_stop.sh manually from bash works fine with the same user (pi).

script;

#!/bin/bash
# Script to start our application
echo "Stop Maverick Reporter"
echo "{\"Food\": 0, \"BBQ\": 0 }" >> /home/pi/Maverick/log.txt
sudo /usr/bin/pkill maverick > /dev/null 2>&1

Anyone got an idea to get HASS not to report ERROR and turn the switch?

I am surprised that the stop.sh works while giving an error. If it didn’t work, I would check that there is no white space behind the command.

what happens if you add this as the list line of the script:

exit 0

Unfortunately no change.
It still gives me the error in HASS

No space :frowning:

Can you change the maverick_stop.sh script to something that you know works like the script to start.sh? That way we can determine if its the script or HA.

edit: I altered one of my script to garbage and got the same error as you.

If I exclude the line that kills the process it works:
sudo /usr/bin/pkill maverick > /dev/null 2>&1

But I need to kill the process somehow…
Also, it works to run the .sh outside hass without error

Ok, I don’t know why that line doesn’t work. A similar problem here was solved by dropping the sudo.

Thanks for the suggestion but dropping sudo gives me error again

Stop Maverick Reporter
Terminated
2017-06-20 20:22:21 ERROR (Thread-8) [homeassistant.components.switch.command_line] Command failed: /home/pi/maverick_stop.sh