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

Support track direction: Xiaomi Aqara Smart Curtain Motor ZNCLDJ11LM #1639

Closed
yozik04 opened this issue Jun 15, 2019 · 69 comments
Closed

Support track direction: Xiaomi Aqara Smart Curtain Motor ZNCLDJ11LM #1639

yozik04 opened this issue Jun 15, 2019 · 69 comments

Comments

@yozik04
Copy link
Contributor

yozik04 commented Jun 15, 2019

We have support of Xiaomi Aqara Smart Curtain Motor. But we need a "reverse" mode as well.

I have a problem. I have 3 motors. If all are physically closed, 2 of them reports that they are open and one closed.

How hard it is to implement reverse mode? Should it be done in zigbee2mqtt or in HomeAssistant?

Initial Xiaomi Aqara Smart Curtain Motor support was introduced in #294

@yozik04
Copy link
Contributor Author

yozik04 commented Jun 15, 2019

I figured out how to get device specific configuration from yaml in fromZigbee.js.
But I do not understand how to get it in toZigbee.js.

@Koenkk
Copy link
Owner

Koenkk commented Jun 16, 2019

What exactly do you want to add to toZigbee.js, also what is this "reverse mode"?

@yozik04
Copy link
Contributor Author

yozik04 commented Jun 16, 2019

Curtains can open to the left or to the right. So open state is different.
2 of my curtains open to the left. Which is reverse. It causes motor to spin in the opposite direction.
In MiHome there is a switch to do this.

@yozik04
Copy link
Contributor Author

yozik04 commented Jun 16, 2019

@yozik04
Copy link
Contributor Author

yozik04 commented Jun 16, 2019

In toZigbee.js ZNCLDJ11LM_control method I would like to get device specific setting called "reverse" or "direction". In case of "positive" direction:

                const lookup = {
                    'open': 100,
                    'close': 0,
                    'on': 100,
                    'off': 0,
                };

in case of "reverse" direction:

                const lookup = {
                    'open': 0,
                    'close': 100,
                    'on': 0,
                    'off': 100,
                };

Makes sense?

@Koenkk
Copy link
Owner

Koenkk commented Jun 16, 2019

