lad1337 / cec2mqtt

cec mqtt bridge

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

cec2mqtt

A HDMI-CEC to MQTT bridge for connecting your AV-devices to your Home Automation system. You can control and monitor power status and volume.

Features

  • Power feedback (given every ~10sec)
  • Power control
  • Volume control

Dependencies

MQTT

HDMI-CEC

Instalation

pip install cec2mqtt

Usage

Run

$ cec2mqtt run

Runs the bridge in forground with info logging.

$ cec2mqtt run --config /etc/cec2mqtt/config.yaml

Runs the bridge in forground using the config at /etc/cec2mqtt/config.yaml (default)

See more with cec2mqtt --help

Generate config for homekit2mqtt

You can generate a config section for homekit2mqtt with: $ cec2mqtt homekit2mqtt This prints a switch-service config for all currently connected cec devices.

Check CEC devices

$ cec2mqtt cecdevices will print some cec device information.

MQTT Topics

Subscribtion

The bridge subscribes to cec/set/# (by default)

This can be set in the config on the key mqtt.topic_subscribe_prefix. It will define everything before the wildcard /#. E.g. topic_subscribe_prefix = foo/bar will subscribe to foo/bar/#

Following topics are understood:

topic (behind the prefix) body remark
power/<id> on / standby set power state of device
active/<id> make the device "active"
volume up / down volume up and down

<id> referes to the logical cec id (TV is always 0)

Publishing

The bridge publishes to cec/status (by default):

This can be set in the config on the key mqtt.topic_publish_prefix. It will define everything before the wildcard /#. E.g. topic_publish_prefix = foo/bar will publish to foo/bar/#

topic (behind the prefix) body remark
power/<id> on / standby

<id> referes to the logical cec id (TV is always 0)

Config

Default config location is at etc/cec2mqtt/config.yaml (this file may not exists)

Default config is:

name: CEC2MQTT
mqtt:
  host: localhost
  port: 8883
  username:
  password:
  topic_subscribe_prefix: cec/set
  topic_publish_prefix: cec/status
cec:
  id: 1
  port:
  devices: [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15]

Most cases you just want to set cec.devices to the list of device ids you have (try cec2mqtt cecdevices)

Service File Example

[Unit]
Description=cec mqtt bridge
After=syslog.target network.target

[Service]
Type=simple
PIDFile=/var/cec2mqtt/cec2mqtt.pid
ExecStart=/home/pi/.virtualenvs/cec/bin/cec2mqtt run
Restart=on-failure

[Install]
WantedBy=multi-user.target

Interesting links

About

cec mqtt bridge


Languages

Language:Python 100.0%