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 M3 curtain motor (_TZE204_xu4a5rhj/M3TYW-2.0-13) percentage inverted #26660

Open
devkaiwang opened this issue Mar 8, 2025 · 0 comments
Open
Labels
problem Something isn't working

Comments

@devkaiwang
Copy link

devkaiwang commented Mar 8, 2025

What happened?

I recently purchased a Tuya curtain motor, model _TZE204_xu4a5rhj/M3TYW-2.0-13. The motor is of good quality and quiet. However, there is an annoying issue when setting the motor's percentage through the Home Assistant cover UI or the Tuya app's curtain animation, the toZigbee percentage is inverted.

I wrote this converter code, which successfully fixed the problem. I’m curious if others have encountered this same issue or if it’s just a firmware bug specific to my device.

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

const invertedTuyaCoverControl = {
    key: ['state', 'position'],
    convertSet: async (entity, key, value, meta) => {
        if (key === 'position') {
            value = 100 - value; // Invert the position value
        }
        return await legacy.toZigbee.tuya_cover_control.convertSet(entity, key, value, meta);
    },
};

const definition = {
    zigbeeModel: [],
    fingerprint: [
        ...tuya.fingerprint('TS0601', [
            '_TZE204_xu4a5rhj',
        ]),
    ],
    model: 'TS0601_cover_1',
    vendor: 'Tuya',
    description: 'Curtain motor with corrected percentage setting',
    whiteLabel: [],
    fromZigbee: [legacy.fromZigbee.tuya_cover, fz.ignore_basic_report],
    toZigbee: [invertedTuyaCoverControl, legacy.toZigbee.tuya_cover_options],
    exposes: [
        e.cover_position().setAccess('position', ea.STATE_SET),
        e.composite('options', 'options', ea.STATE_SET)
            .withFeature(e.numeric('motor_speed', ea.STATE_SET)
                .withValueMin(0)
                .withValueMax(255)
                .withDescription('Motor speed'))
            .withFeature(e.binary('reverse_direction', ea.STATE_SET, true, false)
                .withDescription('Reverse the motor direction')),
    ],
};

module.exports = definition;

What did you expect to happen?

No response

How to reproduce it (minimal and precise)

No response

Zigbee2MQTT version

2.1.3

Adapter firmware version

20240710

Adapter

zStack3x0

Setup

Pi5

Debug log

No response

@devkaiwang devkaiwang added the problem Something isn't working label Mar 8, 2025
@devkaiwang devkaiwang changed the title Tuya curtain motor (_TZE204_xu4a5rhj/M3TYW-2.0-13) percentage inverted Tuya M3 curtain motor (_TZE204_xu4a5rhj/M3TYW-2.0-13) percentage inverted Mar 9, 2025
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

1 participant