Shell command - mediainfo

I’m trying to get an automation to run mediainfo when my media player starts playing. I can get this to work using the Advanced SSH & Web Terminal add-on when I run the commands in sequence, so I think in theory this should work, but it doesn’t seem to be executing outside of that. Here’s how I set up configuration.yaml:

shell_command:
  startup: mkdir -p /mnt/v; mount -t cifs -o vers=3.0,noserverino,username=user,password=pass //192.168.1.5/share /mnt/v; apk add mediainfo; cp /mnt/v/startmpc.py startmpc.py
  mediainfo: python3 ~/startmpc.py

Then I have shell_command.startup run when Home Assistant starts, and shell_command.mediainfo runs when the player starts.

Any suggestions would be appreciated. Thanks!

You have three commands on that line. You can only run one.

https://www.home-assistant.io/integrations/shell_command/

You could try using a bash script that you run with the shell command instead.

I set log level to debug for shell commands and it seems that the startup shell command works OK (although when I subsequently run it from the services section it gives an error that the resource is busy when trying to mount the folder again - maybe that’s expected?).

The mediainfo shell command returns this error:

stdout: ""
stderr: >-
  python3: can't open file '/root/startmpc.py': [Errno 2] No such file or
  directory
returncode: 2

OK thanks. I’m running Home Assistant supervised on Debian. Where do I place the bash script so that it can be seen by the shell command? I might be misunderstanding but my impression was that changes to the disk were not persistent, hence why I wanted it to install mediainfo each time on startup.

In your /config directory.

That works, thanks!

For folks who are less familiar with Linux, like me, I had to adjust the shell command as follows:

startup: bash -c /config/startup.sh

And then I also opened a terminal and did chmod +x on startup.sh. I also placed startmpc.py in the config folder so that one looks like this:

mediainfo: python3 /config/startmpc.py

1 Like