Simple mqtt command executor to turn screen on or off via MQTT
.gitignore | ||
go.mod | ||
go.sum | ||
main.go | ||
README.md |
MQTT backlight control
Simple mqtt command executor to turn screen on or off via MQTT.
Config example:
mqtt:
address: "tcp://example.com:1883"
username: "mqtt"
password: "${MQTT_PASSWORD}"
command_topic: "light/screen/command"
state_topic: "light/screen/state"
commands:
on:
program: "xrandr"
args:
- "--display"
- ":0"
- "--output"
- "HDMI-0"
- "--auto"
off:
program: "xrandr"
args:
- "--display"
- ":0"
- "--output"
- "HDMI-0"
- "--off"
Password is provided via MQTT_PASSWORD environment variable.
Usage:
mqtt-backlight-control config.yaml
Systemd unit example:
[Unit]
Description=Control screen backlight via mqtt
After=network-online.target
StartLimitIntervalSec=500
StartLimitBurst=5
[Service]
Type=simple
User=mqtt_backlight_control
Environment=MQTT_PASSWORD=xxxxxxxxxxxxx
WorkingDirectory=/opt/backlight-control/
ExecStart=/opt/backlight-control/mqtt-backlight-control config.yaml
Restart=on-failure
RestartSec=5s
[Install]
WantedBy=multi-user.target