Skip to content

Instantly share code, notes, and snippets.

@Koenkk

Koenkk/ext.js Secret

Created August 25, 2023 06:49
Show Gist options
  • Save Koenkk/fafd62c76aee9d331f70aa4ff4cf12fd to your computer and use it in GitHub Desktop.
Save Koenkk/fafd62c76aee9d331f70aa4ff4cf12fd to your computer and use it in GitHub Desktop.
const fz = require('zigbee-herdsman-converters/converters/fromZigbee');
const tz = require('zigbee-herdsman-converters/converters/toZigbee');
const exposes = require('zigbee-herdsman-converters/lib/exposes');
const reporting = require('zigbee-herdsman-converters/lib/reporting');
const legacy = require('zigbee-herdsman-converters/lib/legacy');
const extend = require('zigbee-herdsman-converters/lib/extend');
const ota = require('zigbee-herdsman-converters/lib/ota');
const tuya = require('zigbee-herdsman-converters/lib/tuya');
const utils = require('zigbee-herdsman-converters/lib/utils');
const globalStore = require('zigbee-herdsman-converters/lib/store');
const e = exposes.presets;
const ea = exposes.access;
const definition = {
zigbeeModel: ['Remote Control N2'],
model: 'E2001/E2002',
vendor: 'IKEA',
description: 'STYRBAR remote control',
fromZigbee: [],
exposes: [],
toZigbee: [tz.battery_percentage_remaining],
ota: ota.zigbeeOTA,
configure: async (device, coordinatorEndpoint, logger) => {
// Binding genOnOff is not required to make device send events.
const endpoint = device.getEndpoint(1);
const version = device.softwareBuildID.split('.').map((n) => Number(n));
// https://github.com/Koenkk/zigbee2mqtt/issues/15725
const v245OrLater = version[0] > 2 || (version[0] == 2 && version[1] >= 4);
const binds = v245OrLater ? ['genPowerCfg', 'genOnOff', 'genLevelCtrl', 'genScenes'] : ['genPowerCfg'];
await reporting.bind(endpoint, coordinatorEndpoint, binds);
await reporting.batteryPercentageRemaining(endpoint);
},
};
module.exports = definition;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment