Calling bash script (w/args) from command line notify

Does anyone have an example of running a bash script as a command line notifier?

I have a TTS engine that I call on a remote machine to do notifications. I figured I could do:

#!/bin/bash
while read -r; do
  curl "http://192.168.1.110/gir/speak.lhtml?t=$REPLY"
done

And in my config.yaml I have:

  - name: say
    platform: command_line
    command: "bash /home/pi/scripts/say.sh"

If I run the bash script directly, anything I type into STDIN is spoken correctly (as long as I escape it), but I get no response when I try to call the service directly from the HA services dev tool.

If I make the bash script simply call curl with an argument, it gets triggered. It just doesn’t appear to receive the “message” argument.

I’m not 100% sure that STDIN is making it to my script and I’m not sure how to tell.

Any chance someone can help me figure out the right format for that bash script so that it receives STDIN from command_line?

I would also like to know the answer to this as I am facing the exact same issue. I have a script for pico2wave to do voice notifications and it runs fine from the CLI but not when called by HASS.

Bumping this. I tried adding newlines (tried: \n, \n, \n\n, \n\r) with no love.

I see that there are two other threads that address this, but neither looks like they got command line notify to work. Anyone using it?

I also didn’t figure out (yet) to get to work command line notification, because it expect some data when call the notify, but I am wondering which data to provide. So instead I am using command line switch, less elegant but still work…

anyone ever figure tis out?

Got this working today thanks to this post.

My script now looks like this.

#!/bin/bash
foo=$(cat)
bar=${foo// /+}
/usr/bin/curl "http://ipadd:2323/?cmd=textToSpeech&text=$bar&password=pass" >> /dev/null

and notify looks like this,

notify:
  - name: fully
    platform: command_line
    command: "/root/tts.py"