I see, I think direction makes the most sense and then with positive (default) and reverse as the options (basically just what is shown in the Xiaomi app.

@yozik04 yozik04 changed the title Support Reverse mode: Xiaomi Aqara Smart Curtain Motor Support track direction: Xiaomi Aqara Smart Curtain Motor Jun 16, 2019
@yozik04
Copy link
Contributor Author

yozik04 commented Jun 16, 2019

Let's use direction then. But how to get this setting in toZigbee.js ZNCLDJ11LM_control method? =)

@Koenkk
Copy link
Owner

Koenkk commented Jun 16, 2019

@dzungpv
Copy link
Contributor

dzungpv commented Jun 19, 2019

@yozik04 just sniff packet with original hub when you change the direction, and then add to toZigbee code i remember it send a command and store in the motor memory, but i sniff it long time ago and then not save the packet.

@yozik04
Copy link
Contributor Author

yozik04 commented Jun 19, 2019

I do not have original hub =(

@yozik04
Copy link
Contributor Author

yozik04 commented Jun 26, 2019

@Koenkk I see you have added options in 10.0.0. Do I get it right that it serves different purpose than deviceSettings?

@yozik04
Copy link
Contributor Author

yozik04 commented Jun 26, 2019

@Koenkk I think you have mistake there:

const convertedResults = converter.convert(key, json[key], json, topic.type, topic.postfix, options);

const getConvertedResults = converter.convert(key, json[key], json, 'get', options);

In second postfix is missing before options

@Koenkk
Copy link
Owner

Koenkk commented Jun 27, 2019

@yozik04 thanks, fixed!

@Koenkk
Copy link
Owner

Koenkk commented Jun 27, 2019

@dzungpv would you mind sniffing setting the track direction?

@dzungpv
Copy link
Contributor

dzungpv commented Jun 28, 2019

@Koenkk i sniff the packet:

curtain

Some thing like this need to test with your side @yozik04 , add to toZigbee.js, because i have much device, must run xiaomi hub, not test with zigbee2mqtt. When i capture datatype is string: 0x42, but string not write raw hex if i remember correctly with z2m, it will convert to ASCII code, so let try uint16 0x21

    ZNCLDJ11LM_direction: {
        key: ['direction'],
        convert: (key, value, message, type, postfix, options) => {
            const cid = 'genBasic';

            if (type === 'set') {
                const lookup = {
                    'positive': 0x0100000000070007,
                    'reverse': 0x0100000101070007,
                };

                if (lookup.hasOwnProperty(value)) {
                    return [{
                        cid: cid,
                        cmd: 'write',
                        cmdType: 'foundation',
                        zclData: [{
                            attrId: 0x0401, // presentValue
                            dataType: 0x21, // dataType
                            attrData: lookup[value],
                        }],
                        cfg: cfg.xiaomi,
                    }];
                }
            } else if (type === 'get') {
                return [{
                    cid: cid,
                    cmd: 'read',
                    cmdType: 'foundation',
                    zclData: [{
                        attrId: 0x0401
                    }],
                    cfg: cfg.xiaomi,
                }];
            }
        },
},

@yozik04
Copy link
Contributor Author

yozik04 commented Jun 28, 2019

Trying:
Do I need to add something to fromZigbee.js ?

@yozik04
Copy link
Contributor Author

yozik04 commented Jun 28, 2019

zigbee2mqtt          | RangeError [ERR_OUT_OF_RANGE]: The value of "value" is out of range. It must be >= 0 and <= 65535. Received 72057598350131200
zigbee2mqtt          |     at checkInt (internal/buffer.js:35:11)
zigbee2mqtt          |     at writeU_Int16LE (internal/buffer.js:543:3)
zigbee2mqtt          |     at Buffer.writeUInt16LE (internal/buffer.js:551:10)
zigbee2mqtt          |     at Concentrate.write_number (/app/node_modules/zigbee-herdsman/node_modules/concentrate/index.js:63:21)
zigbee2mqtt          |     at Concentrate.<anonymous> (/app/node_modules/zigbee-herdsman/node_modules/concentrate/index.js:42:29)
zigbee2mqtt          |     at Array.forEach (<anonymous>)
zigbee2mqtt          |     at Concentrate.result (/app/node_modules/zigbee-herdsman/node_modules/concentrate/index.js:38:13)
zigbee2mqtt          |     at getDataTypeBuf (/app/node_modules/zigbee-herdsman/dist/zcl-packet/lib/foundation.js:463:24)
zigbee2mqtt          |     at /app/node_modules/zigbee-herdsman/dist/zcl-packet/lib/foundation.js:141:46
zigbee2mqtt          |     at Array.forEach (<anonymous>)

Probably dataType is wrong.

@yozik04
Copy link
Contributor Author

yozik04 commented Jun 28, 2019

0x0100000000070007 is 8 byte

@dzungpv
Copy link
Contributor

dzungpv commented Jun 28, 2019

@yozik04 do your last commit work?

@yozik04
Copy link
Contributor Author

yozik04 commented Jun 28, 2019

It successfully sends. But no change to the behaviour.

Zigbee publish to device 'living_room_right_curtain', genBasic - write - [{"attrId":1025,"dataType":66,"attrData":"\u0001\u0000\u0000\u0001\u0001\u0007\u0000\u0007"}] - {"manufSpec":1,"disDefaultRsp":1,"manufCode":4447} - 1

@dzungpv
Copy link
Contributor

dzungpv commented Jun 29, 2019

@yozik04 As i said from the start, this string write currently not work with z2m, if you use 0x42 then zcl-packet will convert it to ASCII string and not the original. May be we will find other way to write raw data (hexstream) @Koenkk ?
Also other packet capture here can help us:
https://github.com/TedTolboom/com.xiaomi-mi-zigbee/blob/master/drivers/curtain/device.js

@dzungpv
Copy link
Contributor

dzungpv commented Jun 29, 2019

@yozik04 let try this:

                const lookup = {
                    'positive': '\u0001\u0000\u0000\u0000\u0000\u0007\u0000\u0007',
                    'reverse': '\u0001\u0000\u0000\u0001\u0001\u0007\u0000\u0007',
                };

Or

                const lookup = {
                    'positive': '\u01\u00\u00\u00\u00\u07\u00\u07',
                    'reverse': '\u01\u00\u00\u01\u01\u07\u00\u07',
                };

with datatype 0x42

@yozik04
Copy link
Contributor Author

yozik04 commented Jun 29, 2019

@dzungpv first is equal to '\x01\x00\x00\x01\x01\x07\x00\x07' form
second is wrong syntax.

@dzungpv
Copy link
Contributor

dzungpv commented Jun 29, 2019

@yozik04 i see the last commit, it work or not?

Koenkk added a commit to Koenkk/zigbee-herdsman that referenced this issue Dec 15, 2019
Koenkk added a commit to Koenkk/zigbee-herdsman-converters that referenced this issue Dec 15, 2019
@Koenkk
Copy link
Owner

Koenkk commented Dec 15, 2019

Thanks, I've made some necessary modification to zigbee-herdsman in order to support this.

First make sure you update to the latest dev.

I've created an example changeset on how to write a certain feature: Koenkk/zigbee-herdsman-converters@c2b4b16 (probably this is not the correct payload for reverse, this is just an example)

Looking at your screenshots, the only thing you have to change each time is the payload: Koenkk/zigbee-herdsman-converters@c2b4b16#diff-3e0c275bd41af699153bf59d8dda4a2aR752

When for example sniffing the following write request:

image

You click on the String: which will highlight the bytes in blue below. After this add each byte postfixed with 0x and put this in the payload. So for this example it would be: const payload = [0x07, 0x00, 0x02, 0x01, 0x00, 0x00, 0x14];.

Now you can trigger the command by sending to zigbee2mqtt/[FRIENDLY_NAME]/set with payload {"reverse": ""}. Where reverse is the value in key of the toZigbee converter.

@yozik04
Copy link
Contributor Author

yozik04 commented Dec 15, 2019

Is it possible in convertSet to get previous 8 byte value?

@yozik04
Copy link
Contributor Author

yozik04 commented Dec 16, 2019

Can I actually do differently? I want to name the property to options or settings as all options are stored in one zigbee attribute.

mqtt zigbee2mqtt/[FRIENDLY_NAME]/set payloads to set options will be:

  • {"options": {"direction":"original","hand_open":true,"reset_move":false}} default
  • {"options": {"direction":"reverse"}} direction changed, hand_open resets
  • {"options": {"hand_open":false}} direction resets, hand_open is disabled
  • {"options": {"reset_move":true}} reset triggered, direction and hand_open changed to default

from these I will generate the right payload.

@Koenkk
Copy link
Owner

Koenkk commented Dec 16, 2019

Yes that is possible, change the key to options and parse the value as json.

@yozik04
Copy link
Contributor Author

yozik04 commented Dec 16, 2019

Good, thank you for help! Will try to implement and test it this week.

@bernardyeo
Copy link

Tried making the changes manually to devices.js and toZigbee.js. Ended up with the following error. Running on 1.8.0.

zigbee2mqtt:error 2019-12-16 23:41:22: Publish 'set' 'reverse' to '0x00158d00042b0ed3' failed: 'TypeError: argument must be a string'

Sent payload of {"reverse": ""} to zigbee2mqtt/[FRIENDLY_NAME]/set. I am unsure if I did anything wrong.

yozik04 pushed a commit to yozik04/zigbee-herdsman-converters that referenced this issue Dec 20, 2019
@yozik04
Copy link
Contributor Author

yozik04 commented Dec 20, 2019

@Koenkk Which package I should update to the latest dev?

When setting:

error 2019-12-20T14:49:01: Publish 'set' 'options' to 'living_room_left_curtain' failed: 'TypeError: argument must be a string'
info  2019-12-20T14:49:01: MQTT publish: topic 'zigbee2mqtt/bridge/log', payload '{"type":"zigbee_publish_error","message":"Publish 'set' 'options' to 'living_room_left_curtain' failed: 'TypeError: argument must be a string'","meta":{"friendly_name":"living_room_left_curtain"}}'

When getting:

error 2019-12-20T14:57:22: Publish 'get' 'options' to 'living_room_left_curtain' failed: 'Error: Cluster 'genBasic' has no attribute '1025''
info  2019-12-20T14:57:22: MQTT publish: topic 'zigbee2mqtt/bridge/log', payload '{"type":"zigbee_publish_error","message":"Publish 'get' 'options' to 'living_room_left_curtain' failed: 'Error: Cluster 'genBasic' has no attribute '1025''","meta":{"friendly_name":"living_room_left_curtain"}}'

Code here: https://github.com/yozik04/zigbee-herdsman-converters/tree/ZNCLDJ11LM_direction

yozik04 pushed a commit to yozik04/zigbee-herdsman-converters that referenced this issue Dec 21, 2019
@yozik04
Copy link
Contributor Author

yozik04 commented Dec 21, 2019

I managed to make it send. But it does not send Manufacturer code and device responds with 'Unsupported attribute'

@yozik04
Copy link
Contributor Author

yozik04 commented Dec 21, 2019

Another problem after update of my docker container to latest-dev I lost all my devices. 😢

yozik04 added a commit to yozik04/zigbee-herdsman-converters that referenced this issue Dec 21, 2019
yozik04 pushed a commit to yozik04/zigbee-herdsman-converters that referenced this issue Jan 2, 2020
yozik04 added a commit to yozik04/zigbee2mqtt.io that referenced this issue Jan 2, 2020
Koenkk pushed a commit to yozik04/zigbee2mqtt.io that referenced this issue Jan 3, 2020
Koenkk pushed a commit to yozik04/zigbee2mqtt.io that referenced this issue Jan 3, 2020
Koenkk added a commit to Koenkk/zigbee2mqtt.io that referenced this issue Jan 3, 2020
* Update ZNCLDJ11LM.md

Pull: Koenkk/zigbee-herdsman-converters#835
Issue: Koenkk/zigbee2mqtt#1639

* Update ZNCLDJ11LM.md

Co-authored-by: Koen Kanters <[email protected]>
Koenkk added a commit to Koenkk/zigbee-herdsman-converters that referenced this issue Jan 3, 2020
* ZNCLDJ11LM ZNCLDJ12LM options Koenkk/zigbee2mqtt#1639

* ZNCLDJ11LM get current position fix

* Linter happiness

* Linter

Co-authored-by: Koen Kanters <[email protected]>
@Koenkk
Copy link
Owner

Koenkk commented Jan 3, 2020

As this is now supported, I assume this can be closed, thank you very much @yozik04 !!

@Koenkk Koenkk closed this as completed Jan 3, 2020
@bernardyeo
Copy link

@Koenkk I updated zigbee-herdsman-converters to the latest version but encountered the following error when I attempt to set reverse_direction to true:

zigbee2mqtt:info 2020-01-03 22:47:38: ZNCLDJ11LM setting reverse direction
zigbee2mqtt:error 2020-01-03 22:47:38: Publish 'set' 'options' to '0x00158d00042b0ed3' failed: 'TypeError: argument must be a string'
zigbee2mqtt:info 2020-01-03 22:47:38: MQTT publish: topic 'zigbee2mqtt/bridge/log', payload '{"type":"zigbee_publish_error","message":"Publish 'set' 'options' to '0x00158d00042b0ed3' failed: 'TypeError: argument must be a string'","meta":{"friendly_name":"0x00158d00042b0ed3"}}'

@yozik04
Copy link
Contributor Author

yozik04 commented Jan 3, 2020

@bernardyeo you need to update other components too.

@Koenkk Thank you for your great support!

@bernardyeo
Copy link

@yozik04 Thanks I will give it a try.

Koenkk added a commit to Koenkk/zigbee2mqtt.io that referenced this issue Jan 7, 2020
* Update ZNCLDJ11LM.md

Pull: Koenkk/zigbee-herdsman-converters#835
Issue: Koenkk/zigbee2mqtt#1639

* Update ZNCLDJ11LM.md

Co-authored-by: Koen Kanters <[email protected]>
Koenkk added a commit to Koenkk/zigbee2mqtt.io that referenced this issue Jan 14, 2020
* Update ZNCLDJ11LM.md

Pull: Koenkk/zigbee-herdsman-converters#835
Issue: Koenkk/zigbee2mqtt#1639

* Update ZNCLDJ11LM.md

Co-authored-by: Koen Kanters <[email protected]>
@Prozpect
Copy link

Prozpect commented Dec 4, 2021

Not sure if people are still having this issue, but you can reverse direction by resetting the motor. You don't have to do this in the software, allthough that would be a great feature to have off course.
The first direction of motor after reset sets the direction in the software.
Try it, of it's wrong, reset again and try the other way. Worked for me.

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

No branches or pull requests

6 participants