Install Kodi 20.1 On Debian 11/12 (Bullseye/Bookworm)

# KODI Installation version 20.1 Nexus on Debian 11/12 (Bullseye/Bookworm)

# Kodi is a multi-platform home-theater PC (HTPC) application.
# official repository: https://github.com/xbmc/xbmc
# website: http://kodi.tv/

# update all pkgs

  1. $ sudo apt update

# if need run upgrade

  1. $ sudo apt upgrade

# all pkgs must be up to date before going further


# edit source list to add testing repo

  1. $ sudo nano /etc/apt/sources.list

# add the line below at end

deb http://deb.debian.org/debian testing main non-free contrib

# CTRL+X and Y to SAVE
# get testing packages list

  1. $ sudo apt update

DO NOT UPGRADE

# install kodi 20.1

  1. cd ~/Downloads

# AMD64

  1. $ sudo apt install kodi

# or
# download/install Kodi 20.1 manually (not recommended)

  1. $ wget -O  kodi_20.1+dfsg-1_amd64.deb http://ftp.us.debian.org/debian/pool/main/k/kodi/kodi_20.1+dfsg-1_amd64.deb

# in case of dependencies error, download and install all pkgs

  1. $ for x in {'kodi-repository-kodi_20.1+dfsg-1_all.deb','kodi-data_20.1+dfsg-1_all.deb','kodi-bin_20.1+dfsg-1_amd64.deb','kodi_20.1+dfsg-1_amd64.deb'}; do wget $x http://ftp.us.debian.org/debian/pool/main/k/kodi/$x; done

# install Kodi 20.1 manually

  1. $ sudo apt install ./kodi-data_20.1+dfsg-1_all.deb ./kodi-bin_20.1+dfsg-1_amd64.deb ./kodi_20.1+dfsg-1_amd64.deb ./kodi-repository-kodi_20.1+dfsg-1_all.deb

# ARM64 Raspberry PI 4

  1. $ sudo apt install kodi

# or
# download/install Kodi 20.1 manually (not recommended)

  1. $ for x in {'kodi-repository-kodi_20.1+dfsg-1_all.deb','kodi-data_20.1+dfsg-1_all.deb','kodi-bin_20.1+dfsg-1_arm64.deb','kodi_20.1+dfsg-1_arm64.deb'}; do wget $x http://ftp.us.debian.org/debian/pool/main/k/kodi/$x; done
  1. $ sudo apt install ./kodi-data_20.1+dfsg-1_all.deb ./kodi-bin_20.1+dfsg-1_arm64.deb ./kodi_20.1+dfsg-1_arm64.deb ./kodi-repository-kodi_20.1+dfsg-1_all.deb

# official repo should be automatically installed but if you want to install it manually

  1. $ $ sudo apt install kodi-repository-kodi

# add current user to all needed groups

  1. $ sudo usermod -aG adm,dialout,cdrom,sudo,audio,www-data,render,video,plugdev,games,users,dip,input $USER

# for Raspberry PI add gpio i2c spi

  1. $  sudo usermod -aG  adm,dialout,cdrom,sudo,audio,www-data,video,plugdev,games,users,input,render,netdev,gpio,i2c,spi pi

# edit source list to comment testing repo

  1. $ sudo nano /etc/apt/sources.list

# comment testing repo

#deb http://deb.debian.org/debian testing main non-free contrib

# CTRL+X and Y to SAVE
# get main packages list

  1. $ sudo apt update

# Kodi Power Menu

# SUSPEND/RESUME (amd64 platform)
# enable suspend services

  1. $ sudo systemctl unmask sleep.target suspend.target hibernate.target hybrid-sleep.target

# 2 way to enable power policy for pi user
# 1. if /etc/polkit-1/localauthority exists

  1. $ sudo nano /etc/polkit-1/localauthority/50-local.d/50-kodi.pkla
[Allow consolekit]
Identity=unix-group:plugdev
Action=org.freedesktop.upower.suspend;org.freedesktop.consolekit.system.*
#Action=org.freedesktop.consolekit*
ResultAny=yes
ResultInactive=no
ResultActive=yes
[Allow login1]
Identity=unix-group:plugdev
Action=org.freedesktop.login1*
ResultAny=yes
ResultInactive=no
ResultActive=yes
[Allow Upower]
Identity=unix-group:plugdev
Action=org.freedesktop.upower.suspend
ResultAny=yes
ResultInactive=no
ResultActive=yes

