Dim Screen Brightness on Idle

Hello, new Manjaro user here. Really liking the distro.

I have a little linux experience mostly with headless installs using Raspberry PI’s and Proxmox VM’s. Linux as a desktop is all greek, trying to understand the different modules and how everything works together.

Anyway, I picked up a few low-end tablets and loaded Manjaro GNOME edition which appears to be working well. The tablets are intended to be used throughout my house as a touchscreen interface for home automation (Home Assistant). Chose this route of using Linux tablets so they can also run another package to triangulate BLE devices in the house. Network, touchscreen, and screen brightness all worked out of the box. Figured out how to customize the on-screen keyboard, how to make the volume buttons properly and how to load Chromium in full screen mode. That all works great.

The goal is to have the tablets display a webpage (Home Assistant interface) all the time. In Settings → Power, I’ve disabled automatic suspend and set Blank Screen to never. This keeps the tablet logged in and the webpage displayed all the time.

What I’m having a hard time with is lowering the screen brightness when the tablet is idle. I want the screen to stay on and logged in but would like the screen to dim when the tablet hasn’t been used for a few minutes.

I’ve found the following command sets the screen brightness.
echo 2000 | sudo tee /sys/class/backlight/intel_backlight/brightness

However, have not found a command that can print the user idle time in Manjaro GNOME edition. Tried xprintidle but it does not appear to be compatible. Not sure where to look, there doesn’t appear to be a GNOME extension.

Does anyone have an idea how to print the user idle time? Or is there a module that can run a command after X idle seconds?

1 Like

Welcome to the forum!

According to the gnome documentation the functionality is built in gnome all ready: Dim screen when user is idle

Sounds like a cool project you are working on, have fun and hope this helps!

1 Like

Thank you for the help. Tried that in the past and couldn’t get the recommended steps to work.

Found a python script that can obtain the idle time and worked it into a crude auto run script.

nano ~/dimidle.py

#!/usr/bin/env python

import dbus
import subprocess
import os
import time

dim_time = 30               # time to wait before dimming the screen
now_idle = False            # flag to indicate if user is currently idle
idle_brightness = 960       # dimmed screen brightness to set when idle
#brightness_before = "19200" # screen brightness before dimming
brightness_file = "/sys/class/backlight/intel_backlight/brightness"

while True:
  session_bus = dbus.SessionBus()
  bus_object = session_bus.get_object('org.gnome.Mutter.IdleMonitor', '/org/gnome/Mutter/IdleMonitor/Core')
  bus_interface = dbus.Interface(bus_object, 'org.gnome.Mutter.IdleMonitor')
  idle_time = bus_interface.GetIdletime() / 1000
  # print(bus_interface.GetIdletime() / 1000)
  # check if user has gone idle
  if idle_time >= dim_time and now_idle == False:
    # save current brightness
    brightness_before = subprocess.run(["cat", brightness_file], capture_output=True, text=True)

    # dim the screen
    os.system("echo " + str(idle_brightness) + " | sudo tee " + brightness_file)
    now_idle = True
  # check if user has become active
  elif idle_time < dim_time and now_idle == True:
    # set brightness to the value before dimming
    os.system("echo " + str(brightness_before.stdout.rstrip()) + " | sudo tee " + brightness_file)
    now_idle = False

nano ~/.config/autostart/dimidle.desktop

[Desktop Entry]
Exec=python ~/dimidle.py
Name[en_US]=Autostart dimidle.py
Name=Autostart dimidle.py
Comment[en_US]=autostart dimidle.py to dim the screen when idle
Comment=autostart dimidle.py to dim the screen when idle
1 Like

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.