Fix Nuki Auto Unlock on HyperOS (Xiaomi) once and for all - MacroDroid Solution


pipa89

Members
18 May 2017
5
13

️ Ultimate Guide: Solution for Nuki Auto Unlock on HyperOS (Xiaomi) with MacroDroid (UPDATED)​

⚠️ UPDATE NOTE (Latest Revisions)
Extensive stress-testing on HyperOS has revealed that background processes are aggressively killed during Deep Sleep, ignoring regular battery exemptions. This guide and template have been updated with the "Zero-Interruption Defibrillator" Architecture:
  • Wi-Fi Disconnect Trigger: The macro uses your home Wi-Fi disconnection to silently wake up the GPS and Nuki before you reach the outer geofence, guaranteeing the "Departure" state is recorded.
  • Smart Screen-State Trap: If you leave your house actively using your phone (screen on), the macro pauses indefinitely so it doesn't interrupt your usage. The moment you put the phone in your pocket (screen off), it instantly executes the background wake-up actions.
  • ️ Hardware GPS Timing: A precise 2-second delay has been added after forcing location updates to allow the Android OS exactly enough time to write new satellite coordinates to RAM before launching Nuki.
If you have a Xiaomi phone running HyperOS, you have likely experienced the main problem with Nuki Auto Unlock: the system's aggressive energy and memory management kills background processes and throttles the Bluetooth antenna when the screen is off, causing automatic unlocking to fail systematically at your front door.

This guide compiles the exact system-level configuration and a fully optimized MacroDroid macro structure to bulletproof its operation.

​

⚙️ Essential Prerequisite Settings in HyperOS​

To prevent the system from sabotaging the automation, apply these changes:

Nuki & MacroDroid App Settings​

  • Auto-start: Enabled.
  • Battery saver: Set to No restrictions.
  • Multitasking (CRITICAL): Long-press the Nuki and MacroDroid apps in recent apps and lock them with the padlock so the OS script doesn't clear them from RAM.
  • PERSISTENT NOTIFICATIONS (CRITICAL): You MUST enable permanent background notifications for both Nuki and MacroDroid in the system settings. The persistent icons visible in your status bar are strictly mandatory for HyperOS to register them as active Foreground Services. Without this, the system will kill GPS and Bluetooth access entirely.

️ Developer Options​

  • Wi-Fi scan throttling: Disabled (allows scanning networks with the screen off).
  • Background process limit: Set to Standard limit.
  • Suspend execution of cached apps: Disabled.
  • Disable secondary process restrictions: Enabled.

Network and Battery Settings​

  • Wi-Fi Assistant / Switch to mobile data automatically: Disabled.
  • Use mobile data to accelerate Wi-Fi: Disabled.
  • Keep mobile data turned on (even with Wi-Fi): Disabled.
  • Clear cache when device is locked: Set to Never.

⚡ Macro Triggers​

  • Geofence (Enter): [Geofence_Close] (e.g., 50m radius)
  • Geofence (Exit): [Geofence_Far] (e.g., 150m radius)
  • Geofence (Enter): [Geofence_Intermediate] (e.g., 100m radius inner)
  • Wifi Connected: [Your_Home_SSID]
  • Wifi Disconnected: [Your_Home_SSID]
  • Bluetooth Disconnected: [Your_Car_Bluetooth_Name]

Actions Structure and Logic
​

If: Trigger fired: Wifi Connected: [Your_Home_SSID]
Wait 15 seconds
Turn Screen On
Disable Trigger [This macro]: Geofence Enter: [Geofence_Close]
Disable Trigger [This macro]: Geofence Enter: [Geofence_Intermediate]
Disable Trigger [This macro]: Geofence Exit: [Geofence_Far]
Cancel Macro Actions [This macro]

Else If: Trigger fired: Wifi Disconnected: [Your_Home_SSID]
Enable Trigger [This macro]: Geofence Enter: [Geofence_Close]
Enable Trigger [This macro]: Geofence Enter: [Geofence_Intermediate]
Enable Trigger [This macro]: Geofence Exit: [Geofence_Far]

Else If: Trigger fired: Geofence Exit: [Geofence_Far]
Force Location Update
Wait 2 seconds
Launch Application: Nuki (io.nuki)
Wait 5 seconds
Launch Home Screen
Set Variable: Aprox. Activa = False
Cancel Macro Actions [This macro]

Else If: Trigger fired: Geofence Enter: [Geofence_Close] OR Bluetooth Disconnected: [Your_Car_Bluetooth_Name] [AND Aprox. Activa = True]
Repeat 120 times
Wifi SSID Scan ➔ wifis
Wait 9 seconds 60 ms
Set Variable: texto redes = {vjson=wifis}
If: texto redes contains [Your_Home_SSID]|[Other...] (Regex Enabled)
Turn Screen On
End If
End Loop

Else If: Trigger fired: Geofence Enter: [Geofence_Intermediate]
Set Variable: Aprox. Activa = Verdadero
End If
 

Attachments

  • IMG_20260907_040422.png
    IMG_20260907_040422.png
    1.1 MB · Views: 36
  • Auto_unlock_nuki.zip
    4.7 KB · Views: 40
Last edited:

Ultimate Guide: Solution for Nuki Auto Unlock on HyperOS (Xiaomi) with MacroDroid (UPDATED)​


If you have a Xiaomi phone running HyperOS, you have likely experienced the main problem with Nuki Auto Unlock: the system's aggressive energy and memory management kills background processes and throttles the Bluetooth antenna when the screen is off, causing automatic unlocking to fail systematically at your front door.
This guide compiles the exact system-level configuration and an optimized MacroDroid macro structured as a template to bulletproof its operation.

️ Important Note About This Template​

This macro is shared as a 100% structured template. You don't need to create any loops or logic conditions from scratch. All the heavy engineering (the Wi-Fi anti-drift system, Bluetooth maintenance for HyperOS, and state management) is already programmed into the template.
Language Note: This template was originally created in Spanish. The exact actions and structures listed below have been translated to match the literal English MacroDroid UI.
When you import it, the structure will be created automatically. All you need to do is map your local elements adapted to your devices:
  1. Create your two geofences (100m and 50m) in MacroDroid and select them in the corresponding triggers.
  2. Select the name of your home Wi-Fi network in the scanning and restriction blocks.
  3. Select your Bluetooth device (your car's hands-free system) if you use that optional trigger.

1️⃣ Essential Prerequisite Settings in HyperOS​

To prevent the system from sabotaging the automation, apply these changes:
Nuki & MacroDroid App Settings
  • Auto-start: Enabled.
  • Battery saver: Set to No restrictions.
  • Multitasking (CRITICAL): Long-press the Nuki and MacroDroid apps in recent apps and lock them with the padlock so the OS SwipeUpClean script doesn't clear them from RAM.
  • PERSISTENT NOTIFICATIONS (CRITICAL): You MUST enable permanent background notifications for both Nuki and MacroDroid in the system settings. The persistent icons visible in your status bar are strictly mandatory for HyperOS to register them as active Foreground Services. Without this, the system will kill the GPS and Bluetooth access entirely.
Developer Options
  • Wi-Fi scan throttling: Disabled (allows scanning networks with the screen off).
  • Background process limit: Set to Standard limit.
  • Suspend execution of cached apps: Disabled.
  • Disable secondary process restrictions: Enabled.
Network and Battery Settings
  • Wi-Fi Assistant / Switch to mobile data automatically: Disabled (prevents micro-cuts when passing neighbor routers).
  • Use mobile data to accelerate Wi-Fi: Disabled.
  • Keep mobile data turned on (even with Wi-Fi): Disabled.
  • Clear cache when device is locked: Set to Never.

2️⃣ Macro Triggers​

Configure these exactly as shown:
  • Geofence (Enter): "Casa lejos" (100-meter radius)
  • Geofence (Enter): "Casa cerca" (50-meter radius)
  • Geofence (Exit): "Casa lejos" (100-meter radius)
  • Bluetooth Disconnected: (Select your car's hands-free device)
  • Wifi Connected: (Select your main home network)
  • Wifi Disconnected: (Select your main home network)

3️⃣ Template Actions Structure and Logic​

This is the exact sequence of the macro logic.
Block 1: Initial Approach (100m)
  • If:Trigger fired: Geofence Enter: Casa lejos
    • Force Location Update
    • Wait 2 seconds
    • If:Screen off
      • Launch Application: Nuki
      • Wait 5 seconds
      • Launch Home Screen
    • End If
    • Set Variable: Aprox. Activa = True
Block 2: Critical Phase (50m or Car Disconnect)
  • Else If:OR (Trigger fired, Trigger fired) AND Aprox. Activa = True
    • Wifi SSID Scan ➔ wifis
    • Wait 4 seconds
    • If:wifis[Your_Network_Name] contains [SSID]
      • Cancel Macro Actions [This macro]
      • Set Variable: Aprox. Activa = False
    • End If
    • Vibrate (Long buzz)
    • Repeat 150 times
      • If:Aprox. Activa = False
        • Break from loop
      • End If
      • If:Screen off
        • Screen On
      • End If
      • Wait 6 seconds
    • End Loop
Block 3: Final Arrival (Wi-Fi Connection)
  • Else If:Trigger fired: Wifi Connected: Your_Network_Name
    • Disable Trigger [This macro]: Geofence Exit: Casa lejos
    • Disable Trigger [This macro]: Geofence Enter: Casa cerca
    • Disable Trigger [This macro]: Geofence Enter: Casa lejos
    • Set Variable: Aprox. Activa = False
Block 4: Confirming Departure (100m)
  • Else If:Trigger fired: Geofence Exit: Casa lejos
    • Force Location Update
    • If:Screen off
      • Launch Application: Nuki
      • Wait 5 seconds
      • Launch Home Screen
    • End If
    • Set Variable: Aprox. Activa = False
Block 5: The Silent Defibrillator (Leaving Home / Wi-Fi Disconnect)
  • Else If:Trigger fired: Wifi Disconnected: Your_Network_Name
    • Enable Trigger [This macro]: Geofence Enter: Casa lejos
    • Enable Trigger [This macro]: Geofence Enter: Casa cerca
    • Enable Trigger [This macro]: Geofence Exit: Casa lejos
    • If:Screen on
      • Wait until trigger: Screen off (Configured with NO timeout)
    • End If
    • Screen On
    • Launch Application: MacroDroid
    • Wait 2 seconds
    • Launch Application: Nuki
    • Wait 4 seconds
    • Launch Home Screen
  • End If (Closes the entire macro structure)
⚠️ UPDATE NOTE (Latest Revisions)Extensive stress-testing on HyperOS has revealed that background processes are aggressively killed during Deep Sleep, ignoring regular battery exemptions. This guide and template have been updated with a new "Zero-Interruption Defibrillator" Architecture:

  • Wi-Fi Disconnect Trigger: The macro now uses your home Wi-Fi disconnection to silently wake up the GPS and Nuki before you reach the 100m geofence, guaranteeing the "Departure" state is recorded.
  • Smart Screen-State Trap: If you leave your house actively using your phone (screen on), the macro pauses indefinitely so it doesn't interrupt your usage. The moment you put the phone in your pocket (screen off), it instantly executes the background wake-up actions.
  • Hardware GPS Timing: A precise 2-second delay has been added after forcing location updates to allow the Android OS exactly enough time to write the new satellite coordinates to RAM before launching Nuki.