Licznik zigbee na szynę din ZBN- JT-63 - niewspierany :(

Cześć
Czy ktoś pomoże mi napisać external_definition do takiego licznika?


Mam taki kod wygenerowany. Co dalej?

const definition = {
    zigbeeModel: ['TS0601'],
    model: 'TS0601',
    vendor: '_TZE204_m64smti7',
    description: 'Automatically generated definition',
    extend: [],
    meta: {},
};

module.exports = definition;

Ten licznik/bezpiecznik/przełącznik czy jak to tam nazwać działa na wprost jako EARU EAKCB-T-M-Z. To znaczy nie testowałem nic oprócz działania wyłącznika, pokazuje też napięcie, moc i energie ale nie wiem czy dobrze. Inne parametry też trzeba pewnie dostosować. Traktuj bardziej jako punkt wyjścia.

Ja bym raczej stawiał na coś zbliżonego do

Dziękuje za porady.
Utworzyłem plik licznik.js i dodałem go w pliku configuration.yaml jednak nic to nie zmieniło. Mój plik licznik.js wygląda tak:

const {} = require('zigbee-herdsman-converters/lib/modernExtend');
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 ota = require('zigbee-herdsman-converters/lib/ota');
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: ['TS0601'],
    model: 'TS0601',
    vendor: '_TZE204_m64smti7',
    description: 'Automatically generated definition',
     fromZigbee: [tuya.fz.datapoints],
        toZigbee: [tuya.tz.datapoints],
        configure: tuya.configureMagicPacket,
        exposes: [e.voltage(), e.power(), e.current(),
            e.energy().withDescription('Total forward active energy'),
            e.produced_energy().withDescription('Total reverse active energy'),
            e.power_factor().withUnit('%'), e.ac_frequency(),
        ],
        meta: {
            tuyaDatapoints: [
                [1, 'energy', tuya.valueConverter.divideBy100],
                [2, 'produced_energy', tuya.valueConverter.divideBy100],
                // [6, null, tuya.valueConverter.phaseVariant3],
                [15, 'power_factor', tuya.valueConverter.raw],
                // [16, 'clear_energy', tuya.valueConverter.onOff],
                [101, 'ac_frequency', tuya.valueConverter.divideBy100],
                [102, 'voltage', tuya.valueConverter.divideBy10],
                [103, 'current', tuya.valueConverter.divideBy1000],
                [104, 'power', tuya.valueConverter.raw],
            ],
        }
};
module.exports = definition;

Proszę o poradę co robię nie tak.

A załadowałeś go w Z2M ?

Nie za bardzo wiem co powinienem jeszcze dodatkowo zrobić oprócz wpisania go w pliku configuration.yaml

external_converters:
  - licznik.js

w logu Z2M wydaje się że został załadowany

Logi daj na Debug będziesz więcej widział.

Widzę mniej na debug. Te logi w ogóle są jakieś dziwne. Dzisiaj nie mam w ogóle nic w logach…
Jak mogę sprawdzić czy załadował się ten plik konwertera licznik.js
Czy ogólnie tak jak jest on napisany to jest poprawnie? Czy nie powinienem mieć jakich kolwiek zmian w urządzeniu ( chodzi że widziec jakieś parametry, nawet jeśli one by wyświetlały głupoty)

Sprawdź logi wdodatku Z2M:


Może są jakieś błędy i Z2M uruchamia się z błędem.

Będzie ci pokazywał jeżeli wszystko będzie poprawnie w twoim pliku licznik.js

Znajdź jakiś podobny i porównaj z twoim licznik.js

Możesz też spróbować Zigbee2MQTT Edge zawiera nie publikowaną obsługę urządzeń.

Siedzę kombinuje rozszerzenie nie działa bo nie ma tam w stałych odwołania do

const tuya = require('zigbee-herdsman-converters/lib/tuya');

Jak dodam tą linijkę to Z2M nie wstaje. W logach mam tak:

W wielu różnych przykładach jest stosowane.
bez tej linijki reszta nie pójdzie. Jak wykasuje tą linię to w logach mam tak

To tylko przykłady,

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 extend = require('zigbee-herdsman-converters/lib/extend');
const ota = require('zigbee-herdsman-converters/lib/ota');
const tuya = require('zigbee-herdsman-converters/lib/tuya');
const e = exposes.presets;
const ea = exposes.access;
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 extend = require('zigbee-herdsman-converters/lib/extend');
const e = exposes.presets;
const ea = exposes.access;
const tuya = require('zigbee-herdsman-converters/lib/tuya');

const definition = {
    // Since a lot of TuYa devices use the same modelID, but use different datapoints
    // it's necessary to provide a fingerprint instead of a zigbeeModel
    fingerprint: [
        {
            // The model ID from: Device with modelID 'TS0601' is not supported
            // You may need to add \u0000 at the end of the name in some cases
            modelID: 'TY0A01',
            // The manufacturer name from: Device with modelID 'TS0601' is not supported.
            manufacturerName: '_TYST12_bfejtdig',
        },
    ],
    model: 'TY0A01',
    vendor: 'TuYa',
    description: 'Smart Lock',
	powerSource: 'Battery',
	supports: 'inserted',
	ota: 'ota.zigbeeOTA',
    onEvent: tuya.onEventSetTime, // Add this if you are getting no converter for 'commandMcuSyncTime'
    fromZigbee: [fz.javis_lock_report, fz.battery],
    toZigbee: [],
    exposes: [e.battery(), e.action(['unlock'])],
};

module.exports = definition;

Trochę mnie nie było, nie wiem czy sobie poradziłeś. Wklejam kod który u mnie działa bez problemów. Tzn. działa włącz/wyłącz, działa wskazanie mocy. Zlicza też zużycie i pokazuje prąd ale nie wiem czy dobrze:

const {} = require('zigbee-herdsman-converters/lib/modernExtend'); 
// Add the lines below 
const exposes = require('zigbee-herdsman-converters/lib/exposes'); 
const fz = {...require('zigbee-herdsman-converters/converters/fromZigbee'), legacy: require('zigbee-herdsman-converters/lib/legacy').fromZigbee}; 
const tz = require('zigbee-herdsman-converters/converters/toZigbee'); 
const ota = require('zigbee-herdsman-converters/lib/ota'); 
const tuya = require('zigbee-herdsman-converters/lib/tuya'); 
const reporting = require('zigbee-herdsman-converters/lib/reporting'); 
const extend = require('zigbee-herdsman-converters/lib/modernExtend'); 
const e = exposes.presets; 
const ea = exposes.access; 
const libColor = require('zigbee-herdsman-converters/lib/color'); 
const utils = require('zigbee-herdsman-converters/lib/utils'); 
const zosung = require('zigbee-herdsman-converters/lib/zosung'); 
const fzZosung = zosung.fzZosung; 
const tzZosung = zosung.tzZosung; 
const ez = zosung.presetsZosung; 
const globalStore = require('zigbee-herdsman-converters/lib/store'); 
const {Buffer} = require('buffer'); 
 
function convertDecimalValueTo2ByteHexArray(value) { 
  const hexValue = Number(value).toString(16).padStart(4, '0'); 
  const chunk1 = hexValue.substring(0, 2); 
  const chunk2 = hexValue.substring(2); 
  return [chunk1, chunk2].map((hexVal) => parseInt(hexVal, 16)); 
} 
 
