Ddcutil losing i2c reference

I recently created a script to change the monitor input via the terminal using ddcutil. This allows me to switch between DP (computer) and HDMI (Switch 2), but the script sometimes fails. After some investigation, I discovered it might be an issue with the Nvidia driver regarding I2C; sometimes ddcutil “loses” the reference to the monitor I want to switch, causing the script to fail. I tested this by enabling my integrated AMD GPU, and the script didn’t fail a single time—in fact, the input switching was even faster. I searched the forum and found someone with a similar problem, though not exactly the same: the monitor appears in /dev/i2c-* but sometimes disappears. Does anyone have any idea what might be causing this?

Computer specs:

GPU: NVIDIA GeForce RTX 3060 Lite Hash Rate
Driver: 610.57.04
Kernel: Linux 7.1.8-1-cachyos

Here’s the script:

#!/bin/bash

DISPLAY_BUS=17

current=$(ddcutil -b "$DISPLAY_BUS" getvcp 0x60 | grep -oP 'sl=0x\K[0-9a-fA-F]+')

if [ -z "$current" ]; then
    notify-send -a "Alternador" "Monitor" "Não foi possível detectar a entrada atual" -u critical
    exit 1
fi

if [ "$current" == "01" ] || [ "$current" == "1" ]; then
    target=0x03
    target_name="DisplayPort (PC)"
else
    target=0x01
    target_name="HDMI (Switch)"
fi

for i in 1 2 3; do
    if ddcutil -b "$DISPLAY_BUS" setvcp 0x60 "$target"; then
        notify-send -a "Alternador" "Monitor" "Entrada alterada para $target_name"
        exit 0
    fi
    sleep 0.5
done

notify-send -a "Alternador" "Monitor" "Falha ao trocar para $target_name" -u critical
exit 1

ddcutil detect --verbose:

Display 1
   I2C bus:  /dev/i2c-4
      DRM_connector:                             card1-HDMI-A-1
      /sys/class/drm/card1-HDMI-A-1/dpms         On
      /sys/class/drm/card1-HDMI-A-1/enabled      enabled
      /sys/class/drm/card1-HDMI-A-1/status       connected
      /sys/class/drm/card1-HDMI-A-1/connector_id 823
      Driver:                                    nvidia
      I2C address 0x30 (EDID block#)  present:   false
      EDID exists:                               true
      I2C address 0x37 (DDC) responsive:         true
      Is LVDS or EDP display:                    false
      Is laptop display by EDID:                 false
      Is laptop display:                         false
      /sys/bus/i2c/devices/i2c-4/name            NVIDIA i2c adapter 5 at 1:00.0
      PCI device path:                           /sys/devices/pci0000:00/0000:00:01.1/0000:01:00.0/i2c-4
   EDID synopsis:
      Mfg id:               GSM - LG Electronics
      Model:                LG FULL HD
      Product code:         23547  (0x5bfb)
      Serial number:        
      Binary serial number: 220846 (0x00035eae)
      Manufacture year:     2023,  Week: 3
      EDID version:         1.3
      Extra descriptor:        
      Video input definition:    0x80 - Digital Input
      Supported features:
         DPMS standby
         DPMS suspend
         DPMS active-off
         Digital display type: RGB 4:4:4 + YCrCb 4:4:4
         Standard sRGB color space: False
      White x,y:        0.313, 0.329
      Red   x,y:        0.645, 0.335
      Green x,y:        0.305, 0.630
      Blue  x,y:        0.148, 0.050
      Extension blocks: 1
   EDID source: I2C
   EDID hex dump:
        +0          +4          +8          +c            0   4   8   c   
+0000   00 ff ff ff ff ff ff 00 1e 6d fb 5b ae 5e 03 00   .........m.[.^..
+0010   03 21 01 03 80 30 1b 78 ea 31 35 a5 55 4e a1 26   .!...0.x.15.UN.&
+0020   0c 50 54 a5 4b 00 71 4f 81 80 95 00 b3 00 a9 c0   .PT.K.qO........
+0030   81 00 81 c0 90 40 2a 44 80 a0 70 38 27 40 30 20   .....@*D..p8'@0 
+0040   35 00 e0 0e 11 00 00 1e 00 00 00 fd 00 30 4b 1e   5............0K.
+0050   55 12 00 0a 20 20 20 20 20 20 00 00 00 fc 00 4c   U...      .....L
+0060   47 20 46 55 4c 4c 20 48 44 0a 20 20 02 3a 80 18   G FULL HD.  .:..
+0070   71 38 2d 40 58 2c 45 00 e0 0e 11 00 00 1e 01 f9   q8-@X,E.........
   VCP version:         2.1
   Controller mfg:      Novatek
   Firmware version:    3.5
   Monitor uses all data bytes 0 in DDC reply packet to indicate unsupported feature.
   Current dynamic sleep adjustment multiplier:  0.20
   Monitor Model Id:  GSM-LG_FULL_HD-23547
   Feature definition file GSM-LG_FULL_HD-23547.mccs not found.
 
Display 2
   I2C bus:  /dev/i2c-5
      DRM_connector:                             card1-DP-1
      /sys/class/drm/card1-DP-1/dpms             On
      /sys/class/drm/card1-DP-1/enabled          enabled
      /sys/class/drm/card1-DP-1/status           connected
      /sys/class/drm/card1-DP-1/connector_id     826
      Driver:                                    nvidia
      I2C address 0x30 (EDID block#)  present:   false
      EDID exists:                               true
      I2C address 0x37 (DDC) responsive:         true
      Is LVDS or EDP display:                    false
      Is laptop display by EDID:                 false
      Is laptop display:                         false
      /sys/bus/i2c/devices/i2c-5/name            NVIDIA i2c adapter 6 at 1:00.0
      PCI device path:                           /sys/devices/pci0000:00/0000:00:01.1/0000:01:00.0/i2c-5
   EDID synopsis:
      Mfg id:               GSM - LG Electronics
      Model:                LG ULTRAGEAR
      Product code:         23692  (0x5c8c)
      Serial number:        509AZNKHA791
      Binary serial number: 588791 (0x0008fbf7)
      Manufacture year:     2025,  Week: 9
      EDID version:         1.4
      Extra descriptor:        
      Video input definition:    0xb5 - Digital Input (DisplayPort), Bit depth: 10
      Supported features:
         DPMS standby
         Digital display type: RGB 4:4:4 + YCrCb 4:4:4 + YCrCb 4:2:2
         Standard sRGB color space: True
      White x,y:        0.313, 0.329
      Red   x,y:        0.676, 0.320
      Green x,y:        0.298, 0.640
      Blue  x,y:        0.146, 0.061
      Extension blocks: 1
   EDID source: I2C
   EDID hex dump:
        +0          +4          +8          +c            0   4   8   c   
+0000   00 ff ff ff ff ff ff 00 1e 6d 8c 5c f7 fb 08 00   .........m.\....
+0010   09 23 01 04 b5 3c 22 78 9f 07 a5 ad 52 4c a3 25   .#...<"x....RL.%
+0020   0f 50 54 25 4b 00 d1 c0 61 40 31 7c 45 7c 61 7c   .PT%K...a@1|E|a|
+0030   45 40 01 01 01 01 4f a7 80 a0 70 38 40 40 30 30   E@....O...p8@@00
+0040   35 00 58 54 21 00 00 1a 00 00 00 fd 00 30 b4 c8   5.XT!........0..
+0050   c8 2a 01 0a 20 20 20 20 20 20 00 00 00 fc 00 4c   .*..      .....L
+0060   47 20 55 4c 54 52 41 47 45 41 52 0a 00 00 00 ff   G ULTRAGEAR.....
+0070   00 35 30 39 41 5a 4e 4b 48 41 37 39 31 0a 01 d0   .509AZNKHA791...
   VCP version:         2.1
   Controller mfg:      Novatek
   Firmware version:    3.4
   Monitor correctly uses invalid feature flag in DDC reply packet to indicate unsupported feature.
   Current dynamic sleep adjustment multiplier:  0.20
   Monitor Model Id:  GSM-LG_ULTRAGEAR-23692
   Feature definition file GSM-LG_ULTRAGEAR-23692.mccs not found.

ddcutil environment | head -n 40:

The following tests probe the runtime environment using multiple overlapping methods.
*** Basic System Information ***
ddcutil version: 2.2.7
/proc/version:
   Linux version 7.1.6-1-cachyos (linux-cachyos@cachyos) (clang version 22.1.8, LLD 22.1.8) #1 SMP PREEMPT_DYNAMIC Mon, 03 Aug 2026 16:03:35 +0000
Architecture:     x86_64
Distributor id:   cachyos
Release:          rolling
Found a known architecture
/proc/cmdline:
   quiet nowatchdog splash rw rootflags=subvol=/@ root=UUID=0cfe10fb-565a-43d6-9fc4-705c68b29483
*** Primary Check 1: Identify video card and driver ***
Obtaining card and driver information from /sys...
Primary video controller at PCI address 0000:01:00.0 (boot_vga flag is set)
   Device class:        x030000    VGA compatible controller
   Vendor:              x10de      NVIDIA Corporation
   Device:              x2504      GA106 [GeForce RTX 3060 Lite Hash Rate]
   Subvendor/Subdevice: 10de/1536  NVIDIA Corporation
   Driver name:         nvidia
   Driver version:      610.57.04
   I2C device:          i2c-3      name: NVIDIA i2c adapter 2 at 1:00.0
   I2C device:          i2c-6      name: NVIDIA i2c adapter 7 at 1:00.0
   I2C device:          i2c-4      name: NVIDIA i2c adapter 5 at 1:00.0
   I2C device:          i2c-2      name: NVIDIA i2c adapter 1 at 1:00.0
   I2C device:          i2c-7      name: NVIDIA i2c adapter 8 at 1:00.0
   I2C device:          i2c-5      name: NVIDIA i2c adapter 6 at 1:00.0
*** Primary Check 2: Check that /dev/i2c-* exist and writable ***
Current user: fhilipe (1000)
Checking /dev/i2c-* devices...
Devices /dev/i2c-* must exist and the logged on user must have read/write permission for those devices (or at least those devices associated

Various displays, drivers, and GPU’s may behave differently.

Is the failure intermittent, if you try again, things sometimes succeed? In which case, you might try altering some of the reliability related parameters, such as the --sleep-multiplier. The ddcutil help pages at ddcutil.com have some nvidia specific notes: Setting Nvidia Driver Options Using X11 - ddcutil Documentation

A solution based on libddcutil might be more reliable. For example:

Although I’m primarily targeting GUI’s, either of those can be accessed by command line utilities such as busctl or varlinkctl. The advantage being that the script would then be interacting with services that have cache pre-initialized detection info, so might be more reliable.

Michael