# CTRL + X the Y to SAVE

# 2. alternative
# or create rules in /usr/share/polkit-1/rules.d/

  1. $sudo nano /usr/share/polkit-1/rules.d/10-kodi.rules
polkit.addRule(function(action, subject) {
    polkit.log("action=" + action);
    polkit.log("subject=" + subject);
    if (action.id.indexOf("org.freedesktop.login1.") == 0) {
        return polkit.Result.YES;
    }
    if (action.id.indexOf("org.freedesktop.udisks.") == 0) {
        return polkit.Result.YES;
    }
    if (action.id.indexOf("org.freedesktop.upower.") == 0) {
        return polkit.Result.YES;
    }
});

# CTRL + X the Y to SAVE

# run kodi to check the power menu

  1. $ kodi-standalone

# create kodi service

  1. $ sudo nano /lib/systemd/system/kodi.service
[Unit]
Description = Kodi Media Center
After = remote-fs.target network-online.target
Wants = network-online.target
[Service]
User = pi
Group = pi
Type = simple
ExecStart = /usr/bin/kodi-standalone
Restart = on-abort
RestartSec = 5
[Install]
WantedBy = multi-user.target

# CTRL + X the Y to SAVE

  1. $ sudo systemctl daemon-reload
  1. $ sudo systemctl enable kodi
  1. $ sudo systemctl start kodi
  1. $ sudo systemctl status kodi

# add kodi smb share points

# insert lines at the end of conf

  1. $ sudo nano /etc/samba/smb.conf
[kodi]
path = /home/pi/.kodi
read only = no
public = yes
writable = yes
browseable = yes
guest ok = yes
create mask = 0777
directory mask = 0755
force user = pi

[userdata]
path = /home/pi/.kodi/userdata
read only = no
public = yes
writable = yes
browseable = yes
guest ok = yes
create mask = 0777
directory mask = 0755
force user = pi

# CTRL + X the Y to SAVE

  1. $ sudo systemctl restart smbd
  1. $ sudo reboot

# Adding media source to Kodi


# IMPORTANT NOTICE for Windows network SMB share in Kodi 20
# make sure to configure your NAS with shared folders using SMB v2 or v3 and with
# access to everyone (no user/pass)
# setup KODI SMB service with minimum version SMBv2 and maximum SMBv3
# browse the network from a PC and check if you have a full access to shared
# folders without needing to enter your credential
# then in Kodi create your movies, TV shows, etc. source points (i.e. //MYSERVER/Video ) with
# a dummy username and password (like username: srcmedia and paswd: srckodi)


# OPTIONAL: create Video and TV Shows folders if you store the media on the server (not recommended)

  1. $ cd ~/
  1. $ mkdir Video
  1. $ mkdir "TV Shows"

# setup HDMI CEC

# on raspberry PI 4 HDMI CEC is already managed,
# however some keys of remote control must be adjusted like the back and contextual menu key.
# use the Keymap Editor addon (already installed) to make your changes in >global>navigation.

# on amd64 platform

# do not forget to add the Pulse Heigh CEC adapter ( https://www.pulse-eight.com ) to be able to use the TV remote control even with the Intel NUC which have a poor CEC implementation.
you may need to deactivate internal IR Receiver and HDMI CEC in Intel NUC Bios.


# install rc6 mce IR remote control with Kodi 20

# by default Kodi manages the RC6 MCE remote control if your usb dongle is installed or the built in extended IR receiver is set in your bios
# you may need to activate internal IR Receiver in Intel NUC Bios.
# unfortunately some essential buttons of the remote control do not work like BACK (KEY_BACK) and OK (KEY_OK) for example. Read the instructions below to fix it.
# open SSH session
# install ir-keytable

  1. $ sudo apt install ir-keytable

# check if remote control is recognized

  1. $ sudo ir-keytable

# result for usb dongle (mceusb)

