Skip to main content

A Python 3 based Xiaomi TV remote

Project description

# pymitv
A Python based control of the Mi Tv 3

## Using the Python package
The package includes two modules: `Discover` and `Control`. Each have their role, as implied by their names.

### Discovering TVs
#### `Discover.scan()`
This method is used to scan the local network for TVs.

| Name | Required | Default value | Purpose |
| --- | --- | --- | --- |
| `stop_on_first` | No | `True` | Whether or not the method should continue scanning for TVs after finding its first one. Only needed for people with multiple Xiaomi TVs. |
| `base_ip` | No | `0` | Instead of looking for the base IP, you can give it to the function in the format of `192.168.0.` |
| `speedy_gonzalez` | No | `False` | Speeds up the scan drastically at the risk of missing a TV. |

**Example usage**
import Discover from pymitv

discover = Discover.scan(speedy_gonzalez=True)

#### `Discover.checkIp()`
Used by `Discover.scan()` to check if a TV is present at the IP.


| Name | Required | Default value | Purpose |
| `ip` | Yes | None | The IP to check. |
| `fast` | No | `False` | Speeds up the scan drastically at the risk of missing a TV. |

**Example usage**

import Discover from pymitv



### Controlling TVs
This is where the `Control` class comes in handy. The class has a bunch of predefined keystrokes:
- `turn_on`
- `turn_off`
- `sleep`
- `wake`
- `up`
- `down`
- `right`
- `left`
- `home`
- `enter`
- `back`
- `menu`
- `volume_up`
- `volume_down`

#### `Control.sendKeystrokes(ip, keystrokes)`

Sends a set of keystrokes to a TV at `ip`

| Name | Required | Default value | Purpose |
| `ip` | Yes | None | The IP of the TV to send keystroke(s) to. |
| `keystrokes` | Yes | None | Keystroke(s) to send. E.g. `Control.sleep` |

**Using the `wait` keystroke**

Using this keyword in a sequence of keystrokes will make the method sleep for 0.4 seconds which is the effective time it takes for the TV to listen to new keystrokes.

**Example usage**
import Control from pymitv


## Accessing the local API exposed by the TV
This can be useful if you don't wish to use the Python package (this one), but you'd rather implement your own version. Below you'll find everything you need.

#### Finding the TV IP
To find the IP of your TV you need to scan your network for clients. You can use an application like [*Advanced IP Scanner*]( for Windows and [*LanScan*]( for MacOS. Both these applications resolves the MAC address to give you the name of the manufacturer. However, if you have multiple Xiaomi products it can still prove difficult to find the right one. **Fear not!** The MAC address should start with `00:9E:C8`.

#### Check TV status
To check if the TV is on, use the following request:

The above will return something along the lines of:
"status": 0,
"msg": "success",
"data": {
"devicename": "客厅的小米电视",
"ip": "TV_IP:6095",
"feature": ["power"],
"url": ["http:\/\/\/video\/av\\d+\/", "http:\/\/\/video\/av\\d+\/"],
"platform": 606,
"build": 1381,
"version": 16777500

**BEWARE! If the TV is in standby mode, this request will still return as if it were on. Currently there is no way to check if TV is actually on.**

#### Send keystroke
To send a keystroke use the following request:

Instead of `KEYCODE`, you should write an actual keycode. These are the available ones:
| Key/button | keycode | action |
| --- | --- | --- |
| On/off toggle | `power` | Turns the TV on or off |
| Up | `up` | Goes up |
| Down | `down` | Goes down |
| Left | `left` | Goes left |
| Right | `right` | Goes right |
| Enter | `enter` | Affirms selection |
| Home | `home` | Returns to home screen |
| Back | `back` | Goes one step back |
| Menu | `menu` | Opens options menu |
| Volume up | `volumeup` | Increases volume by 1 |
| Volume down | `volumedown` | Decreases volume by 1 |

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for pymitv, version 1.0.0a2
Filename, size File type Python version Upload date Hashes
Filename, size pymitv-1.0.0a2-py3-none-any.whl (7.7 kB) File type Wheel Python version py3 Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page