Page 1 of 1

Change screen brightness by hour

Posted: 05 Sep 2018, 17:09
by jet
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

Change screen brightness by hour

Posted: 05 Sep 2018, 17:31
by apollo
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

Change screen brightness by hour

Posted: 05 Sep 2018, 20:32
by jet
" 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

Change screen brightness by hour

Posted: 06 Sep 2018, 18:23
by fanthom
Once you figure out the script part you may program cron as described here:
http://porteus-kiosk.org/faq.html#22

Change screen brightness by hour

Posted: 07 Sep 2018, 13:18
by apollo
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.

Change screen brightness by hour

Posted: 09 Sep 2018, 15:13
by jet
Thanks!

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

Kind regards,
Jan

Change screen brightness by hour

Posted: 12 Sep 2018, 12:10
by jet
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

Change screen brightness by hour

Posted: 12 Sep 2018, 13:18
by fanthom
"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.

Change screen brightness by hour

Posted: 12 Sep 2018, 15:22
by jet
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

Change screen brightness by hour

Posted: 12 Sep 2018, 19:28
by jet
That seems not working, any thoughts?

Change screen brightness by hour

Posted: 13 Sep 2018, 07:09
by fanthom
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).

Change screen brightness by hour

Posted: 18 Sep 2018, 12:19
by jet
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?

Change screen brightness by hour

Posted: 18 Sep 2018, 14:21
by fanthom
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

Change screen brightness by hour

Posted: 19 Sep 2018, 13:18
by jet
Thanks!

Found out that there was a missing $-sign in my script and there were some other issues too..

Now finally got it up and running!

Kind regards,
Jan

Change screen brightness by hour

Posted: 20 Sep 2018, 12:03
by jet
Hi.
How to close and restart the browser (Chrome) from a script?