Change screen brightness by hour

'User made' tutorials related to Porteus Kiosk edition.
Official kiosk documentation can be find here: http://porteus-kiosk.org/documentation.html
Post Reply
jet
White ninja
White ninja
Posts: 22
Joined: 10 Feb 2015, 21:49
Distribution: Kiosk
Location: Finland

Change screen brightness by hour

Post#1 by jet » 05 Sep 2018, 17:09

How to change screen brightness by hour?

For as an example one would like the screen have 100 brightness 10:00 and dim it after 20:00 to 75%

Kind regards,
Jan

apollo
Black ninja
Black ninja
Posts: 72
Joined: 28 Oct 2017, 13:40
Distribution: 4.0 XFCE, Manjaro
Location: .bay.de
Contact:

Change screen brightness by hour

Post#2 by apollo » 05 Sep 2018, 17:31

Screen brightness can be set by pushing a value to a specific file, you may need to look up how your device is named, for me its "amdgpu_bl0".

Code: Select all

/sys/class/backlight/<your_device>/brightness
you can write a short script that pushes a value depending on daytime and let this script execute by a cron job every 15 minutes or whatever you need. i can provide a small sample script later if you need
My Porteus Module Repo: https://porteus.rw-net.de

jet
White ninja
White ninja
Posts: 22
Joined: 10 Feb 2015, 21:49
Distribution: Kiosk
Location: Finland

Change screen brightness by hour

Post#3 by jet » 05 Sep 2018, 20:32

" i can provide a small sample script later if you need"

Yes please, send example.

How to obtain the device screen name? Is there a common alias (for the primary screen) that could be used directly?

Kind regads,
Jan

User avatar
fanthom
Site Admin
Site Admin
Posts: 4831
Joined: 28 Dec 2010, 02:42
Distribution: Porteus Kiosk
Location: Poland, currently - Cork, IE
Contact:

Change screen brightness by hour

Post#4 by fanthom » 06 Sep 2018, 18:23

Once you figure out the script part you may program cron as described here:
http://porteus-kiosk.org/faq.html#22
Please add [Solved] to your thread title if the solution was found.

apollo
Black ninja
Black ninja
Posts: 72
Joined: 28 Oct 2017, 13:40
Distribution: 4.0 XFCE, Manjaro
Location: .bay.de
Contact:

Change screen brightness by hour

Post#5 by apollo » 07 Sep 2018, 13:18

A very short sample script could look like this:

Code: Select all

#!/bin/bash
HOUR=`date +%H`

# replace the values with the hours you want to change the brightness
# for easier comparing we use the 24-hours-scheme
if (( $HOUR < 8 )) || (( $HOUR > 13 )); then
    # replace with the required brightness value
    BRIGHT=50
else
    # replace with the required brightness value
    BRIGHT=100
fi

# replace "radeon_bl0" with the corresponding dir on your system
echo $BRIGHT | tee /sys/class/backlight/radeon_bl0/brightness
You need to replace the hours and brightness values to something that matches your need.
Instead of directly tee-ing to a specified file, you could enumerate through the directories in /sys/class/backlight/ and set it for all displays. If i have time later i will add this to the script.
My Porteus Module Repo: https://porteus.rw-net.de

jet
White ninja
White ninja
Posts: 22
Joined: 10 Feb 2015, 21:49
Distribution: Kiosk
Location: Finland

Change screen brightness by hour

Post#6 by jet » 09 Sep 2018, 15:13

Thanks!

Yes, would be very nice to have the script to enumerate through the directories in /sys/class/backlight/

Kind regards,
Jan

jet
White ninja
White ninja
Posts: 22
Joined: 10 Feb 2015, 21:49
Distribution: Kiosk
Location: Finland

Change screen brightness by hour

Post#7 by jet » 12 Sep 2018, 12:10

fanthom wrote:
06 Sep 2018, 18:23
Once you figure out the script part you may program cron as described here:
http://porteus-kiosk.org/faq.html#22
Hi.
Is there any other way to inject the script to cron?
Can it be loaded and included to Porteus Kiosk thru run_command and wget?

Kind regards,
Jan

User avatar
fanthom
Site Admin
Site Admin
Posts: 4831
Joined: 28 Dec 2010, 02:42
Distribution: Porteus Kiosk
Location: Poland, currently - Cork, IE
Contact:

Change screen brightness by hour

Post#8 by fanthom » 12 Sep 2018, 13:18

"Can it be loaded and included to Porteus Kiosk thru run_command and wget?"
I believe you could download and replace whole /etc/crontab file with 'run_command='.

Let us know if this method works so i'll update the FAQ.
Please add [Solved] to your thread title if the solution was found.

jet
White ninja
White ninja
Posts: 22
Joined: 10 Feb 2015, 21:49
Distribution: Kiosk
Location: Finland

Change screen brightness by hour

Post#9 by jet » 12 Sep 2018, 15:22

Any help such as exact commands would be helpful.

Thanks :)

I assume I have to put something like this to run_command=

Code: Select all

wget https://domain.com/files/script.sh -O /home/script.sh; chown -R 1000:1000 /home/script.sh; chmod +X /home/script.sh; echo '* * * * * root su - -c "/home/script.sh" '  >> /etc/crontab;
Kind regards,
Jan

jet
White ninja
White ninja
Posts: 22
Joined: 10 Feb 2015, 21:49
Distribution: Kiosk
Location: Finland

Change screen brightness by hour

Post#10 by jet » 12 Sep 2018, 19:28

That seems not working, any thoughts?

User avatar
fanthom
Site Admin
Site Admin
Posts: 4831
Joined: 28 Dec 2010, 02:42
Distribution: Porteus Kiosk
Location: Poland, currently - Cork, IE
Contact:

Change screen brightness by hour

Post#11 by fanthom » 13 Sep 2018, 07:09

I though you want to update crontab file.

Anyway - this is enough to run the script:

Code: Select all

wget https://domain.com/files/script.sh -O /home/script.sh; echo '* * * * * root su - -c "sh /home/script.sh"'  >> /etc/crontab;
Mind it will be executed by root every minute.

Also - its better to download files to /opt as /home may be refreshed (depends on your persistence level).
Please add [Solved] to your thread title if the solution was found.

jet
White ninja
White ninja
Posts: 22
Joined: 10 Feb 2015, 21:49
Distribution: Kiosk
Location: Finland

Change screen brightness by hour

Post#12 by jet » 18 Sep 2018, 12:19

Hi. Thanks!

The executing seems to work, but I think permissions (and owner?) should be changed for /sys/class/backlight/ to be able to read and modify the brightness file?

User avatar
fanthom
Site Admin
Site Admin
Posts: 4831
Joined: 28 Dec 2010, 02:42
Distribution: Porteus Kiosk
Location: Poland, currently - Cork, IE
Contact:

Change screen brightness by hour

Post#13 by fanthom » 18 Sep 2018, 14:21

With this configuration:

Code: Select all

* * * * * root
You have instructed the cron to run the command as root.

You may add following line to your script to confirm this:

Code: Select all

whoami >> /opt/script.log
Please add [Solved] to your thread title if the solution was found.

Post Reply