My setup using RemotePi and a Harmony remote

Sunday, June 27th, 2021 at 11:19 am

Recently I wrote about how the RemotePi Board was the key to my desired setup for using a Raspberry Pi running Kodi as a media player. After the initial setup I needed to tweek some things related to my universal remote and while I don’t expect the RemotePi website to disappear, this post is my documentation on how I set it up (and how it works).

Raspberry Pi hardware

When I ordered the RemotePi I also ordered their open case as it has a hole for the power button and I didn’t want to hack up the existing case I was using. Based on the provided parts you shouldn’t need the instructions, it is pretty obvious how it all goes together.

Raspberry Pi software

It was interesting adding the scripts and config as I learned how it hooked into the LibreElec Startup & Shutdown process.

/storage/.config/autostart.sh

Runs at boot, in this case used to launch irswitch.sh in the background

#!/bin/bash
(/storage/.config/irswitch.sh)&

/storage/.config/irswitch.sh

Running in the background monitoring GPIO pin 14 for a signal from the RemotePi. This is how pressing the power button on the remote results in a graceful shutdown of the Pi.

#!/bin/bash
# this is the GPIO pin receiving the shut-down signal
GPIOpin1=14
echo "$GPIOpin1" > /sys/class/gpio/export
echo "in" > /sys/class/gpio/gpio$GPIOpin1/direction
while true; do
  sleep 1
  power=$(cat /sys/class/gpio/gpio$GPIOpin1/value)
  if [ $power != 0 ]; then
    echo "out" > /sys/class/gpio/gpio$GPIOpin1/direction
    echo "1" > /sys/class/gpio/gpio$GPIOpin1/value
    sleep 3
    poweroff
  fi
done

/storage/.config/shutdown.sh

Runs when the Pi is shutting down this tells the RemotePi via GPIO pin 15 to also shutdown and kill power to the Pi.

#!/bin/bash
if [ "$1" != "reboot" ]; then
  GPIOpin=15
  GPIOpin1=14
  echo "$GPIOpin" > /sys/class/gpio/export
  # execute shutdown sequence on pin
  echo "out" > /sys/class/gpio/gpio$GPIOpin/direction
  echo "1" > /sys/class/gpio/gpio$GPIOpin/value
  usleep 125000
  echo "0" > /sys/class/gpio/gpio$GPIOpin/value
  usleep 200000
  echo "1" > /sys/class/gpio/gpio$GPIOpin/value
  usleep 400000
  echo "0" > /sys/class/gpio/gpio$GPIOpin/value
  # set GPIO 14 high to feedback shutdown to RemotePi Board
  # because the irswitch.sh has already been terminated
  echo "$GPIOpin1" > /sys/class/gpio/export
  echo "out" > /sys/class/gpio/gpio$GPIOpin1/direction
  echo "1" > /sys/class/gpio/gpio$GPIOpin1/value
  usleep 4000000
fi

Remote control

MSL Digital have provided instructions for two remotes, a generic DVD player remote (that they can also provide) or how to configure a Logitech Harmony remote.

I wanted to keep using my old Harmony 650 remote so that is the path I choose. I was a bit surprised that once I dug up the MyHarmony software and remembered how to login that the config for my remote was still there. It was reasonable straightforward to add a “Media Center PC” device and configure a new “Kodi” activity.

The tricky part of the config was that I found it best to go into the settings for the device and change the power settings from “I press the same button for on and for off” to “I press two different buttons for on and for off”. The MCE device has PowerOn, PowerOff and PowerToggle commands. Not using PowerToggle is a cleaner solution, eg if the Pi was off but the Harmony thought it was still on, pressing the all off button would actually turn the Pi back on. Using discrete on and off will avoid that.

Once I had my remote sending MCE commands I trained the RemotePi to know about PowerOn and PowerOff:

  1. hold down button on RemotePi for 10 seconds, until the LED flashes red/green
  2. On the Harmony press PowerOn (be in devices and not activity to get the list of all commands)
  3. The LED will flash, then press PowerOff
  4. The LED will flash twice

Telling LibreELEC/Kodi about the remote and its buttons was amazingly easy and involved putting the SD card in a reader (so not on the Pi) and adding one line:

config.txt

dtoverlay=gpio-ir,rc-map-name=rc-rc6-mce

The documentation does say that CEC has to be disabled for an IR remote to work, I wonder if there was some automatic detection going on as I found that CEC stopped working as soon as the RemotePi was installed, in the end it didn’t matter as I knew I would be disabling CEC anyway by going to:

  • System > Settings > System > Input Devices > Peripherals > CEC

Update: Force resolution

After working fine for many weeks, LibreELEC/Kodi started only running at 640×480, I tested with another Pi and something seems to have changed with my television and it wasn’t detecting the resolutions correctly, to get around this I force the Pi to boot up with 1920×1080 by adding the following:

config.txt

hdmi_group=1
hdmi_mode=16

Tagged with: ,