Found /sys/class/rc/rc0/ with:
        Name: Media Center Ed. eHome Infrared Remote Transceiver (147a:e03e)
        Driver: mceusb
        Default keymap: rc-rc6-mce
        Input device: /dev/input/event6
        LIRC device: /dev/lirc0
        Attached BPF protocols: Operation not supported
        Supported kernel protocols: lirc rc-5 rc-5-sz jvc sony nec sanyo mce_kbd rc-6 sharp xmp imon rc-mm
        Enabled kernel protocols: lirc rc-6
        bus: 3, vendor/product: 147a:e03e, version: 0x1201
        Repeat delay = 500 ms, repeat period = 125 ms

# example with build IR (cir)

Found /sys/class/rc/rc0/ with:
        Name: ITE8708 CIR transceiver
        Driver: ite-cir
        Default keymap: rc-rc6-mce
        Input device: /dev/input/event4
        LIRC device: /dev/lirc0
        Attached BPF protocols: Operation not supported
        Supported kernel protocols: lirc rc-5 rc-5-sz jvc sony nec sanyo mce_kbd rc-6 sharp xmp imon rc-mm
        Enabled kernel protocols: lirc rc-6
        bus: 25, vendor/product: 1283:0000, version: 0x0000
        Repeat delay = 500 ms, repeat period = 125 ms

# Important Info are:

 system device: rc0 (Found /sys/class/rc/rc0/)
driver: mceusb or ite-cir
protocol: rc-6

# copy the rc6 mce keymap rc6_mce.toml from /lib/udev/rc_keymaps/ to /etc/rc_keymaps/

  1. $ sudo cp /lib/udev/rc_keymaps/rc6_mce.toml /etc/rc_keymaps/

# edit the keymap to fix it

  1. $ sudo nano /etc/rc_keymaps/rc6_mce.toml

# replace entries 0x800f0412, 0x800f0413, 0x800f0418, 0x800f0422 and 0x800f0423 with:

.
.
0x800f0412 = "KEY_PAGEUP"
0x800f0413 = "KEY_PAGEDOWN"
.
0x800f0418 = "KEY_PLAY"
.
.
0x800f0422 = "KEY_ENTER"
0x800f0423 = "KEY_BACK"

# CTRL+X then Y to save
# edit /etc/rc_maps.cfg to add our custom keymap for mceusb and ite-cir driver

  1. $ sudo nano /etc/rc_maps.cfg

# add these lines at end

mceusb	*			/etc/rc_keymaps/rc6_mce.toml
ite-cir	*			/etc/rc_keymaps/rc6_mce.toml

# CTRL+X then Y to save
# now we are going to create a service to load our keymap at startup

  1. $ sudo nano /etc/systemd/system/rc6mce-ir-keytable.service

# rc-6 protocol and sys/class/rc rc0 is reported and obviously the path to our keymap

[Unit]
Description=RC6 MCE Keymap Fix
After=network.service kodi.service
[Service]
Type=oneshot
ExecStart=/usr/bin/ir-keytable -c -p rc-6 --write=/etc/rc_keymaps/rc6_mce.toml --sysdev=rc0
[Install]
WantedBy=default.target

# CTRL+X then Y to save
# activate the service

  1. $ sudo systemctl enable rc6mce-ir-keytable.service

# start service

  1. $ sudo systemctl start rc6mce-ir-keytable.service

# now the pause, back and OK buttons work and to get info select the item on Kodi and do a long press on OK
# reboot

  1. $ sudo reboot

# to test your remote control or get the correct scancode

  1. $ sudo ir-keytable -t

# Backup / Restore Kodi Data

# backup

  1. $ cd ~/
  2. $ tar cvzf ~/Downloads/"kodi_backup-$(date +'%m-%d-%y').tar.gz" --exclude=.kodi/temp .kodi

# restore

  1. $ cd ~/
  2. $ sudo systemctl stop kodi
  3. $ tar xzvf kodi_backup-xx-xx-xx.tar.gz
  4. $ sudo systemctl start kodi

# UNINSTALL KODI SERVICES

# if for some reason you no longer need the Home Theater service and want to keep the server for the audio system only (in short using it as the MusicLounge server) do the following

  1. $ sudo systemctl stop kodi
  1. $ sudo systemctl disable kodi

# edit /etc/samba/smb.conf to remove or comment SMB Share kodi

  1. $ sudo nano /etc/samba/smb.conf
#[kodi]
#path = /home/pi/.kodi
#read only = no
#public = yes
#writable = yes
#browseable = yes
#guest ok = yes
#create mask = 0777
#directory mask = 0755
#force user = pi

