This service can be used to control the backlight of a raspberrypi (touchscreen) e.g. the official 7" touchsceen via mqtt.
The default config works with homeassistant if used with the config example for home assistant below. (You just have
to enter your mqtt broker info)
The project uses the systemd package, so it will run automatically on startup and restart upon error. The script publishes the current
state of power and brightness every 10 seconds.
- clone this repository to your raspberry pi
git clone https://github.com/tofuSCHNITZEL/rpi-screenbrightness-mqtt
- run installer
sudo ./rpi-screenbrightness-mqtt/install.sh
- edit config and enter your mqtt broker info and optional change the control and state topics you can use "${HOSTNAME}" in clientid, state_topic, command_topic, brightness_state_topic, brightness_command_topic and it will be replaced by the hostname of the device
sudo nano /etc/rpi_screenbrightness_mqtt.conf
- to enable debug output set "debug" to True or 1 in
/etc/rpi_screenbrightness_mqtt.conf
you can find the logs via `sudo journalctl -u rpi_screenbrightness_mqtt.service' - you can check the status with
sudo systemctl status rpi_screenbrightness_mqtt
or restart the service withsudo systemctl restart rpi_screenbrightness_mqtt
since version 0.7.0 the backlight should be automatically added to home assistant via MQTT discovery. Check your entities for something named: "light.rpi_screenbacklight_....."
To add it manually use the following configuration:
light:
- platform: mqtt
name: "dashboard backlight"
state_topic: "stat/rpi1/power"
command_topic: "cmnd/rpi1/power"
brightness_state_topic: "stat/rpi1/brightness"
brightness_command_topic: "cmnd/rpi1/brightness"
brightness_scale: 100