Skip to main content

aiomihome

Asyncio version of https://github.com/Danielhiversen/PyXiaomiGateway

Description

The API only includes a thin layer with out proper handling of devices or sensors with seprate

Library consist of two classes

  • Service
    Manage the multisocket interface to the xiaomi bridge and connecting to a gateway. Includes service for discovery of gateways

  • Gateway
    Handles the connection to the gateway

The bridge needs to be i local mode and key needs to be provided to communicate with the gateway

Usage

Create a new service object. The gateway config key is required to be able to communicate with the gateway. If discovery is used and only one gateway exist only key is needed, if several provide sid or host.

See example folder for runnable code.

Connect go gateway

Run auto discover:

gateways_config = [
    {
      "host": "10.0.4.104", 
      "sid": "7811dcb07917",
      "port": 9898,
      "key": key
     }
]
service = XiaomiService(gateways_config=gateways_config)

# Start the mulitcast socket listner
await service.listen()

# Run the auto discover
gateways = await service.discover()

print("Number of gateways found: {}".format(len(gateways)))

# Get first gateway
gateway = gateways[0]

Directly connect to gateway:

service = XiaomiService()

# Start the mulitcast socket listner
await service.listen()

# Create a gatewate connetion
gateway = await service.add_gateway("10.0.4.104", 9898, "7811dcb07917", key)

Close conections

await service.close()

Listners

async def heartbeat_callback(data):
    print("HEARTBEAT RECIVED", data)

async def device_callback(data):
    print("Device data RECIVED", data)

gateway.heartbeat_callback = heartbeat_callback
gateway.device_callback = device_callback

Interact with the gateway

Print devices

print("Turn on light")
for device_type, devices in gateway.devices.items():
  print(device_type, len(devices))
  for device in devices:
    print("     ", device['model'])
    print(device)
      for value_key, value in device['data'].items():
        print("         ", value_key, value)

Set the gateway light

# Red
await gateway.set_color(255, 0, 0)
await asyncio.sleep(1)
# Green
await gateway.set_color(0, 255, 0)
await asyncio.sleep(1)
# Blue
await gateway.set_color(0, 0, 255)
await asyncio.sleep(1)
# Off
await gateway.turn_off_light()

Metadata

Release files for aiomihome 1.0.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for aiomihome 1.0.4
File Size Uploaded Provenance Actions
aiomihome-1.0.4.tar.gz 9.5 kB Without provenance Details for aiomihome-1.0.4.tar.gz

Release files / aiomihome-1.0.4.tar.gz

Download URL aiomihome-1.0.4.tar.gz
Size 9.5 kB
Tags Source
SHA-256 checksum
How to use checksums
c877cc9d52fb66a13bf7b3be34f0e7cad2cde4f6ddff918ef9be217e64023317
BLAKE2b-256 checksum
How to use checksums
74f312116e5b3a3d4cc33f09da95a7421166a04c02077be83ecb7b1cc131c114
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/40.6.2 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.6.8

Security for aiomihome 1.0.4

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

1.0.4 This release

1 release file No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page