Skip to content

Instantly share code, notes, and snippets.

@farshidtz
Created January 3, 2023 10:35
Show Gist options
  • Save farshidtz/79a7d18a8b2241d9de7604e283f88a90 to your computer and use it in GitHub Desktop.
Save farshidtz/79a7d18a8b2241d9de7604e283f88a90 to your computer and use it in GitHub Desktop.
Simple Matter on/off handler in Python. See https://stackoverflow.com/a/74992066/3041544
from chip.server import (
GetLibraryHandle,
PostAttributeChangeCallback,
)
CLUSTER_ONOFF = 6
ATTR_ONOFF = 0
@PostAttributeChangeCallback
def attributeChangeCallback(endpoint: int, clusterId: int, attributeId: int, xx_type: int, size: int, value: bytes):
if endpoint == 1:
if clusterId == CLUSTER_ONOFF and attributeId == ATTR_ONOFF:
if value and value[0] == 1:
print(">>> on <<<")
else:
print(">>> off <<<")
chipLib = GetLibraryHandle(attributeChangeCallback)
input('Press any key to exit')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment