Skip to content

Conversation

@1tigris1
Copy link
Contributor

@1tigris1 1tigris1 commented Jan 18, 2026

Hi, could you please tell me why after the update some devices stopped working correctly, namely… what could be the reason? I had to rewrite the converter.
Here is the corrected converter.

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

const DP_CO_STATE = 1;
const DP_CO_VALUE = 2;
const DP_SELF_CHECKING = 8;
const DP_CHECK_RESULT = 9;
const DP_PREHEAT = 10;
const DP_FAULT = 11;
const DP_LIFECYCLE = 12;
const DP_BATTERY_STATE = 14;

const CO_STATES = {0: 'normal', 1: 'alarm'};
const CHECK_RESULTS = {0: 'ok', 1: 'error'};
const PREHEAT_STATE = {0: 'off', 1: 'on'};
const FAULT_STATE = {0: 'normal', 1: 'fault'};

const valueConverterLookup = (lookupTable) => ({
from: (v) => lookupTable[v] ?? v,
to: (v) => {
const entry = Object.entries(lookupTable).find(([, name]) => name === v);
return entry ? Number(entry[0]) : v;
},
});

const trueFalseRobust = {
from: (v) => !!v,
to: (v) => (v ? 1 : 0),
};

const definition = {
fingerprint: tuya.fingerprint('TS0601', ['_TZE284_sonkaxrd']),

model: 'E12',
vendor: 'Nous',
description: 'Zigbee carbon monoxide (CO) sensor',

fromZigbee: [tuya.fz.datapoints],
toZigbee: [tuya.tz.datapoints],

configure: tuya.configureMagicPacket,

exposes: [
    e.enum('co_state', ea.STATE, Object.values(CO_STATES))
        .withDescription('CO alarm state (normal or alarm)'),
    e.numeric('co_value', ea.STATE).withUnit('ppm').withDescription('Current CO concentration'),
    e.binary('self_checking', ea.ALL, 'ON', 'OFF')
        .withDescription('Triggers self-checking process'),
    e.enum('checking_result', ea.STATE, Object.values(CHECK_RESULTS))
        .withDescription('Result of self-checking'),
    e.enum('preheat', ea.STATE, Object.values(PREHEAT_STATE))
        .withDescription('Sensor preheating status'),
    e.enum('fault', ea.STATE, Object.values(FAULT_STATE))
        .withDescription('Sensor fault indicator'),
    e.numeric('lifecycle', ea.STATE).withUnit('days').withDescription('Sensor service life or usage counter'),
    e.battery(),
],

meta: {
    tuyaDatapoints: [
        [DP_CO_STATE,     'co_state',        valueConverterLookup(CO_STATES)],
        [DP_CO_VALUE,     'co_value',        tuya.valueConverter.raw],
        [DP_SELF_CHECKING, 'self_checking',  trueFalseRobust],
        [DP_CHECK_RESULT, 'checking_result', valueConverterLookup(CHECK_RESULTS)],
        [DP_PREHEAT,      'preheat',         valueConverterLookup(PREHEAT_STATE)],
        [DP_FAULT,        'fault',           valueConverterLookup(FAULT_STATE)],
        [DP_LIFECYCLE,    'lifecycle',       tuya.valueConverter.raw],
        [DP_BATTERY_STATE,'battery',         tuya.valueConverter.raw],
    ],
},

};

module.exports = definition;

@Koenkk
Copy link
Owner

Koenkk commented Jan 18, 2026

Hi, could you please tell me why after the update some devices stopped working correctly, namely… what could be the reason? I

Hey, what does not work with z2m 2.7.2?

@1tigris1
Copy link
Contributor Author

Здравствуйте, не могли бы вы объяснить, почему после обновления некоторые устройства перестали корректно работать, а именно… в чем может быть причина?

Привет, что не работает с z2m 2.7.2?

[19.01.2026, 16:37:05] frontend:api: Sending {"topic":"0xa4c13888e075a13a/set","payload":{"self_checking":true}}
[19.01.2026, 16:37:05] z2m: Publish 'set' 'self_checking' to '0xa4c13888e075a13a' failed: 'Error: No datapoint defined for 'self_checking''
[19.01.2026, 16:37:09] frontend:api: Sending {"topic":"0xa4c13888e075a13a/set","payload":{"preheat":"ON"}}
[19.01.2026, 16:37:09] z2m: Publish 'set' 'preheat' to '0xa4c13888e075a13a' failed: 'Error: Value: 'ON' not found in: [0, 1]'
[19.01.2026, 16:37:11] frontend:api: Sending {"topic":"0xa4c13888e075a13a/set","payload":{"fault":true}}
[19.01.2026, 16:37:11] z2m: Publish 'set' 'fault' to '0xa4c13888e075a13a' failed: 'Error: No datapoint defined for 'fault''

@1tigris1
Copy link
Contributor Author

I figured it out and reworked the converter, although the device worked correctly before the update.
I dare to assume that the issue was in tuya.valueConverter.trueFalse0, which sometimes strictly expects a boolean, while the device may send a number (0/1). This results in errors like:
"Value 'false' is not allowed, expected one of OFF, ON.
At least now the device is working normally.

@Koenkk
Copy link
Owner

Koenkk commented Jan 20, 2026

Could you update this PR with just the necessary changes?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants