miio.alarmclock module

class miio.alarmclock.AlarmClock(ip: Optional[str] = None, token: Optional[str] = None, start_id: int = 0, debug: int = 0, lazy_discover: bool = True, timeout: Optional[int] = None, *, model: Optional[str] = None)[source]

Bases: Device

Implementation of Xiao AI Smart Alarm Clock.

Note, this device is not very responsive to the requests, so it may take several seconds /tries to get an answer.

alarmops()[source]

Method to create, query, and delete alarms (not implemented).

The alarm_ops method is the one used to create, query and delete all types of alarms (reminders, alarms, countdowns):

->  192.168.0.128 data= {"id":263,"method":"alarm_ops",
    "params":{"operation":"create","data":[
        {"type":"alarm","event":"testlabel","reminder":"","smart_clock":0,
        "ringtone":"a2.mp3","volume":100,"circle":"once","status":"on",
        "repeat_ringing":0,"delete_datetime":1564291980000,
        "disable_datetime":"","circle_extra":"",
        "datetime":1564291980000}
        ],"update_datetime":1564205639326}}
<-  192.168.0.57 data= {"result":[{"id":1,"ack":"OK"}],"id":263}

# query per index, starts from 0 instead of 1 as the ids it seems
->  192.168.0.128 data= {"id":264,"method":"alarm_ops",
    "params":{"operation":"query","req_type":"alarm",
        "update_datetime":1564205639593,"index":0}}
<-  192.168.0.57 data= {"result":
    [0,[
        {"i":"1","c":"once","d":"2019-07-28T13:33:00+0800","s":"on",
        "n":"testlabel","a":"a2.mp3","dd":1}
       ], "America/New_York"
    ],"id":264}

# result [code, list of alarms, timezone]
->  192.168.0.128 data= {"id":265,"method":"alarm_ops",
    "params":{"operation":"query","index":0,"update_datetime":1564205639596,
        "req_type":"reminder"}}
<-  192.168.0.57 data= {"result":[0,[],"America/New_York"],"id":265}
buttons() List[ButtonDescriptor]

Return a list of button-like, clickable actions of the device.

cancel()[source]

Cancel timer alarm.

clock_system() HourlySystem[source]

Returns either 12 or 24 depending on which system is in use.

configure_wifi(ssid, password, uid=0, extra_params=None)

Configure the wifi settings.

countdown()[source]

-> 192.168.0.128 data= {“id”:258,”method”:”get_count_down_v2”,”params”:[]}

get_button_light()[source]

Get button’s light state.

get_config_version()[source]

# values unknown {‘result’: [4], ‘id’: 203} :return:

classmethod get_device_group()
get_properties(properties, *, property_getter='get_prop', max_properties=None)

Request properties in slices based on given max_properties.

This is necessary as some devices have limitation on how many properties can be queried at once.

If max_properties is None, all properties are requested at once.

Parameters
  • properties (list) – List of properties to query from the device.

  • max_properties (int) – Number of properties that can be requested at once.

Returns

List of property values.

get_ring(alarm_type: AlarmType)[source]

Get current ring tone settings.

info(*, skip_cache=False) DeviceInfo

Get (and cache) miIO protocol information from the device.

This includes information about connected wlan network, and hardware and software versions.

Parameters

bool (skip_cache) – Skip the cache

near_wakeup()[source]

Status for near wakeup.

Get the status:

->  192.168.0.128 data= {"id":235,"method":"get_near_wakeup_status",
    "params":[]}
<-  192.168.0.57 data= {"result":["disable"],"id":235}

Set the status:

->  192.168.0.128 data= {"id":254,"method":"set_near_wakeup_status",
    "params":["enable"]}
<-  192.168.0.57 data= {"result":["OK"],"id":254}

->  192.168.0.128 data= {"id":255,"method":"set_near_wakeup_status",
    "params":["disable"]}
<-  192.168.0.57 data= {"result":["OK"],"id":255}
night_mode()[source]

Get night mode status.

query()[source]

Query timer alarm.

raw_command(command, parameters)

Send a raw command to the device. This is mostly useful when trying out commands which are not implemented by a given device instance.

Parameters
  • command (str) – Command to send

  • parameters (dict) – Parameters to send

send(command: str, parameters: Optional[Any] = None, retry_count: Optional[int] = None, *, extra_parameters=None) Any

Send a command to the device.

Basic format of the request: {“id”: 1234, “method”: command, “parameters”: parameters}

extra_parameters allows passing elements to the top-level of the request. This is necessary for some devices, such as gateway devices, which expect the sub-device identifier to be on the top-level.

Parameters
  • command (str) – Command to send

  • parameters (dict) – Parameters to send

  • retry_count (int) – How many times to retry on error

  • extra_parameters (dict) – Extra top-level parameters

  • model (str) – Force model to avoid autodetection

send_handshake()

Send initial handshake to the device.

sensors() Dict[str, SensorDescriptor]

Return sensors.

set_button_light(on)[source]

Enable or disable the button light.

set_hourly_system(hs: HourlySystem)[source]
set_night_mode()[source]

Set the night mode (not implemented).

Enable night mode:

->  192.168.0.128 data= {"id":248,"method":"set_night_mode",
    "params":[1,"21:00","6:00"]}
<-  192.168.0.57 data= {"result":["OK"],"id":248}

Disable night mode:

->  192.168.0.128 data= {"id":249,"method":"set_night_mode",
    "params":[0,"21:00","6:00"]}
<-  192.168.0.57 data= {"result":["OK"],"id":249}
set_ring(alarm_type: AlarmType, ring: RingTone)[source]

Set alarm tone (not implemented).

Raw payload example:

->  192.168.0.128 data= {"id":236,"method":"set_ring",
   "params":[{"ringtone":"a1.mp3","smart_clock":"","type":"alarm"}]}
<-  192.168.0.57 data= {"result":["OK"],"id":236}
set_volume(volume)[source]

Set volume [1,100].

settings() Dict[str, SettingDescriptor]

Return list of settings.

start_countdown(url)[source]

Start countdown timer playing the given media.

status() DeviceStatus

Return device status.

switches() Dict[str, SwitchDescriptor]

Return toggleable switches.

update(url: str, md5: str)

Start an OTA update.

update_progress() int

Return current update progress [0-100].

update_state()

Return current update state.

volume() int[source]

Return the volume.

property device_id: int

Return device id (did), if available.

property model: str

Return device model.

property raw_id: int

Return the last used protocol sequence id.

retry_count = 3
supported_models = ['zimi.clock.myk01']
timeout = 5
class miio.alarmclock.AlarmType(value)[source]

Bases: Enum

An enumeration.

Alarm = 'alarm'
Reminder = 'reminder'
Timer = 'timer'
class miio.alarmclock.HourlySystem(value)[source]

Bases: Enum

An enumeration.

Twelve = 12
TwentyFour = 24
class miio.alarmclock.Nightmode(data)[source]

Bases: DeviceStatus

embed(other: DeviceStatus)

Embed another status container to current one.

This makes it easy to provide a single status response for cases where responses from multiple I/O calls is wanted to provide a simple interface for downstreams.

Internally, this will prepend the name of the other class to the property names, and override the __getattribute__ to lookup attributes in the embedded containers.

sensors() Dict[str, SensorDescriptor]

Return the dict of sensors exposed by the status container.

You can use @sensor decorator to define sensors inside your status class.

settings() Dict[str, SettingDescriptor]

Return the dict of settings exposed by the status container.

You can use @setting decorator to define sensors inside your status class.

switches() Dict[str, SwitchDescriptor]

Return the dict of sensors exposed by the status container.

You can use @sensor decorator to define sensors inside your status class.

property enabled: bool
property end
property start
class miio.alarmclock.RingTone(data)[source]

Bases: DeviceStatus

embed(other: DeviceStatus)

Embed another status container to current one.

This makes it easy to provide a single status response for cases where responses from multiple I/O calls is wanted to provide a simple interface for downstreams.

Internally, this will prepend the name of the other class to the property names, and override the __getattribute__ to lookup attributes in the embedded containers.

sensors() Dict[str, SensorDescriptor]

Return the dict of sensors exposed by the status container.

You can use @sensor decorator to define sensors inside your status class.

settings() Dict[str, SettingDescriptor]

Return the dict of settings exposed by the status container.

You can use @setting decorator to define sensors inside your status class.

switches() Dict[str, SwitchDescriptor]

Return the dict of sensors exposed by the status container.

You can use @sensor decorator to define sensors inside your status class.

class miio.alarmclock.Tone(value)[source]

Bases: Enum

An enumeration.

Fifth = 'a5.mp3'
First = 'a1.mp3'
Fourth = 'a4.mp3'
Second = 'a2.mp3'
Seventh = 'a7.mp3'
Sixth = 'a6.mp3'
Third = 'a3.mp3'