Debian 10 udev rule not matching for bluetooth keyboard connect event

I'm trying to detect when a bluetooth keyboard is connected via a udev rule. I'm on debian buster.

$ udevadm --version

241
$ cat /lib/udev/rules.d/98-bt-rules

SUBSYSTEM=="input", ACTION=="add", ENV{UNIQ}="34:88:5d:c8:51:50", RUN+="/usr/bin/wall test"

ATTR{uniq} / ATTRS{uniq} / ATTR{UNIQ} don't work either.

Here are the logs from udevadm monitor when I turn on the keyboard and connect it:

monitor will print the received events for:
UDEV - the event which udev sends out after rule processing

UDEV  [53071.875294] add      /devices/pci0000:00/0000:00:14.0/usb3/3-10/3-10:1.0/bluetooth/hci0/hci0:256 (bluetooth)
ACTION=add
DEVPATH=/devices/pci0000:00/0000:00:14.0/usb3/3-10/3-10:1.0/bluetooth/hci0/hci0:256
SUBSYSTEM=bluetooth
DEVTYPE=link
SEQNUM=11330
USEC_INITIALIZED=53071874990
SYSTEMD_ALIAS=/sys/subsystem/bluetooth/devices/hci0:256
SYSTEMD_WANTS=bluetooth.target
TAGS=:systemd:

UDEV  [53072.058271] add      /devices/pci0000:00/0000:00:14.0/usb3/3-10/3-10:1.0/bluetooth/hci0/hci0:256/0005:046D:B342.002B (hid)
ACTION=add
DEVPATH=/devices/pci0000:00/0000:00:14.0/usb3/3-10/3-10:1.0/bluetooth/hci0/hci0:256/0005:046D:B342.002B
SUBSYSTEM=hid
HID_ID=0005:0000046D:0000B342
HID_NAME=Keyboard K380
HID_PHYS=cc:f9:e4:9e:e5:52
HID_UNIQ=34:88:5d:c8:51:50
MODALIAS=hid:b0005g0001v0000046Dp0000B342
SEQNUM=11331
USEC_INITIALIZED=53072057996
DRIVER=hid-generic

UDEV  [53072.062746] add      /devices/pci0000:00/0000:00:14.0/usb3/3-10/3-10:1.0/bluetooth/hci0/hci0:256/0005:046D:B342.002B/input/input179 (input)
ACTION=add
DEVPATH=/devices/pci0000:00/0000:00:14.0/usb3/3-10/3-10:1.0/bluetooth/hci0/hci0:256/0005:046D:B342.002B/input/input179
SUBSYSTEM=input
PRODUCT=5/46d/b342/4201
NAME="Keyboard K380 Keyboard"
PHYS="cc:f9:e4:9e:e5:52"
UNIQ="34:88:5d:c8:51:50"
PROP=0
EV=120013
KEY=1000000000007 ff9f207ac14057ff febeffdfffefffff fffffffffffffffe
MSC=10
LED=1f
MODALIAS=input:b0005v046DpB342e4201-e0,1,4,11,14,k71,72,73,74,75,77,79,7A,7B,7C,7D,7E,7F,80,81,82,83,84,85,86,87,88,89,8A,8C,8E,96,98,9E,9F,A1,A3,A4,A5,A6,AD,B0,B1,B2,B3,B4,B7,B8,B9,BA,BB,BC,BD,BE,BF,C0,C1,C2,F0,ram4,l0,1,2,3,4,sfw
SEQNUM=11334
USEC_INITIALIZED=53072062339
ID_INPUT=1
ID_INPUT_KEY=1
ID_INPUT_KEYBOARD=1
ID_BUS=bluetooth
ID_PATH=pci-0000:00:14.0-usb-0:10:1.0
ID_PATH_TAG=pci-0000_00_14_0-usb-0_10_1_0
ID_FOR_SEAT=input-pci-0000_00_14_0-usb-0_10_1_0
TAGS=:seat:

UDEV  [53072.063389] add      /devices/pci0000:00/0000:00:14.0/usb3/3-10/3-10:1.0/bluetooth/hci0/hci0:256/0005:046D:B342.002B/input/input180 (input)
ACTION=add
DEVPATH=/devices/pci0000:00/0000:00:14.0/usb3/3-10/3-10:1.0/bluetooth/hci0/hci0:256/0005:046D:B342.002B/input/input180
SUBSYSTEM=input
PRODUCT=5/46d/b342/4201
NAME="Keyboard K380 Consumer Control"
PHYS="cc:f9:e4:9e:e5:52"
UNIQ="34:88:5d:c8:51:50"
PROP=0
EV=1b
KEY=40000000000000 0 2000000 103840000800 1e000000000000 0
ABS=10000000000
MSC=10
MODALIAS=input:b0005v046DpB342e4201-e0,1,3,4,k71,72,73,74,8B,9E,A3,A4,A5,AC,D9,176,ra28,m4,lsfw
SEQNUM=11345
USEC_INITIALIZED=53072063006
ID_INPUT=1
ID_INPUT_KEY=1
ID_BUS=bluetooth
ID_PATH=pci-0000:00:14.0-usb-0:10:1.0
ID_PATH_TAG=pci-0000_00_14_0-usb-0_10_1_0
ID_FOR_SEAT=input-pci-0000_00_14_0-usb-0_10_1_0
TAGS=:seat:

UDEV  [53072.063982] add      /devices/pci0000:00/0000:00:14.0/usb3/3-10/3-10:1.0/bluetooth/hci0/hci0:256/0005:046D:B342.002B/hidraw/hidraw1 (hidraw)
ACTION=add
DEVPATH=/devices/pci0000:00/0000:00:14.0/usb3/3-10/3-10:1.0/bluetooth/hci0/hci0:256/0005:046D:B342.002B/hidraw/hidraw1
SUBSYSTEM=hidraw
DEVNAME=/dev/hidraw1
SEQNUM=11349
USEC_INITIALIZED=53072063646
MAJOR=250
MINOR=1

UDEV  [53072.064120] add      /devices/pci0000:00/0000:00:14.0/usb3/3-10/3-10:1.0/bluetooth/hci0/hci0:256/0005:046D:B342.002B/input/input181 (input)
ACTION=add
DEVPATH=/devices/pci0000:00/0000:00:14.0/usb3/3-10/3-10:1.0/bluetooth/hci0/hci0:256/0005:046D:B342.002B/input/input181
SUBSYSTEM=input
PRODUCT=5/46d/b342/4201
NAME="Keyboard K380 System Control"
PHYS="cc:f9:e4:9e:e5:52"
UNIQ="34:88:5d:c8:51:50"
PROP=0
EV=13
KEY=4000 0 0
MSC=10
MODALIAS=input:b0005v046DpB342e4201-e0,1,4,k8E,ram4,lsfw
SEQNUM=11347
USEC_INITIALIZED=53072063592
ID_INPUT=1
ID_INPUT_KEY=1
ID_BUS=bluetooth
ID_PATH=pci-0000:00:14.0-usb-0:10:1.0
ID_PATH_TAG=pci-0000_00_14_0-usb-0_10_1_0
ID_FOR_SEAT=input-pci-0000_00_14_0-usb-0_10_1_0
TAGS=:seat:

UDEV  [53072.065337] add      /devices/pci0000:00/0000:00:14.0/usb3/3-10/3-10:1.0/bluetooth/hci0/hci0:256/0005:046D:B342.002B/input/input179/input179::numlock (leds)
ACTION=add
DEVPATH=/devices/pci0000:00/0000:00:14.0/usb3/3-10/3-10:1.0/bluetooth/hci0/hci0:256/0005:046D:B342.002B/input/input179/input179::numlock
SUBSYSTEM=leds
SEQNUM=11335
USEC_INITIALIZED=53072065225

UDEV  [53072.066937] add      /devices/pci0000:00/0000:00:14.0/usb3/3-10/3-10:1.0/bluetooth/hci0/hci0:256/0005:046D:B342.002B/input/input179/input179::capslock (leds)
ACTION=add
DEVPATH=/devices/pci0000:00/0000:00:14.0/usb3/3-10/3-10:1.0/bluetooth/hci0/hci0:256/0005:046D:B342.002B/input/input179/input179::capslock
SUBSYSTEM=leds
SEQNUM=11337
USEC_INITIALIZED=53072066833

UDEV  [53072.067687] add      /devices/pci0000:00/0000:00:14.0/usb3/3-10/3-10:1.0/bluetooth/hci0/hci0:256/0005:046D:B342.002B/power_supply/hid-34:88:5d:c8:51:50-battery/wakeup64 (wakeup)
ACTION=add
DEVPATH=/devices/pci0000:00/0000:00:14.0/usb3/3-10/3-10:1.0/bluetooth/hci0/hci0:256/0005:046D:B342.002B/power_supply/hid-34:88:5d:c8:51:50-battery/wakeup64
SUBSYSTEM=wakeup
SEQNUM=11332
USEC_INITIALIZED=53072067586

UDEV  [53072.068104] add      /devices/pci0000:00/0000:00:14.0/usb3/3-10/3-10:1.0/bluetooth/hci0/hci0:256/0005:046D:B342.002B/input/input179/input179::scrolllock (leds)
ACTION=add
DEVPATH=/devices/pci0000:00/0000:00:14.0/usb3/3-10/3-10:1.0/bluetooth/hci0/hci0:256/0005:046D:B342.002B/input/input179/input179::scrolllock
SUBSYSTEM=leds
SEQNUM=11339
USEC_INITIALIZED=53072068014

UDEV  [53072.068756] add      /devices/pci0000:00/0000:00:14.0/usb3/3-10/3-10:1.0/bluetooth/hci0/hci0:256/0005:046D:B342.002B/input/input179/input179::compose (leds)
ACTION=add
DEVPATH=/devices/pci0000:00/0000:00:14.0/usb3/3-10/3-10:1.0/bluetooth/hci0/hci0:256/0005:046D:B342.002B/input/input179/input179::compose
SUBSYSTEM=leds
SEQNUM=11341
USEC_INITIALIZED=53072068677

UDEV  [53072.069230] change   /devices/pci0000:00/0000:00:14.0/usb3/3-10/3-10:1.0/bluetooth/hci0/hci0:256/0005:046D:B342.002B/input/input179/input179::numlock (leds)
ACTION=change
DEVPATH=/devices/pci0000:00/0000:00:14.0/usb3/3-10/3-10:1.0/bluetooth/hci0/hci0:256/0005:046D:B342.002B/input/input179/input179::numlock
SUBSYSTEM=leds
TRIGGER=kbd-numlock
SEQNUM=11336
USEC_INITIALIZED=53072069158

UDEV  [53072.070162] change   /devices/pci0000:00/0000:00:14.0/usb3/3-10/3-10:1.0/bluetooth/hci0/hci0:256/0005:046D:B342.002B/input/input179/input179::capslock (leds)
ACTION=change
DEVPATH=/devices/pci0000:00/0000:00:14.0/usb3/3-10/3-10:1.0/bluetooth/hci0/hci0:256/0005:046D:B342.002B/input/input179/input179::capslock
SUBSYSTEM=leds
TRIGGER=kbd-capslock
SEQNUM=11338
USEC_INITIALIZED=53072070075

UDEV  [53072.070417] add      /devices/pci0000:00/0000:00:14.0/usb3/3-10/3-10:1.0/bluetooth/hci0/hci0:256/0005:046D:B342.002B/input/input179/input179::kana (leds)
ACTION=add
DEVPATH=/devices/pci0000:00/0000:00:14.0/usb3/3-10/3-10:1.0/bluetooth/hci0/hci0:256/0005:046D:B342.002B/input/input179/input179::kana
SUBSYSTEM=leds
SEQNUM=11342
USEC_INITIALIZED=53072070357

UDEV  [53072.070663] change   /devices/pci0000:00/0000:00:14.0/usb3/3-10/3-10:1.0/bluetooth/hci0/hci0:256/0005:046D:B342.002B/input/input179/input179::scrolllock (leds)
ACTION=change
DEVPATH=/devices/pci0000:00/0000:00:14.0/usb3/3-10/3-10:1.0/bluetooth/hci0/hci0:256/0005:046D:B342.002B/input/input179/input179::scrolllock
SUBSYSTEM=leds
TRIGGER=kbd-scrolllock
SEQNUM=11340
USEC_INITIALIZED=53072070559

UDEV  [53072.071742] change   /devices/pci0000:00/0000:00:14.0/usb3/3-10/3-10:1.0/bluetooth/hci0/hci0:256/0005:046D:B342.002B/input/input179/input179::kana (leds)
ACTION=change
DEVPATH=/devices/pci0000:00/0000:00:14.0/usb3/3-10/3-10:1.0/bluetooth/hci0/hci0:256/0005:046D:B342.002B/input/input179/input179::kana
SUBSYSTEM=leds
TRIGGER=kbd-kanalock
SEQNUM=11343
USEC_INITIALIZED=53072071646

UDEV  [53072.095391] add      /devices/pci0000:00/0000:00:14.0/usb3/3-10/3-10:1.0/bluetooth/hci0/hci0:256/0005:046D:B342.002B/power_supply/hid-34:88:5d:c8:51:50-battery/hwmon8 (hwmon)
ACTION=add
DEVPATH=/devices/pci0000:00/0000:00:14.0/usb3/3-10/3-10:1.0/bluetooth/hci0/hci0:256/0005:046D:B342.002B/power_supply/hid-34:88:5d:c8:51:50-battery/hwmon8
SUBSYSTEM=hwmon
SEQNUM=11333
USEC_INITIALIZED=53072095223

UDEV  [53072.145367] add      /devices/pci0000:00/0000:00:14.0/usb3/3-10/3-10:1.0/bluetooth/hci0/hci0:256/0005:046D:B342.002B/input/input181/event23 (input)
ACTION=add
DEVPATH=/devices/pci0000:00/0000:00:14.0/usb3/3-10/3-10:1.0/bluetooth/hci0/hci0:256/0005:046D:B342.002B/input/input181/event23
SUBSYSTEM=input
DEVNAME=/dev/input/event23
SEQNUM=11348
USEC_INITIALIZED=53072144992
ID_INPUT=1
ID_INPUT_KEY=1
ID_BUS=bluetooth
XKBMODEL=pc105
XKBLAYOUT=us
XKBVARIANT=
XKBOPTIONS=
BACKSPACE=guess
LIBINPUT_DEVICE_GROUP=5/46d/b342:cc:f9:e4:9e:e5:52
MAJOR=13
MINOR=87
TAGS=:power-switch:

UDEV  [53072.158413] add      /devices/pci0000:00/0000:00:14.0/usb3/3-10/3-10:1.0/bluetooth/hci0/hci0:256/0005:046D:B342.002B/input/input179/event21 (input)
ACTION=add
DEVPATH=/devices/pci0000:00/0000:00:14.0/usb3/3-10/3-10:1.0/bluetooth/hci0/hci0:256/0005:046D:B342.002B/input/input179/event21
SUBSYSTEM=input
DEVNAME=/dev/input/event21
SEQNUM=11344
USEC_INITIALIZED=53072158065
ID_INPUT=1
ID_INPUT_KEY=1
ID_INPUT_KEYBOARD=1
ID_BUS=bluetooth
XKBMODEL=pc105
XKBLAYOUT=us
XKBVARIANT=
XKBOPTIONS=
BACKSPACE=guess
LIBINPUT_DEVICE_GROUP=5/46d/b342:cc:f9:e4:9e:e5:52
MAJOR=13
MINOR=85
TAGS=:power-switch:

UDEV  [53072.218994] add      /devices/pci0000:00/0000:00:14.0/usb3/3-10/3-10:1.0/bluetooth/hci0/hci0:256/0005:046D:B342.002B/input/input180/event22 (input)
ACTION=add
DEVPATH=/devices/pci0000:00/0000:00:14.0/usb3/3-10/3-10:1.0/bluetooth/hci0/hci0:256/0005:046D:B342.002B/input/input180/event22
SUBSYSTEM=input
DEVNAME=/dev/input/event22
SEQNUM=11346
USEC_INITIALIZED=53072218624
ID_INPUT=1
ID_INPUT_KEY=1
ID_BUS=bluetooth
XKBMODEL=pc105
XKBLAYOUT=us
XKBVARIANT=
XKBOPTIONS=
BACKSPACE=guess
LIBINPUT_DEVICE_GROUP=5/46d/b342:cc:f9:e4:9e:e5:52
MAJOR=13
MINOR=86
TAGS=:power-switch:

UDEV  [53072.220940] bind     /devices/pci0000:00/0000:00:14.0/usb3/3-10/3-10:1.0/bluetooth/hci0/hci0:256/0005:046D:B342.002B (hid)
ACTION=bind
DEVPATH=/devices/pci0000:00/0000:00:14.0/usb3/3-10/3-10:1.0/bluetooth/hci0/hci0:256/0005:046D:B342.002B
SUBSYSTEM=hid
DRIVER=hid-generic
HID_ID=0005:0000046D:0000B342
HID_NAME=Keyboard K380
HID_PHYS=cc:f9:e4:9e:e5:52
HID_UNIQ=34:88:5d:c8:51:50
MODALIAS=hid:b0005g0001v0000046Dp0000B342
SEQNUM=11350
USEC_INITIALIZED=53072220802

UDEV  [53072.222445] change   /devices/pci0000:00/0000:00:14.0/usb3/3-10/3-10:1.0/bluetooth/hci0/hci0:256/0005:046D:B342.002B/power_supply/hid-34:88:5d:c8:51:50-battery (power_supply)
ACTION=change
DEVPATH=/devices/pci0000:00/0000:00:14.0/usb3/3-10/3-10:1.0/bluetooth/hci0/hci0:256/0005:046D:B342.002B/power_supply/hid-34:88:5d:c8:51:50-battery
SUBSYSTEM=power_supply
POWER_SUPPLY_NAME=hid-34:88:5d:c8:51:50-battery
POWER_SUPPLY_TYPE=Battery
POWER_SUPPLY_PRESENT=1
POWER_SUPPLY_ONLINE=1
POWER_SUPPLY_CAPACITY=75
POWER_SUPPLY_MODEL_NAME=Keyboard K380
POWER_SUPPLY_STATUS=Discharging
POWER_SUPPLY_SCOPE=Device
SEQNUM=11351
USEC_INITIALIZED=53072222316

UDEV  [53072.224012] change   /devices/pci0000:00/0000:00:14.0/usb3/3-10/3-10:1.0/bluetooth/hci0/hci0:256/0005:046D:B342.002B/power_supply/hid-34:88:5d:c8:51:50-battery (power_supply)
ACTION=change
DEVPATH=/devices/pci0000:00/0000:00:14.0/usb3/3-10/3-10:1.0/bluetooth/hci0/hci0:256/0005:046D:B342.002B/power_supply/hid-34:88:5d:c8:51:50-battery
SUBSYSTEM=power_supply
POWER_SUPPLY_NAME=hid-34:88:5d:c8:51:50-battery
POWER_SUPPLY_TYPE=Battery
POWER_SUPPLY_PRESENT=1
POWER_SUPPLY_ONLINE=1
POWER_SUPPLY_CAPACITY=75
POWER_SUPPLY_MODEL_NAME=Keyboard K380
POWER_SUPPLY_STATUS=Discharging
POWER_SUPPLY_SCOPE=Device
SEQNUM=11352
USEC_INITIALIZED=53072223882```

Solution 1:

First, udev rule files must be suffixed with .rules, not -rules. (Custom rules also should go to /etc/udev, not /lib, but this doesn't affect how they work.)

Second, to match an attribute you must use ==, as plain = is an assignment (so the current rule will technically match literally every input device).

Finally, for some reason, the UNIQ property as shown by udevadm literally contains quotation marks as part of the value, so you also need to include them: ENV{UNIQ}=="\"34:88:..\""

(Alternatively you may use ENVS to match against the parent's HID_UNIQ property, which seems to have the same data but without the quotation marks: ENVS{HID_UNIQ}=="34:88:..")

Don't forget to udevadm control --reload after making those changes.

The properties shown in your monitor are indeed ENV. The ATTR keyword instead deals with sysfs attributes, i.e. the virtual "files" that you can see in /sys/devices/…/input179. Sometimes both have the same information.