You are not logged in.

#1 2018-06-08 04:12:54

CarterCox
Member
From: Argentina
Registered: 2018-02-24
Posts: 116

[SOLVED]Udev rule to change brightness on charger removal/insertion

Hi guys. I am following this guide, because I want to create udev rules so that every time I insert my AC charger to my laptop, this commands is excecuted:

 /usr/bin/change_brightness.sh
echo "2368695" > /sys/class/brightness/intel_backlight/brightness

And whenever I disconnect it, this one is:

 /usr/bin/change_brightness_low.sh
echo "1000000" > /sys/class/brightness/intel_backlight/brightness

So

/etc/udev/rules.d/10-local.rules
KERNEL=="something", ATTR{connected?}=="yes", RUN+="/usr/bin/change_brightness.sh"
KERNEL=="something", ATTR{connected?}=="no", RUN+="/usr/bin/change_brightness_low.sh"

Where "something" would be the name of the the charger and the ATTR and "yes" and "no" would indicate the status of it (maybe, I don't know, this is hypothetical to make my point).
I know I am supposed to find this using

udevadm info -a -p /sys/path/to/device

But I have no idea what this /path/to/device is.
Does anyone know what the possible path could be?
Thanks!

Solution:

/usr/bin/change_brightness.sh

 #!/bin/bash
sleep 2s
echo "2000000" > /sys/class/backlight/intel_backlight/brightness

/usr/bin/change_brightness_low.sh

#!/bin/bash
sleep 2s
echo "1000000" > /sys/class/backlight/intel_backlight/brightness

/etc/udev/rules.d/99-local.rules

ACTION=="change", SUBSYSTEM=="power_supply", ATTR{online}=="1", RUN+="/usr/bin/change_brightness.sh"
ACTION=="change", SUBSYSTEM=="power_supply", ATTR{online}=="0", RUN+="/usr/bin/change_brightness_low.sh"

Last edited by CarterCox (2018-06-08 21:13:47)


And neither the angels in Heaven above
   Nor the demons down under the sea
Can ever dissever my soul from the soul
   Of the beautiful Annabel Lee;

Offline

#2 2018-06-08 04:43:36

x33a
Forum Fellow
Registered: 2009-08-15
Posts: 4,587

Re: [SOLVED]Udev rule to change brightness on charger removal/insertion

Try /sys/class/power_supply

Offline

#3 2018-06-08 05:45:55

seth
Member
From: Won't reply 2 private help req
Registered: 2012-09-03
Posts: 78,849

Re: [SOLVED]Udev rule to change brightness on charger removal/insertion

You're aware that there's even a backlight centric udev example on https://wiki.archlinux.org/index.php/Udev ?

Offline

#4 2018-06-08 11:14:40

CarterCox
Member
From: Argentina
Registered: 2018-02-24
Posts: 116

Re: [SOLVED]Udev rule to change brightness on charger removal/insertion

@x33a: Yes! That's it! Thanks!

@seth: No, you mean this one?


And neither the angels in Heaven above
   Nor the demons down under the sea
Can ever dissever my soul from the soul
   Of the beautiful Annabel Lee;

Offline

#5 2018-06-08 11:29:19

seth
Member
From: Won't reply 2 private help req
Registered: 2012-09-03
Posts: 78,849

Re: [SOLVED]Udev rule to change brightness on charger removal/insertion

No. Press ctrl+f and search the page for "backlight"…

Offline

#6 2018-06-08 18:14:55

CarterCox
Member
From: Argentina
Registered: 2018-02-24
Posts: 116

Re: [SOLVED]Udev rule to change brightness on charger removal/insertion

@seth: Oh, yeah, I used that example to create mine. I didn't know the values would be the same.

However, it doesn't seem to be working now. This is what I did so far: https://forumshare.duckdns.org/Arch/

I even added a wait time so it will wait for the BIOS changes and then override them.

Last edited by CarterCox (2018-06-08 20:14:21)


And neither the angels in Heaven above
   Nor the demons down under the sea
Can ever dissever my soul from the soul
   Of the beautiful Annabel Lee;

Offline

#7 2018-06-08 18:41:36

seth
Member
From: Won't reply 2 private help req
Registered: 2012-09-03
Posts: 78,849

Re: [SOLVED]Udev rule to change brightness on charger removal/insertion

Did you "udevadm control --reload"?

Offline

#8 2018-06-08 19:29:00

CarterCox
Member
From: Argentina
Registered: 2018-02-24
Posts: 116

Re: [SOLVED]Udev rule to change brightness on charger removal/insertion

@seth: No, I just rebooted. I just tried that and it still doesn't work. I want to clarify that the scripts do change the brigthnless when excecuted alone, so the problem is not there. I increased the sleep time but still doesn't work.


And neither the angels in Heaven above
   Nor the demons down under the sea
Can ever dissever my soul from the soul
   Of the beautiful Annabel Lee;

Offline

#9 2018-06-08 19:35:06

seth
Member
From: Won't reply 2 private help req
Registered: 2012-09-03
Posts: 78,849

Re: [SOLVED]Udev rule to change brightness on charger removal/insertion

That's sufficient.
You should add sth. like "echo foo > /tmp/bar" to ensure they're invoked at all.
Also try "udevadm test /sys/class/power_supply/" and check your journal for errors.

I cannot immedidately spot issues w/ the stuff you posted…

Offline

#10 2018-06-08 20:20:58

CarterCox
Member
From: Argentina
Registered: 2018-02-24
Posts: 116

Re: [SOLVED]Udev rule to change brightness on charger removal/insertion

Ok @seth, thanks for taking the time to review this.
Good suggestion on the journal check. There are actually some errors. Here: https://forumshare.duckdns.org/Arch/journal_udev.txt  Also: https://forumshare.duckdns.org/Arch/cha … ess.sh.txt .


And neither the angels in Heaven above
   Nor the demons down under the sea
Can ever dissever my soul from the soul
   Of the beautiful Annabel Lee;

Offline

#11 2018-06-08 20:34:30

seth
Member
From: Won't reply 2 private help req
Registered: 2012-09-03
Posts: 78,849

Re: [SOLVED]Udev rule to change brightness on charger removal/insertion

Thanks for the individual files. Now google "shebang" ;-)

Offline

#12 2018-06-08 21:07:31

CarterCox
Member
From: Argentina
Registered: 2018-02-24
Posts: 116

Re: [SOLVED]Udev rule to change brightness on charger removal/insertion

seth wrote:

Thanks for the individual files. Now google "shebang" ;-)

You know... I actually saw the "shebang" thing here: http://www.reactivated.net/writing_udev … ternal-run , but I thought it was only for scripts per se (like "if" ... "fi"). I can't believe that was the error.

Thanks a lot seth!

Edit: Updated OP to reflect the solution.

Last edited by CarterCox (2018-06-08 21:11:03)


And neither the angels in Heaven above
   Nor the demons down under the sea
Can ever dissever my soul from the soul
   Of the beautiful Annabel Lee;

Offline

Board footer

Powered by FluxBB