scmanjarrez/lirc
Containerized version of LIRC (no need to install on host). Optionally, it can send data to MQTT
85
This repository arose from my own needs to run LIRC with HomeAssistant, but I didn't want to install LIRC. I have prepared two containers:
scmanjarrez/lirc
irsend
using payload data, hosted in dockerhub at scmanjarrez/lirc:mqtt
Source code repository: https://github.com/scmanjarrez/lirc-docker
You need to enable the kernel driver for IR in case you're running the container in a raspberry pi (my case).
Add the following line to your /boot/firmware/config.txt
or
/boot/config.txt
(depending of your OS)
dtoverlay=gpio-ir,gpio_pin=17 # receiver
dtoverlay=gpio-ir-tx,gpio_pin=18 # transmitter
You need to run the container as --privileged
so it can have access
to required dependencies (e.g. devices). You also need to bind
the configuration file to be used:
docker run --rm --privileged -v ./path2cfg:/usr/etc/lirc/lircd.conf.d/cfg_name <container> <command>
I have tried lot of methods to avoid the usage of
--privileged
without much success (I'm not too versed about linux internals). Let me know if you find a way to give the minimal permissions to the container 🙂
docker run --rm --privileged \
-v ./path2cfg:/usr/etc/lirc/lircd.conf.d/cfg_name \
scmanjarrez/lirc <command>
docker run --rm --privileged \
-v ./leds.lircd.conf:/usr/etc/lirc/lircd.conf.d/leds.lircd.conf \
scmanjarrez/lirc irsend SEND_ONCE leds KEY_ON
You need to define a set of environment variables so MQTT client can connect to broker and subscribe to the topic:
docker run --rm --privileged \
-v ./path2cfg:/usr/etc/lirc/lircd.conf.d/cfg_name \
-e MQTT_HOST=<broker_hostname/ip> \
-e MQTT_PORT=<broker_port/ip> \
-e MQTT_USER=<user> \
-e MQTT_PASS=<passwd> \
-e MQTT_TOPIC=<topic> \
scmanjarrez/lirc:mqtt
docker run --rm --privileged \
-v ./leds.lircd.conf:/usr/etc/lirc/lircd.conf.d/leds.lircd.conf \
-e MQTT_HOST=mqtt \
-e MQTT_PORT=1884 \
-e MQTT_USER=hass \
-e MQTT_PASS=strong_password \
-e MQTT_TOPIC=lirc \
scmanjarrez/lirc:mqtt
Note: You can skip any environment, the default value will be used instead:
MQTT_HOST: localhost MQTT_PORT: 1883 MQTT_USER: None # No authentication required ("allow_anonymous true" if using eclipse-mosquitto) MQTT_PASS: None MQTT_TOPIC: lirc
The payload must be a json with the following format:
{
"rc": "remote-name",
"key": "key-name, without KEY_"
}
{
"rc": "leds",
"key": "ON"
}
This is a small example for running with HomeAssistant, I'm using the default topic of the container to send messages: lirc
{"rc": "leds", "key": "ON"}
version: '3'
services:
hass:
image: ghcr.io/home-assistant/home-assistant:stable
network_mode: "host"
privileged: true
volumes:
- /etc/localtime:/etc/localtime:ro
- /run/dbus:/run/dbus:ro
- ./hass-config:/config
depends_on:
- mqtt
restart: unless-stopped
mqtt:
image: eclipse-mosquitto:latest
volumes:
- /etc/localtime:/etc/localtime:ro
- ./mqtt-config:/mosquitto/config # already configured with allow_anonymous false
- ./mqtt-data:/mosquitto/data
- ./mqtt-log:/mosquitto/log
ports:
- 1883:1883
- 9001:9001
restart: unless-stopped
lirc:
image: scmanjarrez/lirc:mqtt
privileged: true
environment:
- MQTT_HOST=mqtt
- MQTT_USER=hass
- MQTT_PASS=strong_password
volumes:
- ./leds.lircd.conf:/usr/etc/lirc/lircd.conf.d/leds.lircd.conf
depends_on:
- mqtt
restart: unless-stopped
docker pull scmanjarrez/lirc