{"id":15637609,"url":"https://github.com/syssi/xiaomi_raw","last_synced_at":"2025-09-01T21:30:39.103Z","repository":{"id":32130568,"uuid":"129353521","full_name":"syssi/xiaomi_raw","owner":"syssi","description":"Custom component for Home Assistant to faciliate the reverse engeneering of Xiaomi MiIO devices","archived":false,"fork":false,"pushed_at":"2024-06-27T08:46:07.000Z","size":70,"stargazers_count":107,"open_issues_count":10,"forks_count":20,"subscribers_count":8,"default_branch":"develop","last_synced_at":"2024-12-22T07:09:34.640Z","etag":null,"topics":["custom-component","hacktoberfest","home-assistant","miio","miio-device","miio-protocol","monitoring","sensor"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/syssi.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-04-13T05:44:17.000Z","updated_at":"2024-11-07T22:15:34.000Z","dependencies_parsed_at":"2024-02-11T15:24:54.870Z","dependency_job_id":"16cbbe81-ba90-45b4-8404-d315970eb9b7","html_url":"https://github.com/syssi/xiaomi_raw","commit_stats":null,"previous_names":[],"tags_count":17,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/syssi%2Fxiaomi_raw","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/syssi%2Fxiaomi_raw/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/syssi%2Fxiaomi_raw/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/syssi%2Fxiaomi_raw/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/syssi","download_url":"https://codeload.github.com/syssi/xiaomi_raw/tar.gz/refs/heads/develop","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":231713089,"owners_count":18415195,"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":["custom-component","hacktoberfest","home-assistant","miio","miio-device","miio-protocol","monitoring","sensor"],"created_at":"2024-10-03T11:12:17.639Z","updated_at":"2024-12-29T08:10:37.110Z","avatar_url":"https://github.com/syssi.png","language":"Python","funding_links":["https://www.buymeacoffee.com/syssi"],"categories":[],"sub_categories":[],"readme":"# Xiaomi Raw\n\n![GitHub actions](https://github.com/syssi/xiaomi_raw/actions/workflows/ci.yaml/badge.svg)\n![GitHub stars](https://img.shields.io/github/stars/syssi/xiaomi_raw)\n![GitHub forks](https://img.shields.io/github/forks/syssi/xiaomi_raw)\n![GitHub watchers](https://img.shields.io/github/watchers/syssi/xiaomi_raw)\n[![\"Buy Me A Coffee\"](https://img.shields.io/badge/buy%20me%20a%20coffee-donate-yellow.svg)](https://www.buymeacoffee.com/syssi)\n\nThis is a custom component for home assistant to faciliate the reverse engeneering of Xiaomi MiIO devices.\n\nPlease follow the instructions on [Retrieving the Access Token](https://www.home-assistant.io/integrations/xiaomi_miio/#xiaomi-cloud-tokens-extractor) to get the API token to use in the configuration.yaml file.\n\nCredits: Thanks to [Rytilahti](https://github.com/rytilahti/python-miio) for all the work.\n\n## Features\n\n* Power (on, off)\n* Sensor value (RSSI in dBm of the WiFi connection)\n* Raw command (method + params)\n* Set properties (property list)\n* Attributes (can be extended by \"Set properties\")\n  - model\n  - firmware_version\n  - hardware_version\n  - properties\n\n\n## Install\n\nYou can install this custom component by adding this repository ([https://github.com/syssi/xiaomi_raw](https://github.com/syssi/xiaomi_raw/)) to [HACS](https://hacs.xyz/) in the settings menu of HACS first. You will find the custom component in the integration menu afterwards, look for 'Xiaomi MiIO Raw'. Alternatively, you can install it manually by copying the custom_component folder to your Home Assistant configuration folder.\n\n\n## Setup\n\n```yaml\n# configuration.yaml\n\nlogger:\n  default: warn\n  logs:\n    custom_components.sensor.xiaomi_miio_raw: info\n    miio: info\n\nsensor:\n  - platform: xiaomi_miio_raw\n    name: Any Xiaomi MiIO device\n    host: 192.168.130.73\n    token: 56197337f51f287d69a8a16cf0677379\n    # Optional and device specific config parameters\n    sensor_property: 'humidity'\n    sensor_unit: '%'\n    default_properties_getter: 'get_prop'\n    default_properties:\n      - humidity\n      - power\n      - temperature\n\n  # If your device doesn't support multiple named properties\n  - platform: xiaomi_miio_raw\n    name: Any Xiaomi MiIO device\n    host: 192.168.130.73\n    token: 56197337f51f287d69a8a16cf0677379\n    sensor_property: 'unnamed6'\n    default_properties_getter: 'get_prop'\n    default_properties:\n      - 'all'\n\nswitch:\n  - platform: xiaomi_miio_raw\n    name: Any Xiaomi MiIO device\n    host: 192.168.130.73\n    token: 56197337f51f287d69a8a16cf0677379\n    turn_on_command: 'set_power'\n    turn_on_parameters: 'on'\n    turn_off_command: 'set_power'\n    turn_off_parameters: 'off'\n    state_property: 'power'\n    state_property_getter: 'get_prop'\n    state_on_value: 'on'\n    state_off_value: 'off'\n\n```\n\nAnother example configuration to control a miot device (`chuangmi.plug.212a01`). Thanks to @lovelylain for adding miot support to the sensor entity!\n\n```yaml\n\nsensor:\n  - platform: xiaomi_miio_raw\n    name: Smart Plug\n    host: 192.168.30.74\n    token: d880f00295a6db218b29a1879eea4663\n    max_properties: 10\n    default_properties_getter: get_properties\n    default_properties:\n      - \"{'did': 'power', 'piid': 1, 'siid': 2}\"\n      - \"{'did': 'temperature', 'piid': 6, 'siid': 2}\"\n      - \"{'did': 'indicator_light', 'piid': 1, 'siid': 3}\"\n      - \"{'did': 'on_duration', 'piid': 1, 'siid': 4}\"\n      - \"{'did': 'off_duration', 'piid': 2, 'siid': 4}\"\n      - \"{'did': 'countdown', 'piid': 3, 'siid': 4}\"\n      - \"{'did': 'task_switch', 'piid': 4, 'siid': 4}\"\n      - \"{'did': 'countdown_info', 'piid': 5, 'siid': 4}\"\n      - \"{'did': 'power_consumption', 'piid': 1, 'siid': 5}\"\n      - \"{'did': 'electric_current', 'piid': 2, 'siid': 5}\"\n      - \"{'did': 'voltage', 'piid': 3, 'siid': 5}\"\n      - \"{'did': 'electric_power', 'piid': 6, 'siid': 5}\"\n  - platform: template\n    sensors:\n      smart_plug_power:\n        unique_id: smart_plug_power\n        unit_of_measurement: W\n        value_template: \"{{ state_attr('sensor.smart_plug', 'electric_power')|int / 100 }}\"\n        availability_template: \"{{ not is_state('sensor.smart_plug', 'unavailable') }}\"\n        icon_template: \"mdi:flash\"\n\nswitch:\n  - platform: template\n    switches:\n      smart_plug_switch:\n        unique_id: smart_plug_switch\n        value_template: \"{{ state_attr('sensor.smart_plug', 'power') }}\"\n        availability_template: \"{{ not is_state('sensor.smart_plug', 'unavailable') }}\"\n        turn_on:\n          service: xiaomi_miio_raw.sensor_raw_command\n          data:\n            entity_id: sensor.smart_plug\n            method: set_properties\n            params:\n              - did: power\n                siid: 2\n                piid: 1\n                value: true\n        turn_off:\n          service: xiaomi_miio_raw.sensor_raw_command\n          data:\n            entity_id: sensor.smart_plug\n            method: set_properties\n            params:\n              - did: power\n                siid: 2\n                piid: 1\n                value: false\n\n\n```\n\nAn example for using the raw sensor to create a rice-cooker temperature sensor based on the raw data. Tested on an `chunmi.cooker.normal2`. This sensor always provides the current temperature unlike the the official sensor that only works during the rice program.\n\n```yaml\nsensor:\n  - platform: xiaomi_miio_raw\n    name: cooker\n    host: 192.168.0.122\n    token: \n    sensor_property: 'unnamed11'\n    default_properties_getter: 'get_prop'\n    default_properties:\n    - 'all'\n\ntemplate:\n  - sensor:\n      - name: \"Cooker Temperature\"\n        unit_of_measurement: \"°C\"\n        state: \"{{ states.sensor.cooker_2.state[28:-2] |int(base=16) }}\"\n        state_class: measurement\n        device_class: temperature\n        availability: \"{{ states.sensor.cooker_2.state != 'unavailable' }}\"\n```\n\nConfiguration variables (sensor platform):\n- **host** (*Required*): The IP of your miio device.\n- **token** (*Required*): The API token of your miio device.\n- **name** (*Optional*): The name of your miio device.\n- **max_properties** (*Optional*): The number of retrieved properties per API call\n- **sensor_property** (*Optional*): Property used as sensor value. WiFi RSSI if unset.\n- **sensor_unit** (*Optional*): Measurement unit of the property. dBm if unset.\n- **default_properties** (*Optional*): List of requested properties. ['power'] if unset.\n- **default_properties_getter** (*Optional*): Method to requested properties. Default value: `get_prop`\n\nConfiguration variables (switch platform):\n- **host** (*Required*): The IP of your miio device.\n- **token** (*Required*): The API token of your miio device.\n- **name** (*Optional*): The name of your miio device.\n- **turn_on_command** (*Optional*): The miIO command to send on `switch.turn_on`. Default value: `set_power`.\n- **turn_on_parameters** (*Optional*): The miIO commands parameters. Default value: `on`.\n- **turn_off_command** (*Optional*): The miIO command to send on `switch.turn_off`. Default value: `set_power`.\n- **turn_off_parameters** (*Optional*): The miIO commands parameters. Default value: `off`.\n- **state_property** (*Optional*): The miIO property which provides the current state.\n- **state_property_getter** (*Optional*): Method to requested properties. Default value: `get_prop`\n- **state_on_value** (*Optional*): The value of the `state_property` which indicates the `is_on` state. Default value: 'on'\n- **state_off_value** (*Optional*): The value of the `state_property` which indicates the `is_off` state. Default value: 'off'\n\n## Debugging\n\nIf the custom component doesn't work out of the box for your device please update your configuration to increase log level:\n\n```yaml\n# configuration.yaml\n\nlogger:\n  default: warn\n  logs:\n    custom_components.sensor.xiaomi_miio_raw: debug\n    custom_components.switch.xiaomi_miio_raw: debug\n    miio: debug\n```\n\n## Platform services\n\n#### Service `xiaomi_miio_raw.sensor_set_properties`\n\nUpdate the list of the retrieved properties.\n\n| Service data attribute    | Optional | Description                                                                |\n|---------------------------|----------|----------------------------------------------------------------------------|\n| `entity_id`               |       no | Only act on a specific Xiaomi miIO fan entity.                             |\n| `properties`              |      yes | List of properties. The default is `['power']`                             |\n\n\n```\n# http://localhost:8123/dev-service\n\nService: xiaomi_miio_raw.sensor_set_properties\nService Data: {\"properties\":[\"power\",\"temperature\",\"humidity\",\"aqi\"]}\n```\n\n#### Service `xiaomi_miio_raw.sensor_raw_command`\n\nSend a command to the device.\n\n| Service data attribute    | Optional | Description                                                                |\n|---------------------------|----------|----------------------------------------------------------------------------|\n| `entity_id`               |       no | Only act on a specific Xiaomi miIO fan entity.                             |\n| `method`                  |       no | Method name of the command. Example: `set_power`                           |\n| `params`                  |      yes | List of parameters. Example: `['on']`                                      |\n\n\n```\n# http://localhost:8123/dev-service\n\n# Turn the device on\nService: xiaomi_miio_raw.sensor_raw_command\nService Data: {\"method\":\"set_power\",\"params\":[\"on\"]}\n\n# Turn the device off\nService: xiaomi_miio_raw.sensor_raw_command\nService Data: {\"method\":\"set_power\",\"params\":[\"off\"]}\n\n# Request some properties\nService: xiaomi_miio_raw.sensor_raw_command\nService Data: {\"method\":\"get_prop\",\"params\":[\"power\",\"temperature\",\"humidity\",\"aqi\"]}\n```\n\n#### Service `xiaomi_miio_raw.sensor_turn_on`\n\nTurn the device on.\n\n| Service data attribute    | Optional | Description                                                          |\n|---------------------------|----------|----------------------------------------------------------------------|\n| `entity_id`               |       no | Only act on a specific xiaomi miio entity.                           |\n\n#### Service `xiaomi_miio_raw.sensor_turn_off`\n\nTurn the device off.\n\n| Service data attribute    | Optional | Description                                                          |\n|---------------------------|----------|----------------------------------------------------------------------|\n| `entity_id`               |       no | Only act on a specific Xiaomi miIO fan entity.                       |\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsyssi%2Fxiaomi_raw","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsyssi%2Fxiaomi_raw","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsyssi%2Fxiaomi_raw/lists"}