command_line notify tts (or any other) command:

Continuing the discussion from Command line notify espeak command:

I have to agree here. command_line does not seem to work at all for any command.

I have


#################################################################
## Notifiers
#################################################################
notify:
  platform: command_line
  command: "tts"

#################################################################
## Automations online status
#################################################################
- alias: "System Online"
  trigger:
    platform: state
    entity_id: device_tracker.work_pc
    from: 'not_home'
    to: 'home'
action:
  service: notify.notify
  data:
    message: "Uttering a really really really long sentence to test this to be really really really really working when my system comes online."

Now ofcourse like joekieffer mentioned…nothing.

When I open a shell and execute the command from the prompt. No problem.

When I do it via shell_command it works. That is how I have it for a while now.


#################################################################
## Automations online status
#################################################################
- alias: "System Online"
  trigger:
    platform: state
    entity_id: device_tracker.work_pc
    from: 'not_home'
    to: 'home'
  action:
    service: shell_command.speak_sus

#################################################################
## Shell commands
#################################################################
shell_command:
 speak_sus: tts "Uttering a really really really long sentence to test this to be really really really really working when my system comes online."

But I want it to work via command_line since that saves me from extra lines under shell_command. For me shell_command is not a solution merely a workaround.

Help?

Do you see anything in the home assistant log that says “Command failed” or “Error trying to…” Basically lines 43 or 45 here: https://github.com/home-assistant/home-assistant/blob/dev/homeassistant/components/notify/command_line.py This would tell you if it is getting an error during command execution. The next thing you would want to try is get a good paragraph of text and trigger the event and us something like

ps aux | grep tts 

See if the program is running the command. One thing that I didn’t put in my post is that I had to change pulse audio permissions on my server build to allow it to use the audio system under my user id. I am running Ubuntu 15.10 server and it might not be an issue with rasbian on the Pi but a similar OS architecture.

What I wonder is how does HA assemble the command line notification. If I am reading the git link above it looks like should be how it assembles and runs the command but alas I am not a skilled programmer.

I have this. Looks fine doesn’t it?


16-04-28 18:16:10 homeassistant.components.automation: Executing System Offline
16-04-28 18:16:10 homeassistant.core: Bus:Handling <Event logbook_entry[L]: name=System offline, message=has been triggered, domain=automation>
16-04-28 18:16:10 homeassistant.core: Bus:Handling <Event call_service[L]: domain=notify, service_call_id=1979574928-20, service_data=message=Uttering a really really really long sentence to test this to be really really really really working when the system goes offline., service=notify>

And this

pi@Livingroom ~ $ ps aux | grep tts
pi        4759  0.0  0.1   4260  1852 pts/2    S+   18:26   0:00 grep --color=auto tts
pi@Livingroom ~ $

Here’s a tip: If you surround the first letter of the program with [ and ], you won’t see the “grep” process.

[grayson@homeassistant ~]$ ps aux | grep tts grayson 934 0.0 0.0 2644 500 pts/0 S+ 17:09 0:00 grep tts [grayson@homeassistant ~]$ ps aux | grep [t]ts [grayson@homeassistant ~]$ ps aux | grep hass grayson 277 0.0 1.5 22364 14228 ? S 02:29 0:00 /usr/bin/python /usr/bin/hass --daemon grayson 278 3.9 3.9 364888 37456 ? Sl 02:29 35:02 /usr/bin/python /usr/bin/hass --daemon grayson 938 0.0 0.0 2644 544 pts/0 S+ 17:09 0:00 grep hass [grayson@homeassistant ~]$ ps aux | grep [h]ass grayson 277 0.0 1.5 22364 14228 ? S 02:29 0:00 /usr/bin/python /usr/bin/hass --daemon grayson 278 3.9 3.9 364888 37456 ? Sl 02:29 35:02 /usr/bin/python /usr/bin/hass --daemon [grayson@homeassistant ~]$

1 Like

Okay. Looks like this

pi@Livingroom:~$ ps aux | grep [t]ts
pi@Livingroom:~$ ps aux | grep [h]ass
root       702  0.0  1.6  23580 15216 ?        S    Apr28   0:00 /usr/bin/python3 /usr/local/bin/hass -v --config /var/opt/homeassistant --pid-file /var/run/hass.pid --daemon
root       703  4.0  4.4 392564 42512 ?        Sl   Apr28  11:35 /usr/bin/python3 /usr/local/bin/hass -v --config /var/opt/homeassistant --pid-file /var/run/hass.pid --daemon
pi@Livingroom:~$

Please know that

1 root user is active and has current password
3. Root is permitted root login.
3. switch commands work
4. Running same commands sudo tts blah b lah blah on shell terminal works.

Based on

 $ ps aux |grep [t]ts
 $ 

it looks like the command is not running or just running tts and exiting in a fraction of a second. What we need someone to comment/verify if using the notify service executes the command like you do in the command line. My bet is that it does not.

If I had to guess as to what is happening, again This is just a guess it executes tts with no options and then does something with that message data, maybe logbook or history had the message data in it.

To prove this you could add the message data in the command field and try triggering the notification. If you get audio then the issue has to be something with the way that notify sends commands.

I already tried adding the message data manually. It launches but no sound.

If you look at this again you see how message data is processed through automation scenario


16-04-28 18:16:10 homeassistant.core: Bus:Handling <Event call_service[L]: domain=notify, service_call_id=1979574928-20, service_data=message=Uttering a really really really long sentence to test this to be really really really really working when the system goes offline., service=notify>

So at loss here.

What you are posting is the log message not exactly what python is doing to execute the command. Below is the code snip-its that are essentially calling tts. Looking at how this all assembles it looks like the tts command is opened and then data is sent to it. The shell command just makes a sub process.

stack over flow says you might need the newline char to get espak to work in the way that is defined maybe the same for tts? adding \n at the end of your message would be required.

http://stackoverflow.com/questions/7618533/python-sequential-calls-to-subprocess-in-this-case-espeak

command_line.py

        proc = subprocess.Popen(self.command, universal_newlines=True,
                                stdin=subprocess.PIPE, shell=True)
        proc.communicate(input=message)

shell_command.py

       subprocess.call(conf[call.service], shell=True,
                        stdout=subprocess.DEVNULL,
                        stderr=subprocess.DEVNULL)

I had a lot of problems with SSH as well…

My solution was to ssh into the local machine…perhaps you need key auth then.

i.e:

pi@Livingroom: ssh root@localhost ps aux | grep [t]ts

some of my command were still not working. I added some " ’ " to make it working…

Perhaps this helps.

@joekieffer

hordur’s templated_shell_command solved my issue