Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tuya Contact Sensor reports false state after recent fix #24025 #24668

Closed
pushpinderbal opened this issue Nov 6, 2024 · 3 comments
Closed

Tuya Contact Sensor reports false state after recent fix #24025 #24668

pushpinderbal opened this issue Nov 6, 2024 · 3 comments
Labels
problem Something isn't working

Comments

@pushpinderbal
Copy link

What happened?

The ONENUO zigbee sensor(_TZ3000_n2egfsli) was previously being reported as a SONOFF SNZB-04, which was deemed a cosmetic issue and fixed as reported on #24305
Related commit: Koenkk/zigbee-herdsman-converters@a551de6

After the upgrade to 1.41.0 the device now reports incorrect state. For example, if the door is left open for too long, it changes to closed after anytime between 1min-1hours. At first I thought this was device related, I changed batteries and reset the device multiple times, but then started to notice the behaviour with multiple devices of the same model.

What did you expect to happen?

The door contact sensor matches the original state.

How to reproduce it (minimal and precise)

Leve the contact sensor in an open state, it will close after some time on it's own.

Zigbee2MQTT version

1.41.0

Adapter firmware version

7.4.4 [GA]

Adapter

SONOFF ZBDongle-E

Setup

HomeAssistant on RockPro64 in docker

Debug log

relevant log message is at 2024-11-06 18:10:49 from device 'Back Door' when it reported as closed even though it was in an open state physically

debug.log

@pushpinderbal pushpinderbal added the problem Something isn't working label Nov 6, 2024
@pushpinderbal
Copy link
Author

I wonder if this is related: Koenkk/zigbee-herdsman-converters@7e8a807

@pushpinderbal pushpinderbal changed the title ONENUO Tuya Zigbee Contact Sensor reports false state after recent fix #24305 Tuya Zigbee Contact Sensor reports false state after recent fix #24025 Nov 10, 2024
@pushpinderbal
Copy link
Author

pushpinderbal commented Nov 10, 2024

It's caused by the use of modern extends for this device in the latest z2m version. I've reverted to an external definition from the previous version which seems to be working fine.

const {} = require('zigbee-herdsman-converters/lib/modernExtend');
const tuya = require('zigbee-herdsman-converters/lib/tuya');
const fz = require('zigbee-herdsman-converters/converters/fromZigbee');
const exposes = require('zigbee-herdsman-converters/lib/exposes');
const reporting = require('zigbee-herdsman-converters/lib/reporting');
const e = exposes.presets;

const definition = {
    fingerprint: [
        // ModelID is from the temperature/humidity sensor (SNZB-02) but this is SNZB-04, wrong modelID in firmware?
        // https://github.com/Koenkk/zigbee-herdsman-converters/issues/1449
        {
            type: 'EndDevice',
            manufacturerName: 'eWeLink',
            modelID: 'TH01',
            endpoints: [{ID: 1, profileID: 260, deviceID: 1026, inputClusters: [0, 3, 1280, 1], outputClusters: [3]}],
        },
    ],
    zigbeeModel: ['DS01', 'SNZB-04'],
    model: 'SNZB-04',
    vendor: 'SONOFF',
    whiteLabel: [{vendor: 'eWeLink', model: 'RHK06'}, tuya.whitelabel('Tuya', 'WL-19DWZ', 'Contact sensor', ['_TZ3000_n2egfsli'])],
    description: 'Contact sensor',
    exposes: [e.contact(), e.battery_low(), e.battery(), e.battery_voltage()],
    fromZigbee: [fz.ias_contact_alarm_1, fz.battery],
    toZigbee: [],
    configure: async (device, coordinatorEndpoint) => {
        const endpoint = device.getEndpoint(1);
        await reporting.bind(endpoint, coordinatorEndpoint, ['genPowerCfg']);
        await reporting.batteryVoltage(endpoint, {min: 3600, max: 7200});
        await reporting.batteryPercentageRemaining(endpoint, {min: 3600, max: 7200});
    },
};

module.exports = definition;

A wild guess based on what I have been looking at is that the device sends an attribute report with the payload as -> "payload":[{"attrId":61441,"dataType":32,"attrData":1}] which is not parsed correctly by iasZoneAlarm setting the zoneStatus to undefined here, alarm1Payload is then computed to an incorrect value.
https://github.com/Koenkk/zigbee-herdsman-converters/blob/15835f6fa2e9658e6dbb1f1599c5ab88b7051622/src/lib/modernExtend.ts#L1519

@pushpinderbal pushpinderbal changed the title Tuya Zigbee Contact Sensor reports false state after recent fix #24025 Tuya Contact Sensor reports false state after recent fix #24025 Nov 10, 2024
@Koenkk
Copy link
Owner

Koenkk commented Nov 10, 2024

Thanks for investigating, pushed a fix!

Changes will be available in the dev branch in a few hours from now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
problem Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants