electroflame / homebridge-cec-tv-control

MIT License
5 stars 3 forks source link

homebridge-cec-tv-control

NPM version License

Homebridge support for controlling a TV via HDMI-CEC commands. Requires Homebridge 1.3.1 or greater.

IMPORTANT

This is very much a work-in-progress. Bugs are to be expected.

Javascript and Typescript are not my main languages -- pointers, tips, and input are all welcome!

Installation

  1. This is a plugin for Homebridge, so you'll need to install homebridge if you haven't already. Be sure to install Node and NPM as well.
  2. Install the plugin using NPM: sudo npm install -g homebridge-cec-tv-control
    • (Unless in hb-shell environment, then type hb-service add homebridge-cec-tv-control instead).
  3. Install the cec-utils package if the cec-client command is not present in your terminal: sudo apt-get install cec-utils
    • Additionally, cec-utils might not be available based on what distribution you're using. You can also search for libCEC, as that might be packaged and available in your package manager.
    • On Raspberry Pi's OSMC image, cec-cilent is present at /usr/osmc/bin/cec-client-4.0.2, you'll need to run sudo ln -s /usr/osmc/bin/cec-client-4.0.2 /usr/bin/cec-client to link it to the default $PATH
  4. Add the TVCECControl platform to your configuration file. If you're using homebridge-ui-x you should be able to configure this right in the UI. Otherwise, you can see an example configuration below.
  5. Since this plugin gets registered as an External Accessory in Homebridge, you'll need to register it manually and input your Homebridge authentication code to link it. More information is output in the Homebridge log when the plugin is loaded.

Config

platforms": [
    {
        "name": "CEC TV",
        "manufacturer": "TVMaker",
        "model": "Best",
        "serialNumber": "CECTV01",
        "firmwareRevision": "1.0",
        "pollingInterval": 2500,
        "minimizeLogging": false,
        "inputs": [
            {
                "inputNumber": 1,
                "displayName": "Apple TV"
            },
            {
                "inputNumber": 2,
                "displayName": "Raspberry Pi"
            },
            {
                "inputNumber": 3,
                "displayName": "Xbox"
            },
            {
                "inputNumber": 4,
                "displayName": "Playstation"
            }
        ],
        "useActiveSource": true,
        "useInactiveSource": true,
        "useSourceRouting": true,
        "useSetStreamPath": true,
        "platform": "TVCECControl"
    }
]

Notes on HDMI Input Switching

HDMI-CEC is complicated, and switching HDMI Inputs seems to vary wildly depending on how manufacturers implement the HDMI-CEC spec. The Source Routing and Set Stream Path options are great ways to try and "brute force" input switches beyond the default Active Source and Inactive Source commands that the plugin tries first. Both options can be enabled at the same time, as a delay is inserted before each type of command is used. However, if input switching still doesn't work with both options enabled I'm not aware of any other options. Sorry!

Additionally, you're in full control of what HDMI-CEC frames (commands) are sent in regards to input switching. What works well for one TV may not work at all on another one. The Active Source and Inactive Source commands should generally be the most stable to use, but if you only have two inputs in-use Active Source may cause issues due to the TV automatically switching to the only other available input when Inactive Source is sent. If your TV flickers between two inputs, disabling Active Source (and possibly Inactive Source) could fix it.

Device Stop Responding?

The cec-client can sometimes crash, or be given bad information from other devices in the chain leading to an error or segmentation fault. If this happens, it may lock up, or freeze, causing the TV accessory to become unresponsive. Restarting the cec-client, or rebooting the host (Raspberry Pi, etc.) should resolve the issue. This shouldn't happen under normal circumstances, but it's something to be aware of!

Based on Dominick Han's homebridge-tv-cec plugin

Uses cec-client, which is part of Pulse-Eight's libCEC.