Command Line notify in automation

Hey, im trying to create a Command Line Notify, but im having some problems.

## automation.yaml
      - service: notify.test
        data:
          message: 'Test...'

## notify.yaml
  - name: test
    platform: command_line
    command: "/home/homeassistant/.homeassistant/scripts/test.sh"


## test.sh
#!/bin/sh
echo "Message: $1" >> /home/homeassistant/.homeassistant/scripts/testlog.log

## testlog.log
## It writes a line to the file but the message is empty...
Message: 

And home-assistant.log shows this error message:
ERROR (Thread-85) [homeassistant.components.notify.command_line] Command failed: /home/homeassistant/.homeassistant/scripts/test.sh

Anyone who knows what to do?

First check - is the script executable. If you do ls -l test.sh you should see something like:

-rwxr-xr-x 1 <more stuff here>

If not, do chmod a+rx test.sh (from the directory with test.sh) and try again.

The file is executable(owned by Homeassistant user, same as HASS process user and +x flag), otherwise the log file would not have been written.

Good point :wink:

Checking my own test command line script, the message is passed on STDIN, try:

#!/bin/bash
MESSAGE=$(cat)
echo "Message: $MESSAGE" >> /home/homeassistant/.homeassistant/scripts/testlog.log
1 Like