HDMI CEC

The hdmi_cec integration provides services that allow selecting the active device, powering on all devices, setting all devices to standby and creates switch entities for HDMI devices. Devices are defined in the configuration file by associating HDMI port number and a device name. Connected devices that provide further HDMI ports, such as sound-bars and AVRs are also supported. Devices are listed from the perspective of the CEC-enabled Home Assistant device. Any connected device can be listed, regardless of whether it supports CEC. Ideally the HDMI port number on your device will map correctly the CEC physical address. If it does not, use cec-client (part of the libcec package) to listen to traffic on the CEC bus and discover the correct numbers.

CEC Setup

Adapter

The computer running Home Assistant must support CEC, and of course be connected via HDMI to a device also supporting CEC. You can purchase a USB CEC adapter to add support if necessary. Note that all Raspberry Pi models support CEC natively.

libcec

libcec must be installed for this integration to work. Follow the installation instructions for your environment, provided at the link. libcec installs Python 3 bindings by default as a system Python module. If you are running Home Assistant in a Python virtual environment, make sure it can access the system module, by either symlinking it or using the --system-site-packages flag.

If you are using Hass.io then just move forward to the configuration as all requirements are already fulfilled.

Symlinking into virtual environment

Create a symlink to the cec installation including the _cec.so file. Keep in mind different installation methods will result in different locations of cec.

If after symlinking and adding hdmi_cec: to your configuration you are getting the following error in your logs,
* failed to open vchiq instance you will also need to add the user account Home Assistant runs under, to the video group. To add the Home Assistant user account to the video group, run the following command. $ usermod -a -G video <hass_user_account>

Another option you can use in config is platform which specifying of default platform of HDMI devices. “switch” and “media_player” are supported. Switch is default.

hdmi_cec:
platform: media_player

Then you set individual platform for devices in customizations:

hdmi_cec:
types:
hdmi_cec.hdmi_5: media_player

And the last option is host. PyCEC supports bridging CEC commands over TCP. When you start pyCEC on machine with HDMI port (python -m pycec), you can then run homeassistant on another machine and connect to CEC over TCP. Specify TCP address of pyCEC server:

hdmi_cec:
host: 192.168.1.3

Services

Select Device

Call the hdmi_cec.select_device service with the name of the device from config or entity_id or physical address”to select it, for example:

{"device": "Chromecast"}

{"device": "switch.hdmi_3"}

{"device": "1.1.0.0"}

So an Automation action using the example above would look something like this.

action:
service: hdmi_cec.select_device
data:
device: Chromecast

Power On

Call the hdmi_cec.power_on service (no arguments) to power on any devices that support this function.

An Automation action using the example above would look something like this.

action:
service: hdmi_cec.power_on

Standby

Call the hdmi_cec.standby service (no arguments) to place in standby any devices that support this function.

An Automation action using the example above would look something like this.