MiAutomations

botao_ZIgbee_zmr4_zemismart.js

Aug 2nd, 2024 (edited)
352
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
JSON 2.62 KB | Source Code | 0 0
  1. const fz = require('zigbee-herdsman-converters/converters/fromZigbee');
  2. const tz = require('zigbee-herdsman-converters/converters/toZigbee');
  3. const exposes = require('zigbee-herdsman-converters/lib/exposes');
  4. const reporting = require('zigbee-herdsman-converters/lib/reporting');
  5. const modernExtend = require('zigbee-herdsman-converters/lib/modernExtend');
  6. const e = exposes.presets;
  7. const ea = exposes.access;
  8. const tuya = require('zigbee-herdsman-converters/lib/tuya');
  9.  
  10. const definition = {
  11.     fingerprint: tuya.fingerprint('TS004F', ['_TZ3000_11pg3ima']),
  12.     model: 'TS004F',
  13.     vendor: 'Tuya',
  14.     description: 'Wireless switch with 4 buttons',
  15.     exposes: [
  16.         e.battery(),
  17.         e
  18.             .enum('operation_mode', ea.ALL, ['command', 'event'])
  19.             .withDescription('Operation mode: "command" - for group control, "event" - for clicks'),
  20.         e.action([
  21.             'on',
  22.             'off',
  23.             'brightness_step_up',
  24.             'brightness_step_down',
  25.             'brightness_move_up',
  26.             'brightness_move_down',
  27.             '1_single',
  28.             '1_double',
  29.             '1_hold',
  30.             '2_single',
  31.             '2_double',
  32.             '2_hold',
  33.             '3_single',
  34.             '3_double',
  35.             '3_hold',
  36.             '4_single',
  37.             '4_double',
  38.             '4_hold',
  39.         ]),
  40.     ],
  41.     fromZigbee: [fz.battery, tuya.fz.on_off_action, fz.tuya_operation_mode, fz.command_on, fz.command_off, fz.command_step, fz.command_move],
  42.     toZigbee: [tz.tuya_operation_mode],
  43.     configure: async (device, coordinatorEndpoint) => {
  44.         const endpoint = device.getEndpoint(1);
  45.         await endpoint.read('genBasic', [0x0004, 0x000, 0x0001, 0x0005, 0x0007, 0xfffe]);
  46.         await endpoint.write('genOnOff', { tuyaOperationMode: 1 });
  47.         await endpoint.read('genOnOff', ['tuyaOperationMode']);
  48.         try {
  49.             await endpoint.read(0xe001, [0xd011]);
  50.         } catch (err) {
  51.             /* do nothing */
  52.         }
  53.         await endpoint.read('genPowerCfg', ['batteryVoltage', 'batteryPercentageRemaining']);
  54.         await reporting.bind(endpoint, coordinatorEndpoint, ['genPowerCfg']);
  55.         for (const ep of [1, 2, 3, 4]) {
  56.             // Not all variants have all endpoints
  57.             // https://github.com/Koenkk/zigbee2mqtt/issues/15730#issuecomment-1364498358
  58.             if (device.getEndpoint(ep)) {
  59.                 await reporting.bind(device.getEndpoint(ep), coordinatorEndpoint, ['genOnOff']);
  60.             }
  61.         }
  62.         await reporting.batteryPercentageRemaining(endpoint);
  63.     }
  64. };
  65.  
  66. module.exports = definition;
Advertisement
Add Comment
Please, Sign In to add comment