{"id":18782908,"url":"https://github.com/simse/pymitv","last_synced_at":"2025-05-08T02:31:36.685Z","repository":{"id":44525428,"uuid":"111238569","full_name":"simse/pymitv","owner":"simse","description":"A Python 3 based control of the Mi Tv 3","archived":true,"fork":false,"pushed_at":"2022-12-11T12:03:30.000Z","size":381,"stargazers_count":46,"open_issues_count":14,"forks_count":15,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-03-16T14:04:12.767Z","etag":null,"topics":["python","xiaomi","xiaomi-tv"],"latest_commit_sha":null,"homepage":"https://simse.io/pymitv","language":"SCSS","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/simse.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-11-18T20:54:17.000Z","updated_at":"2024-09-22T22:21:55.000Z","dependencies_parsed_at":"2022-09-21T04:20:33.752Z","dependency_job_id":null,"html_url":"https://github.com/simse/pymitv","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simse%2Fpymitv","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simse%2Fpymitv/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simse%2Fpymitv/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simse%2Fpymitv/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/simse","download_url":"https://codeload.github.com/simse/pymitv/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252986816,"owners_count":21836231,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["python","xiaomi","xiaomi-tv"],"created_at":"2024-11-07T20:37:27.243Z","updated_at":"2025-05-08T02:31:36.272Z","avatar_url":"https://github.com/simse.png","language":"SCSS","funding_links":[],"categories":[],"sub_categories":[],"readme":"# pymitv\nA Python 3 based control of the Mi Tv 3(s)\n\n![The Mi TV 3s 65-inch](https://i.imgur.com/kOLWhWU.jpg)\n\n## Introduction\nThis package was developed to interface with the Xiaomi TV 3 series through their local HTTP API using Python. The package has both the ability to discover TVs and control them. The TV lineup in question is this [one.](http://www.mi.com/en/mitv3s/65/) It should be noted, that all the TV logic and hardware is in the soundbar. Thus, if you have a soundbar that looks identical to the one in the picture, you should be golden with this library.\n\n##### Supported models\n- Mi TV 3s (all sizes)\n\n##### Not sure if supported models\n- Mi TV 4A (all sizes)\n- Mi TV 4c (all sizes)\n\n## Installing\nEasy as pie! Just use `pip`.\n\n**Most systems**\n```\npip install pymitv\n```\n\n**Or if you have multiple Python versions**\n```\npython3 -m pip install pymitv\n```\n\n## Usage\nThe package includes three modules: `Discover`, `Control` and `TV`. Each have their role, as implied by their names.\n\n### Discovering TVs\n#### `Discover.scan()`\nThis method is used to scan the local network for TVs.\n\n**Arguments**\n\n| Name | Required | Default value | Purpose |\n| --- | --- | --- | --- |\n| `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. |\n| `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.` |\n\n**Example usage**\n\n```python\nimport Discover from pymitv\n\ndiscover = Discover.scan()\nprint(discover)\n```\n\n#### `Discover.check_ip()`\nUsed by `Discover.scan()` to check if a TV is present at the IP.\n\n**Arguments**\n\n| Name              | Required | Default value | Purpose                                                     |\n|-------------------|----------|---------------|-------------------------------------------------------------|\n| `ip`              | Yes      | None          | The IP to check.                                            |\n\n**Example usage**\n\n```python\nimport Discover from pymitv\n\nprint(Discover().check_ip('192.168.0.45'))\n```\n\n___\n\n### Controlling TVs\nThis is where the `Control` class comes in handy. The class has a bunch of predefined keystrokes:\n- `turn_on`\n- `turn_off`\n- `sleep`\n- `wake`\n- `up`\n- `down`\n- `right`\n- `left`\n- `home`\n- `enter`\n- `back`\n- `menu`\n- `volume_up`\n- `volume_down`\n\n#### `Control.send_keystrokes(ip, keystrokes)`\nSends a set of keystrokes to a TV at `ip`\n\n**Arguments**\n\n| Name              | Required | Default value | Purpose                                                     |\n|-------------------|----------|---------------|-------------------------------------------------------------|\n| `ip`              | Yes      | None          | The IP of the TV to send keystroke(s) to.                   |\n| `keystrokes`      | Yes      | None          | Keystroke(s) to send. E.g. `Control.sleep`                  |\n\n**Using the `wait` keystroke**\n\nUsing 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.\n\n**Example usage**\n\n```python\nimport Control from pymitv\n\nControl().sendKeystrokes(Control.sleep)\n```\n\n### TV as a class\nThere is a class representation of the TV which will take an IP address. It has a range of control functions, and will keep track of on/off state (provided the script running is kept alive).\n\n**Example usage**\n\n```python\nfrom pymitv import TV\n\ntv = TV('192.168.0.41')\n\ntv.is_on() #Return False\ntv.wake() #Will wake the TV\ntv.up() #Will press key up\n```\n\nAll keystrokes from the `Control` class are available with the exception of `turn_on`. This is because, you can't actually turn on the TV if it's completely off. Instead, use `wake` and `sleep`.\n\n## Accessing the local API exposed by the TV\nThis 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.\n\n#### Finding the TV IP\nTo find the IP of your TV you need to scan your network for clients. You can use an application like [*Advanced IP Scanner*](http://www.advanced-ip-scanner.com/) for Windows and [*LanScan*](https://itunes.apple.com/us/app/lanscan/id472226235?mt=12) 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`.\n\n#### Check TV status\nTo check if the TV is on, use the following request:\n`http://TV_IP:6095/request?action=isalive`\n\nThe above will return something along the lines of:\n```json\n{\n\t\"status\": 0,\n\t\"msg\": \"success\",\n\t\"data\": {\n\t\t\"devicename\": \"客厅的小米电视\",\n\t\t\"ip\": \"TV_IP:6095\",\n\t\t\"feature\": [\"power\"],\n\t\t\"url\": [\"http:\\/\\/bilibili.kankanews.com\\/video\\/av\\\\d+\\/\", \"http:\\/\\/www.bilibili.tv\\/video\\/av\\\\d+\\/\"],\n\t\t\"platform\": 606,\n\t\t\"build\": 1381,\n\t\t\"version\": 16777500\n\t}\n}\n```\n\n**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 the TV is actually on.**\n\n#### Send keystroke\nTo send a keystroke use the following request:\n`http://TV_IP:6095/controller?action=keyevent\u0026keycode=KEYCODE`\n\nInstead of `KEYCODE`, you should write an actual keycode. These are the available ones:\n\n| Key/button | keycode | action |\n| --- | --- | --- |\n| On/off toggle | `power` | Turns the TV on or off |\n| Up | `up` | Goes up |\n| Down | `down` | Goes down |\n| Left | `left` | Goes left |\n| Right | `right` | Goes right |\n| Enter | `enter` | Affirms selection |\n| Home | `home` | Returns to home screen |\n| Back | `back` | Goes one step back |\n| Menu | `menu` | Opens options menu |\n| Volume up | `volumeup` | Increases volume by 1 |\n| Volume down | `volumedown` | Decreases volume by 1 |\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsimse%2Fpymitv","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsimse%2Fpymitv","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsimse%2Fpymitv/lists"}