How to use zigbee-herdsman - 6 common examples

To help you get started, we’ve selected a few zigbee-herdsman examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Koenkk / zigbee2mqtt / lib / extension / deviceReport.js View on Github external
{type: 'commandHueNotification', data: {button: 2}},
                {type: 'commandHueNotification', data: {button: 3}},
            ],
            genLevelCtrl: [
                {type: 'commandStep', data: {}},
                {type: 'commandStepWithOnOff', data: {}},
                {type: 'commandStop', data: {}},
                {type: 'commandMoveWithOnOff', data: {}},
                {type: 'commandStopWithOnOff', data: {}},
                {type: 'commandMove', data: {}},
            ],
        },
        // Read the following attributes
        read: {cluster: 'genLevelCtrl', attributes: ['currentLevel']},
        // When the bound devices/members of group have the following manufacturerID
        manufacturerID: ZigbeeHerdsman.Zcl.ManufacturerCode.Philips,
    },
];

class DeviceReport extends BaseExtension {
    constructor(zigbee, mqtt, state, publishEntityState) {
        super(zigbee, mqtt, state, publishEntityState);
        this.configuring = new Set();
        this.failed = new Set();
        this.pollDebouncers = {};
    }

    async setupReporting(device) {
        if (this.configuring.has(device.ieeeAddr) || this.failed.has(device.ieeeAddr)) return;
        this.configuring.add(device.ieeeAddr);

        try {
github Koenkk / zigbee2mqtt / lib / zigbee.js View on Github external
async start() {
        logger.info(`Starting zigbee-herdsman...`);
        const herdsmanSettingsLog = objectAssignDeep.noMutate(herdsmanSettings);
        herdsmanSettingsLog.network.networkKey = 'HIDDEN';
        logger.debug(`Using zigbee-herdsman with settings: '${JSON.stringify(herdsmanSettingsLog)}'`);

        try {
            herdsmanSettings.acceptJoiningDeviceHandler = this.acceptJoiningDeviceHandler;
            this.herdsman = new ZigbeeHerdsman.Controller(herdsmanSettings);
            await this.herdsman.start();
        } catch (error) {
            logger.error(`Error while starting zigbee-herdsman`);
            throw error;
        }

        this.herdsman.on('adapterDisconnected', () => this.emit('adapterDisconnected'));
        this.herdsman.on('deviceAnnounce', (data) => this.emit('event', 'deviceAnnounce', data));
        this.herdsman.on('deviceInterview', (data) => this.emit('event', 'deviceInterview', data));
        this.herdsman.on('deviceJoined', (data) => this.emit('event', 'deviceJoined', data));
        this.herdsman.on('deviceLeave', (data) => this.emit('event', 'deviceLeave', data));
        this.herdsman.on('message', (data) => this.emit('event', 'message', data));

        logger.info('zigbee-herdsman started');
        logger.info(`Coordinator firmware version: '${JSON.stringify(await this.getCoordinatorVersion())}'`);
        logger.debug(`Zigbee network parameters: ${JSON.stringify(await this.herdsman.getNetworkParameters())}`);
github hobbyquaker / node-red-contrib-zigbee / nodes / shepherd.js View on Github external
this.proxy.emit('devices');
                        setTimeout(() => {
                            this.configure(data.device);
                        }, 5000);
                    } else {
                        this.log(`deviceInterview ${data.status} ${data.device.ieeeAddr}`);
                    }
                },
                message: message => {
                    this.messageHandler(message);
                }
            };

            if (!herdsmanInstances[this.id]) {
                this.debug('creating new herdsman instance');
                herdsmanInstances[this.id] = new ZigbeeHerdsman.Controller(this.herdsmanOptions);
            }

            this.herdsman = herdsmanInstances[this.id];
            this.proxy = new HerdsmanProxy(this);

            this.connect();

            this.on('close', done => {
                this.debug('stopping');
                clearInterval(this.checkOverdueInterval);
                clearInterval(this.pingInterval);
                this.status = 'closing';
                this.proxy.emit('nodeStatus', {fill: 'yellow', shape: 'ring', text: 'closing'});

                this.removeListeners();
                this.herdsman.stop().then(() => {
github Koenkk / zigbee2mqtt / lib / extension / responder.js View on Github external
createReadResponseRec(cId, attrId, value) {
        return {
            attrId: attrId,
            status: 0,
            attrData: value,
            dataType: Zcl.getAttributeTypeLegacy(cId, attrId).value,
        };
    }
github Koenkk / zigbee2mqtt / lib / extension / responder.js View on Github external
readResponse(message, endpoint) {
        const clusterID = message.clusterid;
        const cluster = Zcl.getClusterLegacy(clusterID).key;
        const attributes = message.zclMsg.payload.map((p) => Zcl.getAttributeLegacy(message.clusterid, p.attrId));
        const response = [];

        attributes.forEach((attribute) => {
            if (cluster === 'genTime' && attribute.key === 'time') {
                const time = Math.round(((new Date()).getTime() - OneJanuary2000) / 1000);
                response.push(this.createReadResponseRec(clusterID, attribute.value, time));
            }
        });

        this.zigbee.publish(
            endpoint.device.ieeeAddr, 'device', cluster, 'readRsp', 'foundation', response,
            {direction: 1, seqNum: message.zclMsg.seqNum, disDefaultRsp: 1}, endpoint.epId,
        );
    }
github Koenkk / zigbee2mqtt / lib / extension / responder.js View on Github external
        const attributes = message.zclMsg.payload.map((p) => Zcl.getAttributeLegacy(message.clusterid, p.attrId));
        const response = [];

zigbee-herdsman

An open source ZigBee gateway solution with node.js.

MIT
Latest version published 8 days ago

Package Health Score

81 / 100
Full package analysis