Kodi Starter script for linux: Linux script to start Kodi from Yatse (NeoAcheron)

This post was originally made on previous version of the forum by NeoArcheron


Hi there,

Love your remote app. Its definitely the best XBMC remote ever. However I recently ditched my Windows installation for a linux one and I found that the only feature lacking was a way to let Yatse launch XMBC automatically, just like in Windows with your autostart utility.

So I spent a few minutes writing a little BASH and came up with a script that can be easily started by your linux distribution’s startup manager as a daemon.
PS: Certain distro’s net to install tcpdump separately, so make sure it is installed and working before attempting to run this utility script.

I placed the following into /home/xbmc/autostarter.sh and made the file executable by all:

#!/bin/bash

UDP_PORT=12          # Change this if you need to run this on a different port, just remember to update Yatse's settings as well
RUN_XBMC_AS=xbmc     # Change this if you need to run it as another user

START_PHRASE="YatseStart-Xbmc"    # Do not touch this, unless you know what you are doing...

# The following block checks if the user running this script has the required privileges to listen on the port specified above
   WHO=`whoami` 
   if [ "$WHO" != "root" ]; then
      echo "Unprivileged users may not evesdrop on ports. Cannot start unless running as root."
      exit 1
   fi


echo "Listening on port $UDP_PORT for Yatse remote start command"

while [ true ]; do
   # Wait for a packet to come in from Yatse
   LISTEN=`tcpdump "udp port $UDP_PORT" -A -c 1 2>&1 | grep -o "$START_PHRASE"`
   # Make sure that we received the right command
   if [ "$LISTEN" = "$START_PHRASE" ]; then
      echo "Starting XBMC as $RUN_XBMC_AS"
      # Start XBMC using sudo -u to run it using the username above
      # If you need to you can replace the xbmc command below with xbmc-standalone if you are not using a window manager
      sudo --user=$RUN_XBMC_AS xbmc
   fi 
   # Sleep, to be nice, for unwanted rogue processes writing to our port
   sleep 1
done   

Hope this is as helpful to someone else as it is to me.

Kindest regards,
NeoAcheron

1 Like

I came here looking for the visa versa send a command from linux to open my shield tiv
From what was written here I figured I should just send a UDP packet with the magic string

echo “YatseStart-Xbmc” | nc -w 2 -C -u -N 192.168.1.5 5600

The above did the trick for me

1 Like

That’s great! I was just looking for such a script :slight_smile:

I had to perform the following 2 modifications in order to get it to work on Kodi18
I changed count (-c option in tcpdump) to 2, as the phrase is actually received on the 2nd packet
LISTEN=tcpdump "udp port $UDP_PORT" -A -c 2 2>&1 | grep -o "$START_PHRASE"

And I had to change the start command to sudo -u, and “xbmc” to “kodi”
sudo -u $RUN_XBMC_AS kodi

Thank you very much NeoAcheron!

Hello, one question. Is it possible to use that script on a Raspberry Pi 3, running as a Magic Mirror with Raspbian Buster and Kodi 18.4? I tried with standard settings and also with the settings of DrGonzo but without success. Any ideas or recommendations?

This topic may be old, but it is a bit of gold dust.

Home Assistant user here. Used a variation of this to start KODI from HA

shell_command:
start_kodi: “echo -n ‘YatseStart-Xbmc’ | nc -u -w1 192.168.1.5 5600”

Maybe this will pickup on a keyword search. And a Home Assistant user will know what to do with the above YAML. (If not ask and I will reply)

Meanwhile - Tolriq you a hero for a brilliant app that keeps giving. I gotta go donate again cos Android Auto works so well with my new Kenwood head unit. Happy Yatse user for long time. And bonus XMBCstarter solving my other puzzles :smiling_face_with_three_hearts: :partying_face:

Hi, the truth is that I’ve been thinking about bash so much and I haven’t managed to start kodi remotely. Could someone please help me?
I’m on kodi 21 (kde neon) my user is ruben.
Thank you

I have made a slight modification to the script to fit my needs.
I wanted the script to run at startup automatically. Doing that from sudo is unecessarily complicated (making sure all the right environment variables are passed back to the owner is a hassle…
To be able to run tcpdump from the current user, make a new group that has permissions to run it without password, and add the current user to it.

sudo groupadd pcap
sudo usermod -a -G pcap $USER
sudo chgrp pcap /usr/bin/tcpdump
sudo setcap cap_net_raw,cap_net_admin=eip /usr/bin/tcpdump

and then you can use the following script

#!/bin/bash
# Note that this is a different port from the one that kodi listens to for commands (i.e "play" in yatse.)!
# This one is dedicated to just starting kodi from WOL.
UDP_PORT=5600 
# This script can be run from the user directly, so no need to run it as sudo.

# The command that the daemon expects Yatse to send.
START_PHRASE="YatseStart-Xbmc"    # Do not touch this, unless you know what you are doing...


echo "Listening on port $UDP_PORT for Yatse remote start command"

while [ true ]; do
   # Wait for a packet to come in from Yatse
   # Normally using tcpdump requires root. As launching a thing in a wayland session from the root user is unecessarily complicated, the way to go is to make it so you can use tcpdump from the current user. See the following snippet on how to do this: https://gist.github.com/srugano/93df27f96a826a6bc1973e6b9a3d8244.
   LISTEN=`tcpdump "udp port $UDP_PORT" -A -c 1 2>&1 | grep -o "$START_PHRASE"`
   # Make sure that we received the right command
   if [ "$LISTEN" = "$START_PHRASE" ]; then
      echo "Wakeup request from yatse received, starting kodi!"
      # Since this is running in background, must specify that you want to start it on the right display. 
      # Which display this is, is by checking `env | grep WAYLAND_DISPLAY` on the desktop environment. 
      # This should say someting like `wayland-0`. To start kodi on that wayland display: `WAYLAND_DISPLAY=wayland-0`. 
      # This is the wayland equivalent of using `DISPLAY=:0` for an XORG session.
      WAYLAND_DISPLAY="wayland-0" kodi
   fi 
   sleep 1
done

This version of the script is made to be run as a user, and explicitly sets the session/display that kodi needs to start at. This means it can be run from cron, or your DE/WM’s startup scripts (I’m running a kde plasma session, so just added it as a startup script there).

Hope this is helpful for people finding this thread in 2025!