const valueConverter = { 
  ...tuya.valueConverter, 
  thresholdVariant1: (statusLookup, stateLookup) => { 
    return { 
      from: (v, meta) => { 
        const buffer = Buffer.from(v, 'base64'); 
        meta.logger.debug(`TEST2: ${JSON.stringify(buffer)}`); 
        return { 
          status: buffer[0],//tuya.valueConverterBasic.lookup(statusLookup).from(buffer[0]), 
          state: buffer[1],//tuya.valueConverterBasic.lookup(stateLookup).from(buffer[1]), 
          value: (buffer[3] | buffer[2] << 8), 
        }; 
      }, 
      to: (v) => { 
        const payload = []; 
        payload.push(/*tuya.valueConverterBasic.lookup(statusLookup).to(v.status)*/v.status); 
        payload.push(/*tuya.valueConverterBasic.lookup(stateLookup).to(v.state)*/v.state); 
        payload.push(...convertDecimalValueTo2ByteHexArray(v.value)); 
        return payload; 
      }, 
    }; 
  }, 
  thresholdVariant2: (names, statusLookup, stateLookup) => { 
    return { 
      from: (v, meta) => { 
        const thresholds = {}; 
        const chunkSize = 4; 
        meta.logger.debug(`TEST0: ${JSON.stringify(v)}`); 
        for (const [i, name] of Object.entries(names)) { 
          const idx = i * chunkSize; 
          const thresholdPayload = v.slice(idx, idx + chunkSize); 
          meta.logger.debug(`TEST1: name: ${name}, idx: ${idx}, payload: ${JSON.stringify(thresholdPayload)}`); 
          thresholds[`${name}_threshold`] = valueConverter.thresholdVariant1(statusLookup, stateLookup).from(thresholdPayload, meta); 
        } 
        return thresholds; 
      }, 
      to: (v) => { 
        const payload = []; 
        for (const threshold of Object.values(v)) payload.push(...valueConverter.thresholdVariant1(statusLookup, stateLookup).to(threshold)); 
        return payload; 
      } 
    }; 
  }, 
}; 
 
const tzDataPoints = { 
  ...tuya.tz.datapoints, 
  key: [ 
      'state', 'energy', 'breaker_id', 'voltage', 'current', 'power', 'status', 'value', 'thresholds', 
      'leakage_threshold', 'overcurrent_threshold', 'overvoltage_threshold', 'undervoltage_threshold', 
  ], 
}; 
 
const definition = { 
  fingerprint: tuya.fingerprint('TS0601', ['_TZE204_m64smti7']), 
  model: 'ZBN-JT-63', 
  vendor: 'TuYa', 
  description: 'Zigbee DIN relay switch', 
  fromZigbee: [tuya.fz.datapoints], 
  toZigbee: [tzDataPoints], 
  configure: tuya.configureMagicPacket, 
  exposes: [tuya.exposes.switch(), e.energy(), e.power(), e.voltage(), e.current(), 
    exposes.composite('Leakage threshold', 'leakage_threshold', ea.STATE) 
      .withFeature(exposes.switch().withState('state', true, 'Toggle leakage threshold alarm', ea.STATE_SET)) 
      .withFeature(exposes.numeric('value', ea.STATE).withUnit('mA').withDescription('Value of trigger for leakage threshold')) 
      .withDescription('Works only on 2P device'), 
    exposes.composite('Thresholds', 'thresholds', ea.STATE_SET) 
      .withFeature(exposes.composite('Overcurrent threshold', 'overcurrent_threshold', ea.STATE) 
        .withFeature(exposes.switch().withState('state', true, 'Toggle overcurrent threshold alarm', ea.STATE_SET)) 
        .withFeature(exposes.numeric('value', ea.STATE_SET).withUnit('A').withValueMax(63).withValueMin(10).withValueStep(1) 
          .withPreset('default', 35, 'Default value').withDescription('Value of trigger for overcurrent threshold'))) 
      .withFeature(exposes.composite('Overvoltage threshold', 'overvoltage_threshold', ea.STATE) 
        .withFeature(exposes.switch().withState('state', true, 'Toggle overvoltage threshold alarm', ea.STATE_SET)) 
        .withFeature(exposes.numeric('value', ea.STATE_SET).withUnit('V').withValueMax(400).withValueMin(1).withValueStep(1) 
          .withPreset('default', 265, 'Default value').withDescription('Value of trigger for overvoltage threshold'))) 
      .withFeature(exposes.composite('Undervoltage threshold', 'undervoltage_threshold', ea.STATE) 
        .withFeature(exposes.switch().withState('state', true, 'Toggle undervoltage threshold alarm', ea.STATE_SET)) 
        .withFeature(exposes.numeric('value', ea.STATE_SET).withUnit('V').withValueMax(300).withValueMin(50).withValueStep(1) 
          .withPreset('default', 180, 'Default value').withDescription('Value of trigger for undervoltage threshold'))), 
    exposes.text('breaker_id', ea.STATE).withDescription('Device identificator from manufacturer'), 
  ], 
  meta: { 
      tuyaDatapoints: [ 
          [1, 'energy', tuya.valueConverter.divideBy100], 
          [6, null, tuya.valueConverter.phaseVariant2], 
          [16, 'state', tuya.valueConverter.onOff], 
          // {"type":"Buffer","data":[4,1,0,30]} - leakage enabled 
          // {"type":"Buffer","data":[4,0,0,30]} - leakage disabled 
          [17, 'leakage_threshold', valueConverter.thresholdVariant1({4: 4}, {'ON': 1, 'OFF': 0})], 
          //[17, 'leakage_threshold', valueConverter.threshold2], 
          // {"type":"Buffer","data":[1,1,0,30,3,0,0,250,4,0,0,150]} - overcurr enabled 30A | overvolt enabled 250V | undervolt enabled 150V 
          // {"type":"Buffer","data":[1,0,0,21,3,0,0,250,4,0,0,150]} - overcurr disabled 21A | overvolt disabled 250V | undervolt disabled 150V 
          [18, 'thresholds', valueConverter.thresholdVariant2(['overcurrent', 'overvoltage', 'undervoltage'], {1: 1, 3: 3, 4: 4}, {'ON': 1, 'OFF': 0})], 
          //[18, 'overcurrent_threshold', valueConverter.thresholdVariant2([], {1: 1}, {'ON': 1, 'OFF': 0})], 
          //[18, 'overvoltage_threshold', valueConverter.thresholdVariant2([], {3: 3}, {'ON': 1, 'OFF': 0})], 
          //[18, 'undervoltage_threshold', valueConverter.thresholdVariant2([], {4: 4}, {'ON': 1, 'OFF': 0})], 
          [19, 'breaker_id', tuya.valueConverter.raw], 
      ], 
  }, 
}; 
 
