Coder Social home page Coder Social logo

[Help] - zigbee readout about zigpy-znp HOT 7 CLOSED

zigpy avatar zigpy commented on August 17, 2024
[Help] - zigbee readout

from zigpy-znp.

Comments (7)

puddly avatar puddly commented on August 17, 2024 1

zigpy is stable. zigpy-znp is also somewhat stable but since few people use it right now, I can't guarantee you won't encounter any bugs.

from zigpy-znp.

Adminiuga avatar Adminiuga commented on August 17, 2024

There's no documentation for things like that. You would need to write your own application on top of zigpy-znp similar to bellows cli implementation

from zigpy-znp.

puddly avatar puddly commented on August 17, 2024

Using zigpy directly is unfortunately undocumented but the interface will be the same regardless of what radio hardware you use. This code is completely untested and probably won't work but it should get you started:

import asyncio
import logging
import coloredlogs

import zigpy_znp.types as t
import zigpy_znp.commands as c

# There are many different radio libraries but they all have the same API
from zigpy_znp.zigbee.application import ControllerApplication

coloredlogs.install(level=logging.DEBUG)
logging.getLogger('zigpy_znp').setLevel(logging.DEBUG)


LOGGER = logging.getLogger(__name__)


class MainListener:
    '''
    Contains callbacks that zigpy will call whenever something happens.
    Look for `listener_event` in the Zigpy source or just look at the logged warnings.
    '''

    def __init__(self, application):
        self.application = application

    def device_joined(self, device):
        asyncio.create_task(self.async_device_joined(device))

    async def async_device_joined(self, device):
        LOGGER.info("Device joined: %s", device)

        for endpoint_id, endpoint in device.endpoints.items():
            # If it's a proper motion sensor, it probably has an IAS Zone cluster
            # that you need to bind to before it does anything.
            #
            # If it's a Xiaomi motion sensor, it'll just send attribute updates.
            if not hasattr(endpoint, 'ias_zone'):
                continue

            endpoint.ias_zone.add_context_listener(self)

            await endpoint.ias_zone.bind()
            await endpoint.ias_zone.write_attributes({'cie_addr': self.application.ieee})
            await endpoint.ias_zone.enroll_response(0x00, 0x00)

    def attribute_updated(self, device, cluster, attribute_id, value):
        # This is where you'll receive attribute updates
        LOGGER.info("Received an attribute update %s=%s on cluster %s from device %s", 
            attribute_id, value, cluster, device)



async def main():
    app = ControllerApplication(ControllerApplication.SCHEMA({
        'database_path': '/path/to/zigbee.db',
        'device': {
            'path': '/dev/serial/by-id/your-serial-port',
        }
    }))

    listener = MainListener(app)
    app.add_listener(listener)

    await app.startup(auto_form=True)

    # Permit joins for a minute
    await app.permit(60)
    await asyncio.sleep(60)

    # Just run forever
    while True:
        asyncio.sleep(10000)


if __name__ == '__main__':
    await asyncio.run(main())

from zigpy-znp.

Adminiuga avatar Adminiuga commented on August 17, 2024

some primer on zigbee https://github.com/MarkDing/IoT-Developer-Boot-Camp/wiki/Zigbee-Boot-Camp

from zigpy-znp.

Mopele avatar Mopele commented on August 17, 2024

Ok thanks for the great info! So basically this module is still in an early phase of development and not quite suited for my needs right?

from zigpy-znp.

puddly avatar puddly commented on August 17, 2024

I'm closing this issue for now since it doesn't directly relate to zigpy-znp, but feel free to comment if you need any help using zigpy on its own.

from zigpy-znp.

Hedda avatar Hedda commented on August 17, 2024

@Mopele Please consider contributing to the discussions in zigpy/zigpy#471 and zigpy/zigpy#477

from zigpy-znp.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.