Skip to content

Python script for controlling Xiaomi Motion Activated Night Light 2

License

Notifications You must be signed in to change notification settings

ov1d1u/mjyd2s_control

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Xiaomi Motion Activated Night Light 2 Controller

This Python script allows you to control a Xiaomi Motion Activated Night Light 2 over Bluetooth using various actions such as turning the light on or off, adjusting brightness, setting duration, and modifying ambient light levels. It utilizes the provided Xiaomi Mi Token and the MAC address of the device to communicate and perform these actions.

Features

  • Turn On / Turn Off the night light.
  • Set Brightness level (from 1 to 100).
  • Set Duration for how long the light stays on (between 15 and 60 seconds).
  • Set Ambient Light Sensitivity (values: 0, 25, 50, 75, 100).
  • Debug mode for detailed logging output.

Requirements

Usage

python mjyd2s.py --mac_address <MAC_ADDRESS> --mi_token <MI_TOKEN> --action <ACTION> [--debug] [EXTRA_ARGS]

Parameters

  • --mac_address (required): The Bluetooth MAC address (or device identifier on macOS) of the Xiaomi night light.

  • --mi_token (required): The Xiaomi Mi Token used for authentication.

  • --action (required): The action you want to perform on the device. Options:

    • turn_on — Turns on the light.
    • turn_off — Turns off the light.
    • set_brightness — Sets the brightness level (requires an additional argument between 1 and 100).
    • set_duration — Sets the duration for how long the light stays on (requires an additional argument between 15 and 60 seconds).
    • set_ambient — Adjusts ambient light sensitivity (requires an additional argument of 0, 25, 50, 75, or 100).
  • EXTRA_ARGS: Used when the action requires additional input (brightness level, duration, or ambient light sensitivity).

  • --debug: Enables detailed logging for troubleshooting.

Examples

  1. Turn on the light:

    python mjyd2s.py --mac_address AA:BB:CC:DD:EE:FF --mi_token abc123 --action turn_on
  2. Set brightness to 80:

    python mjyd2s.py --mac_address AA:BB:CC:DD:EE:FF --mi_token abc123 --action set_brightness 80
  3. Set duration to 30 seconds:

    python mjyd2s.py --mac_address AA:BB:CC:DD:EE:FF --mi_token abc123 --action set_duration 30
  4. Enable debug logging:

    python mjyd2s.py --mac_address AA:BB:CC:DD:EE:FF --mi_token abc123 --action turn_off --debug

Debug Mode

To enable more detailed logging and help troubleshoot any issues, pass the --debug flag to the script. This will display additional output including the steps being taken and any potential errors.

Additional Information

  • Ensure Bluetooth is enabled and functional on the device running the script.
  • For actions requiring additional parameters (set_brightness, set_duration, set_ambient), only a single value should be provided.
  • Warning: bugs ahead. Consider this an alpha version. I'm preparing a Home Assistant integration too.

Resources

This script wouldn't be possible without help from some other projects on the internet:

License

This project is licensed under the Apache-2.0 License. See the LICENSE file for more details.

Disclaimer

This script is provided as-is and is not an official Xiaomi product. Use at your own risk. Ensure you are authorized to control the target device.

About

Python script for controlling Xiaomi Motion Activated Night Light 2

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages