Remote PyCec with RPI (Zero 2) Buster

Just had some fun trying to get a remote pycec container running on a pi zero 2 , so I thought I would share my experiences

Background, I already have pycec running locally, as an addon, using GitHub - samueltardieu/homeassistant-addon-pi-cec: HomeAssistant add-on to expose Raspberry Pi HDMI CEC - I’ve forked that at GitHub - barneyman/homeassistant-addon-pi-cec: HomeAssistant add-on to expose Raspberry Pi HDMI CEC which is what this based on

I then wanted to control another TV & Amp that was in another room, using a Zero2 i had gathering dust, as a docker container so i could rinse and repeat (using my Docker registry)

  • Burn a lite version of Buster, using the Raspberry Imager
    • Give it a sensible name, wifi creds & enable SSH
  • SSH to it
  • update it
    • sudo apt update && sudo apt upgrade && sudo apt install git
  • install docker
    • curl -fsSL https://get.docker.com -o get-docker.sh && sudo sh get-docker.sh
  • add yourself to the docker group
    • sudo usermod -aG docker $USER
  • Log out, log in (for the OS to re-eval your new group membership)
  • Clone my fork (specifically for my ‘helper’ shell scripts)
    • git clone https://github.com/barneyman/homeassistant-addon-pi-cec.git && cd homeassistant-addon-pi-cec
  • build the docker image - this will take a ‘a cup of tea’
    • sh ./build.sh
  • disable DRM VC4 V3D driver in /boot/config.txt (pycec needs tvservice which this driver disables)
    • sudo nano /boot/config.txt - find Enable DRM VC4 V3D driver and comment out that section
  • while in that file, turn off the ‘rpi switches TV input when it reboots’ by adding hdmi_ignore_cec_init=1
  • reboot
  • log back in, cd homeassistant-addon-pi-cec
  • run the test - you may see a few deprecation warnings but no assertions or strange behaviour
    • sh ./runtest.sh
  • edit your configuration.yaml
    • add an hdmi_cec section with a host entry (details in my repo Readme.md, the host is your rpi hostname)
  • restart your HA
  • you should now have a bunch of switch.hdmi_? entities
  • when you’re happy that’s worked, kill the runtest.sh above execute run.sh which will make it persistent across boots
    • beware! HA will vomit errors when pycec disappears, another reboot of HA won’t hurt

I hope this saves someone the 3 hours it took me to get it going

1 Like