Simple mqtt command executor to turn screen on or off via MQTT
Go to file
2024-05-08 09:22:24 +03:00
.gitignore First commit 2024-05-08 09:22:24 +03:00
go.mod First commit 2024-05-08 09:22:24 +03:00
go.sum First commit 2024-05-08 09:22:24 +03:00
main.go First commit 2024-05-08 09:22:24 +03:00
README.md First commit 2024-05-08 09:22:24 +03:00

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