You are not logged in.

#1 2024-09-04 19:28:25

Utini
Member
Registered: 2015-09-28
Posts: 481
Website

[SOLVED] udev rule help needed (power_supply change)

I am trying to run a script based on when my Logitech K400 keyboard is active or inactive.

udev rule:

ACTION=="change", SUBSYSTEM=="power_supply", POWER_SUPPLY_ONLINE=="0", RUN+="/usr/local/bin/on_battery.sh"
ACTION=="change", SUBSYSTEM=="power_supply", POWER_SUPPLY_ONLINE=="1", RUN+="/usr/local/bin/on_ac.sh"

udevadm monitor output when powering off/on the device:

KERNEL[2518.600920] change   /devices/pci0000:00/0000:00:14.0/usb1/1-5/1-5:1.2/0003:046D:C52B.0003/0003:046D:4024.0004/power_supply/hidpp_battery_0 (power_supply)
ACTION=change
DEVPATH=/devices/pci0000:00/0000:00:14.0/usb1/1-5/1-5:1.2/0003:046D:C52B.0003/0003:046D:4024.0004/power_supply/hidpp_battery_0
SUBSYSTEM=power_supply
DEVTYPE=power_supply
POWER_SUPPLY_NAME=hidpp_battery_0
POWER_SUPPLY_TYPE=Battery
POWER_SUPPLY_ONLINE=0
POWER_SUPPLY_STATUS=Unknown
POWER_SUPPLY_SCOPE=Device
POWER_SUPPLY_MODEL_NAME=Wireless Touch Keyboard K400
POWER_SUPPLY_MANUFACTURER=Logitech
POWER_SUPPLY_SERIAL_NUMBER=c8-3b-fd-8c
POWER_SUPPLY_CAPACITY_LEVEL=Unknown
SEQNUM=4236

KERNEL[2521.045047] change   /devices/pci0000:00/0000:00:14.0/usb1/1-5/1-5:1.2/0003:046D:C52B.0003/0003:046D:4024.0004/power_supply/hidpp_battery_0 (power_supply)
ACTION=change
DEVPATH=/devices/pci0000:00/0000:00:14.0/usb1/1-5/1-5:1.2/0003:046D:C52B.0003/0003:046D:4024.0004/power_supply/hidpp_battery_0
SUBSYSTEM=power_supply
DEVTYPE=power_supply
POWER_SUPPLY_NAME=hidpp_battery_0
POWER_SUPPLY_TYPE=Battery
POWER_SUPPLY_ONLINE=1
POWER_SUPPLY_STATUS=Discharging
POWER_SUPPLY_SCOPE=Device
POWER_SUPPLY_MODEL_NAME=Wireless Touch Keyboard K400
POWER_SUPPLY_MANUFACTURER=Logitech
POWER_SUPPLY_SERIAL_NUMBER=c8-3b-fd-8c
POWER_SUPPLY_CAPACITY_LEVEL=Unknown
SEQNUM=4237

KERNEL[2521.145076] change   /devices/pci0000:00/0000:00:14.0/usb1/1-5/1-5:1.2/0003:046D:C52B.0003/0003:046D:4024.0004/power_supply/hidpp_battery_0 (power_supply)
ACTION=change
DEVPATH=/devices/pci0000:00/0000:00:14.0/usb1/1-5/1-5:1.2/0003:046D:C52B.0003/0003:046D:4024.0004/power_supply/hidpp_battery_0
SUBSYSTEM=power_supply
DEVTYPE=power_supply
POWER_SUPPLY_NAME=hidpp_battery_0
POWER_SUPPLY_TYPE=Battery
POWER_SUPPLY_ONLINE=1
POWER_SUPPLY_STATUS=Discharging
POWER_SUPPLY_SCOPE=Device
POWER_SUPPLY_MODEL_NAME=Wireless Touch Keyboard K400
POWER_SUPPLY_MANUFACTURER=Logitech
POWER_SUPPLY_SERIAL_NUMBER=c8-3b-fd-8c
POWER_SUPPLY_CAPACITY_LEVEL=Normal
SEQNUM=4238

KERNEL[2521.306964] change   /devices/pci0000:00/0000:00:14.0/usb1/1-5/1-5:1.2/0003:046D:C52B.0003/0003:046D:4024.0004/power_supply/hidpp_battery_0 (power_supply)
ACTION=change
DEVPATH=/devices/pci0000:00/0000:00:14.0/usb1/1-5/1-5:1.2/0003:046D:C52B.0003/0003:046D:4024.0004/power_supply/hidpp_battery_0
SUBSYSTEM=power_supply
DEVTYPE=power_supply
POWER_SUPPLY_NAME=hidpp_battery_0
POWER_SUPPLY_TYPE=Battery
POWER_SUPPLY_ONLINE=1
POWER_SUPPLY_STATUS=Discharging
POWER_SUPPLY_SCOPE=Device
POWER_SUPPLY_MODEL_NAME=Wireless Touch Keyboard K400
POWER_SUPPLY_MANUFACTURER=Logitech
POWER_SUPPLY_SERIAL_NUMBER=c8-3b-fd-8c
POWER_SUPPLY_CAPACITY_LEVEL=Normal
SEQNUM=4239

It will successfully run the script when the keyboard gets powered off but it won't run the script when the keyboard gets powered on.
Scripts are executable.

What am I missing? :S

Thanks!

