Xiaomi smartphones based on MIUI HyperOS, or HyperOS, offers users not only standard features, but also powerful tools to automate everyday tasks, and it makes routine operations simpler, from turning on a schedule-based Do Not Disturb mode to complex chains of actions triggered by a single touch. Many owners of Redmi devices, POCO Xiaomi doesnβt know where to start.
In this article, we will discuss all the ways to create scripts on Xiaomi: from built-in tools like Automation to Settings. β Special features before using third-party applications like Tasker or MacroDroid, you will learn how to record sequences of actions, configure triggers and even write simple scripts in JavaScript for HyperOS. And also β how to avoid typical errors that can block your smartphone or lead to crashes.
Important: Xiaomi scripts require caution. Incorrectly configured automation can drain the battery in a few hours, overload the processor or even cause a bootloop (locking when booting).
1. Integrated automation tools in MIUI/HyperOS
Starting with MIUI 12 and HyperOS, Xiaomi has added basic automation tools to the firmware without having to install third-party apps. β Special facilities β Automation (some models may have different paths) and there are three types of scripts available:
- π Action Chains β A sequence of manually run commands (e.g., enable Bluetooth, open Spotify, and play a playlist).
- β° Time automation β tasks performed at a given time (turn off Wi-Fi at night).
- π Location triggers: actions that trigger entry/exit from a specific geo-fence (e.g., turn on silent mode at work).
An example of creating a simple script:
- Open the Settings. β Special facilities β Automation β The chain of action.
- Click Add and select actions from the list (e.g. Flight Mode) β On, then Bluetooth. β On.).
- Save the chain and add it to the home screen as a widget or run through the notification bar.
β οΈ Attention: Built-in automation in MIUI It has a limit on the number of actions in a single chain (maximum 8 steps.
2. Script Creation Applications: Tasker vs MacroDroid
For advanced users, Xiaomi's built-in tools are not enough, and specialized applications come to the rescue:
| Annex | Difficulty | Free version | Features |
|---|---|---|---|
| Tasker | ββββ | 7-day trial | JavaScript support, plugins, integration with ADB |
| MacroDroid | βββ | Yes (with limitations) | Simple interface, templates, geofences |
| Automate | ββ | Yes. | Visual block diagram editor, no code |
Tasker is the most powerful tool, but it requires learning, and you can use it to write a script that:
- π± Sending. SMS with coordinates, if the battery is discharged below 10%;
- π Automatically turns on Google Assistant when connecting headphones;
- π Collects statistics on the use of applications and sends it to email.
An example of a simple script in Tasker to enable Driving Mode when connected to a Bluetooth radio:
Profile: Auto Car Mode
Condition: Status β Bluetooth Connected β [Device Name: CarAudio]
Task:
Driving mode β On.
2. Screen brightness β 70%
3. Launch the application β Google Mapsβ οΈ Note: Tasker requires permission for Special Options and may conflict with battery optimization MIUI. After installation, add it to exceptions: Settings β Battery β Optimizing the battery β All applications β Tasker β Not optimize.
Install the app from Google Play|
Insert permission βSpecial facilities"|
Add to the Battery Optimization Exceptions|
Create a backup of your phone settings|
3. JavaScript Scripts for HyperOS
HyperOS (the new shell from Xiaomi) supports JavaScript script execution through the built-in Automation Engine, which allows you to create more flexible scripts than standard automation.
- π To scrape data from web pages and show it in notifications;
- π Automatically respond to messages in Telegram;
- π± Change the system settings depending on the time of day.
An example of a script that sends a notification with a battery level every 2 hours:
// Receive charge level
var batteryLevel = device.battery.level;
// Create a notification
notification.postNotification({
title: "Battery level",
Text: "Current charge:" + batteryLevel + "%",
icon: "ic_battery"
});
// Starting the timer for 2 hours
setTimeout(function() {
engines.execScriptFile("battery_notify.js"); // Self-Call Script
}, 7200000);To run this script:
- Create a file. battery_notify.js file /sdcard/scripts/.
- Open Automation Engine (available in HyperOS via Settings) β Additionally. β Automation).
- Select Execute Script and specify the path to the file.
How to debug a JavaScript script on Xiaomi?
4. Automation through ADB: power-user
If you need system commands (for example, changing settings) MIUI, which are not available through the interface, can be used ADB (Android Debug Bridge. This requires enabling Debugging by USB Connecting to a PC, but offers a wide range of opportunities.
Examples of commands for automation:
- π Disable all notifications: adb shell cmd notification allow_list -p com.android.systemui -c none
- π΅ Enable Do Not Disturb: Adb shell cmd dnd set zen 1
- π Set a charge limit of 80%: adb shell dumpsys battery set ac 1 & & & adb shell dumpsys battery reset (does not work on all models).
To create a script for ADB, scheduled:
- Write a.bat file (for Windows) or a.sh file (for Windows) Linux/Mac) team-wise.
- Use the task scheduler (Windows) or cron (Linux/Mac) auto-execution.
- For remote execution without a PC, configure Termux with sshd.
β οΈ Attention: Teams ADB They can disrupt the system if used incorrectly, such as the adb shell pm disable-user command. --user 0 com.miui.securitycenter to shut down security center MIUI, What will make the device vulnerable to malware.
π‘
Before use ADB-Commands to back up data via adb backup -apk -obb -shared -all -f backup.ab. This will save all applications and settings to the backup.ab file on your PC.
5. Geo scripts: Automation by location
One of the most useful types of scripts is the ones that work when you enter or exit a particular geofence.
- π Turn on Wi-Fi and turn off mobile data at home;
- π’ Switch the sound profile to "Worker" when arriving at the office;
- π Start Yandex.Navigator when leaving home.
Set up a geo-script in MacroDroid:
- Create a new macro and select a location trigger β Entrance to the zone.
- Specify the address or coordinates of the center of the zone and the radius (for example, 200 meters for a house).
- Add Action: Wi-Fi β Including, Mobile data β Off..
- Save the macro and activate it.
For accuracy of geo-scripts:
- π± Enable High Accuracy in Location Settings (Settings) β Location β Regime. β High precision).
- π Regularly update your Google Maps data for your region.
- πΆ Turn off battery optimization for geofence app.
π‘
Geo scripts severely drain the battery due to constant use GPS. To save charge, increase the radius of the zone to 300-500 meters and use triggers for connecting to Wi-Fi instead of using the wifi. GPS where possible.
6.Security and debugging of scripts
Incorrectly configured scripts can:
- π Discharge the battery in 2-3 hours (for example, an infinite cycle in Tasker);
- π΅ Block the network (script that permanently turns on/off Wi-Fi);
- π¨ Call bootloop (if the script changes system files).
Rules for safe automation:
- Test on a secondary device or back up before launching new scripts.
- Use Logs: Enable Logistics in Tasker β Full, in MacroDroid - Settings β Journal management.
- Limit rights: Do not give scripts access to the ADB rooting unnecessarily.
- Keep an eye on the battery: Use AccuBattery to monitor your flow.
Example of Log Analysis in Tasker:
20:45:12 - Car Mode profile activated
20:45:13 - Task: Driving Mode β Successful
20:45:14 - Task: Brightness 70% β Mistake: Not enough rights
20:45:15 - Task: Launch Google Maps β SuccessfulIn this case, you need to give Tasker permission to change the brightness of the screen manually.
What to do if the script is looped?
7. Examples of ready-made scripts for Xiaomi
Here are some useful scenarios that can be customized in 5-10 minutes:
| The challenge | Tool. | Commands/Settings |
|---|---|---|
| Telegram's answering machine | Tasker | AutoNotification plugin + pattern |
| Limiting charging by 80% | ADB | adb shell dumpsys battery set ac 1 |
| Blocking Advertising in Apps | JavaScript (HyperOS) | Script using device.network.blockHost() |
| Automatic synchronization of photos in Google Photos | MacroDroid | Trigger: Connecting to home Wi-Fi β Action: Launching Google Photos |
Script for blocking ads in the browser (for HyperOS):
// List of hosts to block
var blockedHosts = [
"doubleclick.net",
"googlesyndication.com",
"scorecardresearch.com"
];
// Block access to hosts
blockedHosts.forEach(host => {
device.network.blockHost(host);
});
toast ("Advertising is blocked");