Skip to content

Instantly share code, notes, and snippets.

@Alienmario
Last active May 24, 2025 06:47
Show Gist options
  • Save Alienmario/f2a2527fe973c775b204d8b060f4c168 to your computer and use it in GitHub Desktop.
Save Alienmario/f2a2527fe973c775b204d8b060f4c168 to your computer and use it in GitHub Desktop.
Mi home external automation (Non rooted, Android 11)
  1. Create a manual scene in Mi Home for the device you'd like to control
  2. Use Http Toolkit to figure out the scene id.
    • Install the app on PC and Android, follow the instructions - install CA certificate and connect
    • Set to only intercept the Mi home app
    • While snooping, start the scene in Mi home, then you can disconnect http toolkit
    • Look for this request: https://de.api.io.mi.com/app/scene/start
    • The request body should look like this (actual values replaced with *) data=*&rc4_hash__=*&signature=*&_nonce=*&ssecurity=*
    • You will need the values for data, nonce and ssecurity. Run each one by https://www.urldecoder.org/.
    • Download this python script: https://gist.github.com/socram8888/4b8949023c8e8153970764d20c935785
    • Run it like this: python rc4mi.py --decipher -s <ssecurity> -n <nonce> -m <data> Replace with your url-decoded values.
    • You should get a response like this: CLEARTEXT: {"us_id":"1111111111","key":""}
    • Your scene id is in us_id
    • When you have all scene id's you need, you may remove the certificates and VPN service the app installed in Android settings to regain security.
  3. Get an automation app which can launch custom android activity. I prefer Automate which is free. Tasker can do the job as well.
  4. Add an App start / launch activity block
    • Package: com.xiaomi.smarthome
    • Activity class: com.xiaomi.smarthome.scene.activity.SmartHomeLauncherActivity
    • Action: com.xiaomi.smarthome.scene.smarthomelauncher
    • Category: android.intent.category.DEFAULT
    • Extras: {"extra_str_scene_id": "*1", "extra_scene_account": "*2"} Replace *1 with your scene id retrieved earlier. Replace *2 with your account ID from Mi home.

Credits: h3ku, socram8888 for the python script

@Alienmario
Copy link
Author

Typical use case for this is location based automation of your device. For example, I use it to wake up the mi security camera when I leave home.
Don't forget to disable battery optimizations and data saver (if you have it) for mi home and your automation app.
Screenshot_20220103-162501_Automate

@jamilg
Copy link

jamilg commented Aug 23, 2023

Hi, thanks for the instructions. Seems what I was looking for. But the issue is that I have rooted Android 10. Do you think it will work for me, or you need minimum Android 11?

@Alienmario
Copy link
Author

Hi, thanks for the instructions. Seems what I was looking for. But the issue is that I have rooted Android 10. Do you think it will work for me, or you need minimum Android 11?

Worth a try. Only reason why the title says non rooted Android 11 is because it's more involved to snoop https traffic and you have to use something like http toolkit. In your case it should be possible on device with "normal" apps.

@jamilg
Copy link

jamilg commented Aug 23, 2023

Worth a try. Only reason why the title says non rooted Android 11 is because it's more involved to snoop https traffic and you have to use something like http toolkit. In your case it should be possible on device with "normal" apps.

Will definitely give it a try. Thanks for fast reply. Cheers!

@riadhnet
Copy link

when i start http tookit , all scene dissapear from the app , it seems like a security ...

@unlocomqx
Copy link

Could be a simpler approach (from https://llamalab.com/automate/community/flows/22798)

You need to open the file (you may need root access) /data/data/com.xiaomi.smartphone/shared_prefs/160080123456lite_scene_list_cache.xml

Here you can see the uid of the script, which will be required to run through intent

"uid":160080123456 - it is extra_scene_account
"us_id":1030123456 - it is extra_scene_id

@unlocomqx
Copy link

Scenes v2 give this data

CLEARTEXT: {"scene_id":"XXXXXXXXX","trigger_key":"user.click"}

How to use it in an intent?

@unlocomqx
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment