Based on a project from the Homeassistant commuity
sudo apt-get install libcec-dev build-essential python3-dev python3-pip gitgit clone https://github.com/Josua019/python-cec.gitsudo python3 setup.py installpython3 cecwatcher.pyA log file will be created and the console will output relevant information
Stop the script with Ctrl+C
sudo nano /etc/systemd/system/cecwatcher.serviceupdate the path at 'ExecStart'
# systemd unit file for cecwatcher.py
[Unit]
Description=CEC Watcher
[Service]
ExecStart=/usr/bin/python3 /home/pi/Documents/python-cec/cecwatcher.py
# Disable Python's buffering of STDOUT and STDERR, so that output from the
# service shows up immediately in systemd's logs
Environment=PYTHONUNBUFFERED=1
User=pi
[Install]
# Tell systemd to automatically start this service when the system boots
# (assuming the service is enabled)
WantedBy=default.targetsudo systemctl start cecwatcher
sudo systemctl status cecwatchersudo systemctl enable cecwatcherIf status shows an error try fixing it, run
sudo systemctl reset-failedand resart the service