module.exports = definition; 
 
//Fix by Lucas M. 

To nie moje “dzieło”, dostosowałem jak pisałem wcześniej z EARU EAKCB-T-M-Z

1 polubienie

@KrzychuD wstawiłem twój kod…
Jednak niestety, tak jak pisałem wyżej jest tam linijka

const tuya = require('zigbee-herdsman-converters/lib/tuya');

Uruchamianie dodatku zatrzymuje się i koniec.
usunięcie tej linji uruchamia dodatek ale Z2M ale external_definition nie działa prawidłowo.
@artpc Ty znasz się doskonale na HA, może podpowiesz gdzie szukać problemu. Przeszukałem internet i nie bardzo mogę znaleźć rozwiązanie.
Próbowałem Z2M i Z2M Edge - cały czas to samo, ta linia gdzie jest ładowana biblioteka tuya zatrzymuje uruchamianie dodatku Z2M

Wywal jeszcze z mojego kodu pierwszą linię:

const {} = require('zigbee-herdsman-converters/lib/modernExtend'); 

nie wiem skąd ona się tam wzięła, coś poszło nie tak przy kopiowaniu.

Używasz najnowszej wersji z2m (nie edge)?

Usuń tą linię, i zrestartuj dodatek, zobacz w logi, powinno coś być na samym początku po starcie
EDIT:
Internety piszą że może to być problem z node.js, masz wszystko w najnowszych wersjach?

Edge zawiera wszystkie najnowsze jeszcze nie dodane do wersji stabilnej Z2M wsparcia dla urządzeń jak i nowych eksperymentalnych zmian w samym Z2M.
Korzystałem długo z Edge które wspierało urządzenia niedostępne w wersji stabilnej, po roku może dłużej urządzenia te zostały dodane do wersji stabilnej.

Co do samego problemu @Robert szukaj tutaj https://github.com/Koenkk/zigbee-herdsman-converters/pulls

Jeżeli jest to samo urządzenie jak piszę @KrzychuD to znajduje się tutaj https://www.zigbee2mqtt.io/devices/EAKCB-T-M-Z.html

U mnie działa, dziękuję