#[userdata]
#path = /home/pi/.kodi/userdata
#read only = no
#public = yes
#writable = yes
#browseable = yes
#guest ok = yes
#create mask = 0777
#directory mask = 0755
#force user = pi

# CTRL + X and Y to save

  1. $ sudo reboot

# you can remove kodi user data and configuration files if needed

  1. $ cd ~/
  2. $ sudo rm -r .kodi

# Congrats! The audiophile server and the Kodi Home Theater are ready

# setup the Kodi SYSTEM > AUDIO > and choose the correct number of speakers
# activate the passthrough to take benefit of Dolby, DTS, trueHD, etc.

Enable IR Remote Control Wake Up On USB Port

# read this tutorial if you cannot wake up (resume) your Barebone PC with your IR remote control after entering standby mode (suspend)
# do the following to enable wake up on USB port where your IR remote control receiver (USB IR Blaster) is connected
# check the usb port used by your receiver

  1. $ lsusb -t
pi@medialounge:~$ lsusb -t
/:  Bus 02.Port 1: Dev 1, Class=root_hub, Driver=xhci_hcd/1p, 5000M
/:  Bus 01.Port 1: Dev 1, Class=root_hub, Driver=xhci_hcd/6p, 480M
    |__ Port 1: Dev 6, If 1, Class=Human Interface Device, Driver=usbhid, 12M
    |__ Port 1: Dev 6, If 0, Class=Vendor Specific Class, Driver=mceusb, 12M
    |__ Port 3: Dev 3, If 0, Class=Audio, Driver=snd-usb-audio, 480M

# mceusb is on Bus 1 Port 1 (1-1)
# to confirm the USB port, get the Product ID of the receiver

  1. $ lsusb
pi@medialounge:~$  lsusb
Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 001 Device 004: ID 046d:c52b Logitech, Inc. Unifying Receiver
Bus 001 Device 003: ID 152a:8750 Thesycon Systemsoftware & Consulting GmbH D90 MQA
Bus 001 Device 009: ID 147a:e03e Formosa Industrial Computing, Inc. Infrared Receiver [IR605A/Q]
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

# Infrared Receiver Product ID is e03e

# then get the port your receiver is plugged in:

  1. $ grep e03e /sys/bus/usb/devices/*/idProduct
/sys/bus/usb/devices/1-1/idProduct:e03e

# 1-1 confirm the Bus 1 and Port 1
# now check if wake up is enabled for this device

  1. $ cat /sys/bus/usb/devices/1-1/power/wakeup
disabled

# it is disabled, enable wake up on this port

$ sudo sh -c 'echo "enabled" > /sys/bus/usb/devices/1-1/power/wakeup'

# check again

  1. $ cat /sys/bus/usb/devices/1-1/power/wakeup
enabled

# create a systemd entry to make it permanent
# store the script in /usr/local/bin

  1. $ sudo nano /usr/local/bin/ir-remote-wakeup.sh

# add the command to enable wakeup

#!/usr/bin/bash
# enable wake up on IR remote control using USB bus 1 port 1
echo enabled > /sys/bus/usb/devices/1-1/power/wakeup

# CTRL+X and Y to SAVE

  1. $ sudo chmod +x /usr/local/bin/ir-remote-wakeup.sh

#
# now create a systemd service to make it permanent

  1. $ sudo nano /lib/systemd/system/ir-remote-wakeup.service
# enable wake up ir remote conrol on bus 1 port 1
[Unit]
Description=wakeup ir remote on bus 1 port 1 see ir-remote-wakeup.sh from /usr/local/bin/ for more info

[Service]
ExecStart=/usr/local/bin/ir-remote-wakeup.sh

[Install]
WantedBy=multi-user.target

# enable service

  1. $ sudo systemctl daemon-reload
  2. $ sudo systemctl enable ir-remote-wakeup.service
  3. $ sudo systemctl start ir-remote-wakeup.service

#
# on suspend mode your IR remote control can now wake up the barebone PC


# to allow sleep (suspend) but disallow hibernation
# edit

  1. $ sudo nano /etc/systemd/logind.conf
[Sleep]
AllowSuspend=yes
AllowHibernation=no
AllowSuspendThenHibernate=no

# disable ASPM in bios may help if your PCIe hardware cannot on wake up from sleep
# check if the PC wake up normaly if this still not working change the ASPM policy
# check it with:

  1. $ cat /sys/module/pcie_aspm/parameters/policy

# should be set to [performance]

[default] performance powersave powersupersave

# if performance is not set add
# pcie_aspm=force pcie_aspm.policy=performance cmds
# to grub GRUB_CMDLINE_LINUX_DEFAULT

  1. $ sudo nano /etc/default/grub

# add the cmds, save and update grub

  1. $ sudo update-grub
  1. $ sudo reboot

# check again with

  1. $ cat /sys/module/pcie_aspm/parameters/policy
default [performance] powersave powersupersave

Add LIRC Service (Odroid IR Remote Ctrl)


# ###############################################################################
# if Triggerhappy RC service has been previously installed
# it may not be necessary to install Lirc

# ###############################################################################

# STEP 16bis

# OPTIONAL: Remote Control Management with LIRC

# the previous tutorial on remote management by the very easy to use TriggerHappy did not make you happy? so you want a deep control of your RC? read the following…

# Using the integrated IR sensor of the Odroid board to drive your music library with a remote control is possible
# We are going to install a remote control management using LIRC (Linux Infrared Remote Control )

# for the example we use a very common Remote Control using the standard MCE (Media Center Remote Control) format
# reference Remote Control is XPC-RC01 or RC6 Media Center

# do not plug the USB IR sensor included with the remote control, in this example we do not need it as we use the IR sensor integrated on Odroid board
# more info on LIRC is available here: https://lirc.org/

# a snapshot of lirc remotes is available for download here:
# download it, extract it and browse remote images to find the closest one
https://sourceforge.net/p/lirc-remotes/code/ci/master/tree/remotes/

   

# install LIRC

# Armbian for Odroid boards includes a wizard for LIRC installation,
# launch armbian-config and select Network > Install IR

  1. $ sudo armbian-config

# to install it manually

  1. $ sudo apt-get install lirc

# modify the driver

  1. $ sudo nano /etc/lirc/lirc_options.conf
[lircd]
nodaemon        = False
driver          = default
device          = /dev/lirc0
output          = /var/run/lirc/lircd
pidfile         = /var/run/lirc/lircd.pid
plugindir       = /usr/lib/aarch64-linux-gnu/lirc/plugins
#plugindir = /usr/lib/x86_64-linux-gnu/lirc/plugins/
permission      = 666
allow-simulate  = No
repeat-max      = 600

[lircmd]
uinput          = False
nodaemon        = False

[modinit]
code = /sbin/modprobe meson-ir
#code = /sbin/modprobe  lirc_serial

[lircd-uinput]
# add-release-events = True
# release-timeout    = 50
# release-suffix     = _EVUP

# modify the default remote control configuration file
# this one is based on Remote Control ShuttleX conf (PN31) available here
# http://lirc.sourceforge.net/remotes/shuttle/PN31
# Remote Control DB is available here:
# https://sourceforge.net/p/lirc-remotes/code/ci/master/tree/remotes/

# create the remote config file

  1. $ sudo nano /etc/lirc/lircd.conf.d/myremote.lircd.conf
# copy the configuration
#
# this config file was automatically generated
# using WinLIRC 0.6.5 (LIRC 0.6.1pre3) on Mon Aug 25 22:24:07 2003
#
# contributed by lirc @ trollmaster.net
#
# brand:        made in china
# model:        XPC-RC01 based on PN31 from ShuttleX
# supported devices: 
#

begin remote

  name  CNRemote
  bits            9
  flags SPACE_ENC
  eps            40
  aeps          100

  header       3021  1469
  one           310   266
  zero          310   780
  ptrail        310
  post_data_bits  8
  post_data      0xFC
  gap          12038
  toggle_bit      0


      begin codes
          KEY_POWER                0x000000000000017B
          KEY_TV                   0x00000000000001BB
          print                    0x000000000000013B
          KEY_EXIT                 0x00000000000001DB
          KEY_AUDIO                0x000000000000015B
          KEY_IMAGES               0x000000000000019B
          KEY_VIDEO                0x000000000000011B
          KEY_MENU                 0x00000000000001EB
          KEY_BACK                 0x000000000000014B
          KEY_R                    0x000000000000018B
          KEY_OK                   0x0000000000000177
          KEY_PREVIOUS             0x000000000000016B
          KEY_PLAYPAUSE            0x00000000000001AB
          KEY_NEXT                 0x000000000000012B
          KEY_REWIND               0x0000000000000167
          KEY_STOP                 0x00000000000001B7
          KEY_FASTFORWARD          0x000000000000016F
          KEY_VOLUMEUP             0x00000000000001A7
          KEY_VOLUMEDOWN           0x0000000000000127
          KEY_INFO                 0x0000000000000137
          KEY_CHANNELUP            0x00000000000001AF
          KEY_CHANNELDOWN          0x000000000000012F
          KEY_MUTE                 0x00000000000001C7
          KEY_RECORD               0x00000000000001D7
          KEY_BACKSPACE            0x00000000000001CF
          KEY_1                    0x0000000000000147
          KEY_2                    0x0000000000000157
          KEY_3                    0x000000000000014F
          KEY_4                    0x0000000000000187
          KEY_5                    0x0000000000000197
          KEY_6                    0x000000000000018F
          KEY_7                    0x0000000000000107
          KEY_8                    0x0000000000000117
          KEY_9                    0x000000000000010F
          KEY_DOT                  0x00000000000001FB
          KEY_0                    0x00000000000001E7
          KEY_L                    0x00000000000001F7
          KEY_UP                   0x00000000000001B3
          KEY_DOWN                 0x000000000000011F
          KEY_LEFT                 0x00000000000001EF
          KEY_RIGHT                0x00000000000001BF
      end codes

end remote

# CTRL+O to save
# CTRL+X to exit

# change the default remote control buttons configuration to drive MPD with irexec a special daemon included with LIRC

  1. $ sudo nano /etc/lirc/irexec.lircrc
begin
 prog = irexec
 button = KEY_PLAY
 config = mpc play >/dev/null
 flags = quit
end

begin
 prog = irexec
 button = KEY_STOP
 config = mpc stop >/dev/null
 flags = quit
end

begin
 prog = irexec
 button = KEY_PAUSE
 config = mpc pause >/dev/null
 flags = quit
end

begin
 prog = irexec
 button = KEY_PLAYPAUSE
 config = mpc toggle >/dev/null
 flags = quit
end

begin
 prog = irexec
 button = KEY_NEXT
 config = mpc next >/dev/null
 flags = quit
end

begin
 prog = irexec
 button = KEY_PREVIOUS
 config = mpc prev >/dev/null
 flags = quit
end

begin
 prog = irexec
 button = KEY_FASTFORWARD
 config = mpc seek +10 >/dev/null
 flags = quit
end

begin
 prog = irexec
 button = KEY_FORWARD
 config = mpc seek +10 >/dev/null
 flags = quit
end


begin
 prog = irexec
 button = KEY_REWIND
 config = mpc seek -10 >/dev/null
 flags = quit
end

begin
 prog = irexec
 button = KEY_3
 config = /home/pi/scripts/./playlist3.sh >/dev/null
 flags = quit
end

begin
 prog = irexec
 button = KEY_1
 config = /home/pi/scripts/./playlist1.sh >/dev/null
 flags = quit
end

begin
 prog = irexec
 button = KEY_2
 config = /home/pi/scripts/./playlist2.sh >/dev/null
 flags = quit
end

begin
 prog = irexec
 button = KEY_6
 config = /home/pi/scripts/./lowbass.sh >/dev/null
 flags = quit
end

begin
 prog = irexec
 button = KEY_9
 config = /home/pi/scripts/./jbleq.sh >/dev/null
 flags = quit
end

begin
 prog = irexec
 button = KEY_0
 config = mpc enable only 1 && mpc play >/dev/null
 flags = quit
end

# CTRL+O to save
# CTRL+X to exit

# create a symbolic link to match any version of irexec

  1. $ sudo ln -s /etc/lirc/irexec.lircrc /etc/lirc/lircrc

# we can already enable LIRC service and run irexec manually to catch remote control button and drive MPD
# but it’s better to modify the irexec service to start it at boot

  1. $ sudo nano /lib/systemd/system/irexec.service
[Unit]
Documentation=man:irexec(1)
Documentation=http://lirc.org/html/configure.html
Documentation=http://lirc.org/html/configure.html#lircrc_format
Description=Handle events from IR remotes decoded by lircd(8)
After=network.target
Wants=lircd.service

[Service]
Type=simple
ExecStart=/usr/bin/irexec /etc/lirc/irexec.lircrc
Restart=on-failure
SuccessExitStatus=3 4
RestartForceExitStatus=3 4

[Install]
WantedBy=multi-user.target

# CTRL+O to save
# CTRL+X to exit

# activate LIRC and IREXEC service

  1. $ sudo systemctl daemon-reload
  1. $ sudo systemctl enable lircd
  2. $ sudo systemctl start lircd
  1. $ sudo systemctl enable irexec
  2. $ sudo systemctl start irexec
  3. $ sudo systemctl status irexec

# be sure to stop lircd uinput service to not inject key events to kernel

  1. $ sudo systemctl stop lircd-uinput.service
  2. $ sudo systemctl disable lircd-uinput.service
  3.  
  4. $ sudo systemctl status lircd-uinput.service

# reboot and chek the status

  1. $ sudo reboot
  2.  
  3. $ sudo systemctl status lircd

# both services are now activated, enabled and running at startup

# if your remote control do not send the correct key use the dump function to
# identify the correct key and change your cmds in /etc/lirc/irexec.lircrc (see above)

# To dump all events received through your remote control (useful to get the corresponding keys):

  1. $ irw

# CTRL+C to exit

# Run your MPD Client (MALP Android for example) play an album
# use your remote control to stop, play, go next, prev,…

# Congrats! Your MCE Remote controls the Music Player Daemon!

Click the button NEXT below to continue…

Add IR Remote Control


# STEP16

# OPTIONAL: Add A Remote Control Management
# this tutorial and the next one is about controlling the audio server with a remote control to play, pause, stop, go next / prev song, launch playlist, drive equalizer,…
# this one use a very easy to use tool named Triggerhappy and the other use Lirc a more complete implementation supporting hundreds remote controls
# IMPORTANT: some devices like Intel NUC needs to enable Enhanced Consumer IR in BIOS to work with remote control

# Add a remote control management

# install triggerhappy (should be already installed)

  1. $ sudo apt-get install triggerhappy

# create a configuration file
# pressing ZERO button select the default (first) audio output

  1. $ sudo nano /etc/triggerhappy/triggers.d/triggers.conf


# add your key to play, stop,… copy/paste the lines below:
# in addition to the standard play, stop, pause,… commands,
# this remote control config will
# start playing playlist 1 to 3 random order by pressing the corresponding key 1, 2 or 3
# select 2 EQ setup by pressing key 6 or 9
# select the default audio output (NO EQ) by pressing 0 (zero)
#

KEY_PLAY 0 mpc play >/dev/null
KEY_STOP 0 mpc stop >/dev/null
KEY_PAUSE 0 mpc toggle >/dev/null
KEY_PLAYPAUSE 0 mpc toggle >/dev/null 
KEY_NEXT 0 mpc next >/dev/null
KEY_PREVIOUS 0 mpc prev >/dev/null
KEY_FASTFORWARD 0 mpc seek +10 >/dev/null
KEY_REWIND 0 mpc seek -10 >/dev/null
KEY_RECORD 0 /home/pi/scripts/./playlist.sh >/dev/null
KEY_LEFTCTRL+KEY_P 0 mpc play >/dev/null
KEY_LEFTCTRL+KEY_S 0 mpc stop >/dev/null
BTN_MIDDLE 0 mpc toggle >/dev/null
BTN_LEFT 0 mpc prev >/dev/null
KEY_LEFTCTRL+KEY_B 0 mpc prev >/dev/null
KEY_LEFTCTRL+KEY_F 0 mpc next >/dev/null
KEY_HOME 0 mpc toggle >/dev/null
KEY_LEFTSHIFT+KEY_B 0 mpc seek -10 >/dev/null
KEY_LEFTSHIFT+KEY_F 0 mpc seek +10 >/dev/null
KEY_NUMERIC_1 0 /home/pi/scripts/./playlist1.sh >/dev/null 
KEY_NUMERIC_2 0 /home/pi/scripts/./playlist2.sh >/dev/null
KEY_NUMERIC_3 0 /home/pi/scripts/./playlist3.sh >/dev/null
KEY_NUMERIC_6 0 /home/pi/scripts/./lowbass.sh >/dev/null
KEY_NUMERIC_9 0 /home/pi/scripts/./jbleq.sh >/dev/null
KEY_NUMERIC_0 0 mpc enable only 1 && mpc play >/dev/null
KEY_0 0 mpc enable only 1 && mpc play >/dev/null
KEY_1 0 /home/pi/scripts/./playlist1.sh >/dev/null 
KEY_2 0 /home/pi/scripts/./playlist2.sh >/dev/null 
KEY_3 0 /home/pi/scripts/./playlist3.sh >/dev/null 
KEY_6 0 /home/pi/scripts/./lowbass.sh >/dev/null
KEY_9 0 /home/pi/scripts/./jbleq.sh >/dev/null

# CTRL+O to save
# CTRL+X to exit

# activate triggerhappy

  1. $ sudo systemctl enable triggerhappy


  1. $ sudo systemctl start triggerhappy


  1. $ sudo systemctl status triggerhappy


# DEBUG THE KEY CODES
# useful if your remote control is not working, skip this during install
# if your remote control do not send the correct key use the dump function to identify the correct key and change your cmds in triggers.conf
# To dump all events received through your remote control (useful to get the corresponding keys):

  1. $ sudo thd --dump /dev/input/event*
EV_KEY KEY_5 1 /dev/input/event4
# KEY_5 1 command
EV_KEY KEY_5 0 /dev/input/event4
# KEY_5 0 command
EV_KEY KEY_5 1 /dev/input/event4
# KEY_5 1 command
EV_KEY KEY_5 0 /dev/input/event4
# KEY_5 0 command
EV_KEY KEY_5 1 /dev/input/event4
# KEY_5 1 command
EV_KEY KEY_5 0 /dev/input/event4
# KEY_5 0 command


# CTRL+C to exit


# OPTIONAL
# if you need to run script as root from triggerhappy (default user is nobody) do the following:
# giving root access is risky but if know what you’re doing this can be useful to run script to set parametric EQ or load playlist with the remote
# useful to drive ALSAEQ (equalizer plugin) for example

  1. $ sudo nano /lib/systemd/system/triggerhappy.service

change
–user nobody
to
–user root

# CTRL+O to save
# CTRL+X to exit

  1. $ sudo nano /etc/default/triggerhappy



# comment

#DAEMON_OPTS=""

# uncomment

DAEMON_OPTS="--user root"

# CTRL+O to save
# CTRL+X to exit

  1. $ sudo systemctl daemon-reload


  1. $ sudo systemctl restart triggerhappy


  1. $ sudo systemctl status triggerhappy

# add a playlist script
# if you followed our tutorials the playlist/ and scripts/ directory are already created

# from a remote PC, open the share point playlists and copy 2 playlists into it
# for example my_classical_albums.m3u and my_jazzy_albums.m3u

# create the script

  1. $ sudo nano ~/scripts/playlist1.sh
#!/bin/bash
#
# Script to load playlist
 
echo "start playlist"
mpc stop
mpc clear
mpc enable only 1
mpc load my_classical_albums
mpc random "on"
mpc crossfade 0
mpc play

# CTRL+O to save
# CTRL+X to exit

# set exec permission

  1. $ sudo chmod +x ~/scripts/playlist1.sh

# create the script

  1. $ sudo nano ~/scripts/playlist2.sh
#!/bin/bash
#
# Script to load playlist
 
echo "start playlist"
mpc stop
mpc clear
mpc enable only 1
mpc load my_jazzy_albums
mpc random "on"
mpc crossfade 0
mpc play

# CTRL+O to save
# CTRL+X to exit

# set exec permission

  1. $ sudo chmod +x ~/scripts/playlist2.sh

# now pressing key 1 or 2 of the remote control plays the playlist classical or jazzy

# obviously for this to work you need to save your playlists in the playlists directory


# in our example of configuration above we have key 6 and 9 assigned to ALSA EQ,
# by pressing key 6 or 9 you are going to trigger the lowbass.sh or the jbjeq.sh which drive the ALSA Equalizer plugin to shape your sound
read the tutorial on how to add a real time EQ to your audio system to complete the installation of this 2 scripts

# more info: triggerhappy by Stefan Tomanek <stefan.tomanek+th@wertarbyte.de>
http://github.com/wertarbyte/triggerhappy/

Click the button NEXT below to continue…