Last edited by Utini (2024-09-06 12:37:41)


Setup 1: Thinkpad T14s G3, 14" FHD - R7 6850U - 32GB RAM - 2TB Solidigm P44 Pro NVME
Setup 2: Thinkpad X1E G1, 15.6" FHD - i7-8850H - 32GB RAM - NVIDIA GTX 1050Ti - 2x 1TB Samsung 970 Pro NVME
Accessories: Filco Majestouch TKL MX-Brown Mini Otaku, Benq XL2420T (144Hz), Lo(w)gitech G400, Puretrak Talent, Sennheiser HD800S + Meier Daccord FF + Meier Classic FF

Offline

#2 2024-09-04 21:27:42

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

Re: [SOLVED] udev rule help needed (power_supply change)

Does it not run the script or does the script not do what you want/expect?
Add some telling "date > /tmp/k400_up.txt" to the script.

The udev rule doesn't have any device filters?

Offline

#3 2024-09-05 18:24:36

Utini
Member
Registered: 2015-09-28
Posts: 481
Website

Re: [SOLVED] udev rule help needed (power_supply change)

seth wrote:

Does it not run the script or does the script not do what you want/expect?
Add some telling "date > /tmp/k400_up.txt" to the script.

The udev rule doesn't have any device filters?

It doesn't seem to run the script as the file also won't get created in the /tmp/ folder.
Running the script manually works as intended.

Regarding device filters, I haven't figured out how to make that work correctly yet.
It is a USB dongle that connects to the keyboard via bluetooth.
I want to run a script when the bluetooth keyboard turns off (which happens after x minutes).
And then run a script again when I use the keyboard and wake it up.

Last edited by Utini (2024-09-05 18:25:29)


Setup 1: Thinkpad T14s G3, 14" FHD - R7 6850U - 32GB RAM - 2TB Solidigm P44 Pro NVME
Setup 2: Thinkpad X1E G1, 15.6" FHD - i7-8850H - 32GB RAM - NVIDIA GTX 1050Ti - 2x 1TB Samsung 970 Pro NVME
Accessories: Filco Majestouch TKL MX-Brown Mini Otaku, Benq XL2420T (144Hz), Lo(w)gitech G400, Puretrak Talent, Sennheiser HD800S + Meier Daccord FF + Meier Classic FF

Offline

#4 2024-09-05 19:31:06

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

Re: [SOLVED] udev rule help needed (power_supply change)

udevadm monitor

the events, it should tell you all relevant things to filter and react to.

Offline

#5 2024-09-06 04:21:40

Utini
Member
Registered: 2015-09-28
Posts: 481
Website

Re: [SOLVED] udev rule help needed (power_supply change)

seth wrote:
udevadm monitor

the events, it should tell you all relevant things to filter and react to.

Well the output of that is included in the first post and it shows a change of POWER_SUPPLY_ONLINE to 0/1.

That is why I used it in the udev rule.
The "off" script gets executed but not the "on" script.


Setup 1: Thinkpad T14s G3, 14" FHD - R7 6850U - 32GB RAM - 2TB Solidigm P44 Pro NVME
Setup 2: Thinkpad X1E G1, 15.6" FHD - i7-8850H - 32GB RAM - NVIDIA GTX 1050Ti - 2x 1TB Samsung 970 Pro NVME
Accessories: Filco Majestouch TKL MX-Brown Mini Otaku, Benq XL2420T (144Hz), Lo(w)gitech G400, Puretrak Talent, Sennheiser HD800S + Meier Daccord FF + Meier Classic FF

Offline

#6 2024-09-06 08:37:50

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

Re: [SOLVED] udev rule help needed (power_supply change)

Try

ENV{POWER_SUPPLY_ONLINE}=="0"

but also check for concurrent rules, eg. https://bbs.archlinux.org/viewtopic.php … 6#p1737126
Edit: or "ATTR{online}"

Last edited by seth (2024-09-06 08:39:16)

Offline

#7 2024-09-06 12:37:28

Utini
Member
Registered: 2015-09-28
Posts: 481
Website

Re: [SOLVED] udev rule help needed (power_supply change)

seth wrote:

Try

ENV{POWER_SUPPLY_ONLINE}=="0"

but also check for concurrent rules, eg. https://bbs.archlinux.org/viewtopic.php … 6#p1737126
Edit: or "ATTR{online}"

Thanks, that fixed it! smile

ACTION=="change", SUBSYSTEM=="power_supply", ENV{POWER_SUPPLY_ONLINE}=="0", RUN+="/usr/local/bin/on_battery.sh"
ACTION=="change", SUBSYSTEM=="power_supply", ENV{POWER_SUPPLY_ONLINE}=="1", RUN+="/usr/local/bin/on_ac.sh"

Setup 1: Thinkpad T14s G3, 14" FHD - R7 6850U - 32GB RAM - 2TB Solidigm P44 Pro NVME
Setup 2: Thinkpad X1E G1, 15.6" FHD - i7-8850H - 32GB RAM - NVIDIA GTX 1050Ti - 2x 1TB Samsung 970 Pro NVME
Accessories: Filco Majestouch TKL MX-Brown Mini Otaku, Benq XL2420T (144Hz), Lo(w)gitech G400, Puretrak Talent, Sennheiser HD800S + Meier Daccord FF + Meier Classic FF

Offline

Board footer

Powered by FluxBB