dresden-elektronik / deconz-rest-plugin

deCONZ REST-API plugin to control ZigBee devices
BSD 3-Clause "New" or "Revised" License
1.9k stars 498 forks source link

[Request Device Support] Aqara Curtain motor B1 #1654

Closed cacherocks closed 4 years ago

cacherocks commented 5 years ago

Node Info

Снимок экрана 2019-07-04 в 21 01 44

Basic cluster 0000

Снимок экрана 2019-07-04 в 21 11 55

Identify cluster 0003

Снимок экрана 2019-07-04 в 20 48 32

Windows covering cluster 0102

Снимок экрана 2019-07-04 в 20 49 20 Снимок экрана 2019-07-04 в 21 15 03 Снимок экрана 2019-07-04 в 21 15 38

Analog Output (Basic) cluster 000D

Снимок экрана 2019-07-04 в 21 16 02

Multistate Output (Basic) cluster 0013

Снимок экрана 2019-07-04 в 20 52 13

Power Configuration cluster 0001

Снимок экрана 2019-07-04 в 21 16 29

Node

Снимок экрана 2019-07-04 в 20 53 30

Description IMG_3987

Works both with the battery and from power supply. Review.

ebaauw commented 5 years ago

It looks like the previous (mains powered) Aqara curtain controller (lumi.curtain), except that this is an end device instead of a router. The REST API plugin exposes a curtain controller as a /lights resource. We probably need to whitelist this device, because Receiver on when idle is false.

I'm a bit worried that the Windows Covering cluster doesn't provide Current Position Lift Percentage. It probably reports the position on the Analog Output cluster. The REST API plugin already picks that up (the lumi.curtain uses both Current Position Lift Percentage and the Analog Output cluster), but for controlling the curtain, only the Windows Covering cluster is used.

Can you check that the Present Value of the Analog Output cluster reports 0 when the curtains are closed and 100 when open?

Can you also check that it responds to the Open, Close, Stop and Go to lift percentage commands from the Windows Covering cluster? Can you set Reversed in Config/Status to change the direction for Open en Close (in case you installed the band to pull the curtains the other way round)?

I'm afraid we need for the API v2 /devices resource scheme to expose the battery percentage; config.battery is available only to /sensors resources.

cacherocks commented 5 years ago

Ok, in the next 2-3 days I will check everything and write the result on all issues.

cacherocks commented 5 years ago
ebaauw commented 5 years ago
  • If the curtains do not move, then the buttons from the cluster do not control them, but receive the answer "success".
  • If the curtains are in the process of closing or opening, then the buttons from the cluster control (Open, Close and Stop). Lift value and lift percentage buttons do not work, but they get the answer "success"

Odd. Does the curtain controller connect to the RaspBee/ConBee directly, or did it select another parent node?

Present Value of the Analog Output cluster changes only from 0.00 to 1.00 during the opening of the curtains and returns to 0.00 again after opening. In the process of closing the curtains 0.00 does not change.

On the old controller, it changes from 0.00 (closed) to 100.00 (open), after calibrating the controller. Just like Current Position Life Percentage. Does the controller react when you try and write Present Value? Does the Multistate Output report anything?

I can not set the Reversed in Config/Status because Record button is inactive, below is a screenshot.

My bad, it's a read-only attribute. The setting is through Mode.

The values of open and closed are preserved from the aqara hub after binding to deconz.

Do you mean the calibration of the open and close position? Yes, that's handled by the motor itself, "behind" the ZigBee module. On the old model, you need to detach the ZigBee module to access the (other) reset button for the motor and make it re-calibrate.

cacherocks commented 5 years ago

Odd. Does the curtain controller connect to the RaspBee/ConBee directly, or did it select another parent node?

Directly, search and add through "add new light" via Phoscon.

My bad, it's a read-only attribute. The setting is through Mode.

I can set the checkbox and save the Reversed in Mode

Снимок экрана 2019-07-09 в 21 42 02

Do you mean the calibration of the open and close position?

Yes.

On the old controller, it changes from 0.00 (closed) to 100.00 (open), after calibrating the controller. Just like Current Position Life Percentage. Does the controller react when you try and write Present Value? Does the Multistate Output report anything?

No react, no report.

deven2020 commented 5 years ago

Hi

Can you confirm if this works with deconz/conbee 2? I am planning to get one.

Appreciate your feedback.

freenetwork commented 5 years ago

Hello. This curtain is working?

cacherocks commented 5 years ago

Hello. This curtain is working?

Hi Can you confirm if this works with deconz/conbee 2? I am planning to get one. Appreciate your feedback.

Hi, unfortunately not, I'm still waiting for B1 support to be added to the deconz. Maybe support will appear in 2.05.67. Like this issue to show the importance of adding support for B1.

cacherocks commented 5 years ago

@ebaauw Should we expect support for Aqara B1 in Deconz 2.05.67?

ebaauw commented 5 years ago

Should we expect support for Aqara B1 in Deconz 2.05.67?

I’m not the person to answer that question. I am just a deCONZ user, who on occasion contributes to this open source

Should we expect support for Aqara B1?

To support the B1, we first need to understand how to control it, i.e. what ZigBee commands make it open, close, and hold the curtains, and how it reports the current curtain position. If it’s not through the Window Covering nor through the Analog Output cluster, I wouldn’t know how.

freenetwork commented 5 years ago

I test zigbee2mqtt and change config from aqara curtain for aqara curtain b1. It is working. But without battery state

I want to say that the control commands work with the previous non-battery version

One problem i cant get responce with current position

cacherocks commented 5 years ago

I want to say that the control commands work with the previous non-battery version

So it will be enough to clone the settings from the old version of the "lumi.curtain" for the new version of the b1 "lumi.curtain.hagl04", good news.

ebaauw commented 5 years ago

Not according to your own tests. We must understand how to control the B1 from the GUI, before we can support it in the API.

freenetwork commented 5 years ago

https://github.com/freenetwork/ZNCLDJ12LM

I capture packets. Controls messages use previous

ebaauw commented 5 years ago

Thanks. Very insightful.

Unfortunately, you didn't capture opening nor closing the B1. I bet they use special attributes for that as well. And for reporting the current position.

First order of business is defining these attributes in general.xml and see if the B1 can be controlled using the deCONZ GUI.

freenetwork commented 5 years ago

Ok. I try today.

I did not capture the opening and closing since the motor was on the table. it is not calibrated and in packets it would not be possible to determine correctly the current position. I’ll try at home today when the motor is on the ledge and write there

freenetwork commented 5 years ago

My radio broadcast is very full. For this status message is difficult to choose. I take screenshoots from wireshark. Control message work from old model. I will try a new pairing at work, I hope the calibration from the motors will not disappear. Unfortunately, I reset my gateway to get developer mode. And now the broadcast is very clogged with messages so that I catch a new key again

Open for 26 percent. It is current position response. status message open 26 percent

Open for 46 percent. It is current position response. status message open 46 percent

cacherocks commented 5 years ago

Working config Aqara B1 for Homebridge based on Xiaomi hub: YinHangCode/homebridge-mi-aqara#272

cacherocks commented 5 years ago

Working config Aqara B1 for Home Assistant based on Xiaomi hub: home-assistant/home-assistant#25942

ebaauw commented 5 years ago

@cacherocks, that won’t be of any help. These integrate with the API offered by the Xiaomi hub. For deCONZ support, we need to integrate with the B1 itself over ZigBee.

cacherocks commented 5 years ago

@cacherocks, that won’t be of any help. These integrate with the API offered by the Xiaomi hub. For deCONZ support, we need to integrate with the B1 itself over ZigBee.

ok, what other data is needed, at least for the test addition of the motor to the deconz? Even without a battery, the main thing is motor control. The data that @freenetwork provided is not enough?

cacherocks commented 4 years ago

@freenetwork says that the control commands for version B1 are the same as for the old version of the motor. It turns out that you just need to copy everything from lumi.curtain to lumi.curtain.hagl04. Obtaining data on the battery charge can be omitted, it is not as interesting as managing curtains. Please do a PR with a copy of the data from lumi.curtain to lumi.curtain.hagl04.

ebaauw commented 4 years ago

Please do a PR with a copy of the data from lumi.curtain to lumi.curtain.hagl04.

The code checks if the model identifier starts with lumi.curtain, so it already matches lumi.curtain.hagl04.

ArkadiuszNiemiec commented 4 years ago

I have just tried to pair my new B1 but it did not want to connect to Deconz. @ebaauw how can I help? I have the dongle for sniffer.

ebaauw commented 4 years ago

I’m afraid you need to sniff the ZigBee commands that the Aqara hub sends to the controller. As mentioned above, I suspect they use manufacturer-specific attributes to control and report the motor.

As for pairing: it should appear in the deCONZ GUI, see screenshots above.

ArkadiuszNiemiec commented 4 years ago

@ebaauw oh, ok. I was looking into Deconz web interface. I am away for two weeks so cannot do it now but I will update as soon as possible. Thank you for your great work :smile: Edit: I am still learning but I hope that I will be able to contribute soon.

bkorda commented 4 years ago

How is the progress guys?

ArkadiuszNiemiec commented 4 years ago

How is the progress guys?

I gave up, sorry. Moved to zigbee2mqtt, it works there.

bkorda commented 4 years ago

How is the progress guys?

I gave up, sorry. Moved to zigbee2mqtt, it works there.

It's so sad. I wanna buy this one, but it stops me.

netRunner0 commented 4 years ago

How is the progress guys?

I gave up, sorry. Moved to zigbee2mqtt, it works there.

It's so sad. I wanna buy this one, but it stops me.

Homebridge+mi hub

bkorda commented 4 years ago

How is the progress guys?

I gave up, sorry. Moved to zigbee2mqtt, it works there.

It's so sad. I wanna buy this one, but it stops me.

Homebridge+mi hub

It's not an option.

rale commented 4 years ago

Based on the packet captures and what I read so far, it looks like 0x0055 on Analog Output cluster should be what controls opening/closing. Unfortunately, it doesn't seem like I can write to that attribute with deconz gui. Unlike other data types, there's just no input field when I open it.

55

Also, hitting 'read' on this screen seems to crash deconz. Is this just a bug in deconz handling of float attributes then?

ebaauw commented 4 years ago

Indeed, I’m seeing the same for other devices with an Analog Output or Analog Input cluster. We’ve had issues with the deCONZ core program not handling more exotic data types before, but no crash. It does handle attribute reports for float values correctly, though.

If you’re comfortable reading packets captured by a sniffer, you might try the deconz-cli-plugin to write Present Value. I’m not sure how to encode float values, though. Best close the curtains manually and sniff the attribute report to see what the value looks like in the payload.

The lumi.curtain also advertises an Analog Output cluster, whose Present Value mirrors the Current Position Lift Percentage from the Window Covering cluster. I haven’t tried writing that attribute, though.

rale commented 4 years ago

Thanks for pointing me to the cli plugin. I was able to confirm that I can set position via 0x0055 on analog output. The values are just 32-bit floating points.

For example, this will set it to 90%: zclattr 0xD8FD 1 0x000d 025500390000b44200

And this will do 50%: zclattr 0xD8FD 1 0x000d 025500390000484200

ebaauw commented 4 years ago

That's the good news we've been waiting for! Is 100.00 fully opened or fully closed?

I'm sorry, I fail to understand the payload: there seems to be a superfluous 00 at the end?

025500390000b44200
 |   | |       | |
 |   | |       | + ???
 |   | |       + Value: 0x42b40000 (90.0)
 |   | + Data type: 0x39 (float)
 |   + Attribute: 0x0055 (Present Value)
 + Command: 0x02 (Write Attributes)

0x42b40000 = 0b 0 10000101 01101000000000000000000 = 1.40625 * 2^6 = 90.0
                |        |                       + fraction: 0xb40000 / 2^23 = 1.40625
                |        + exponent: 0x85 - 127 = 6
                + sign: positive

0x42480000 = 0b 0 10000100 10010000000000000000000 = 1.5625 * 2^5 = 50.0
                |        |                       + fraction: 0xc80000 / 2^23 = 1.5625
                |        + exponent: 0x84 - 127 = 5
                + sign: positive
ebaauw commented 4 years ago

Could you try my commit above?

It should create a /lights resource for the B1, of type Window covering device, when you search for new devices from Phoscon or open the network from the old web app. state.on and state.bri should reflect the motor's state, but updating these attributes hasn't yet been implemented.

rale commented 4 years ago

Looks good, I have a light entry now. And you're correct, the extra 00 on the end wasn't needed, you can drop that.

As for the direction, 100 = fully opened, 0 = fully closed.

bkorda commented 4 years ago

So when do you plan support b1 motors in release (stable) version?

FletchNZ commented 4 years ago

Yeah, I would also be keen on getting this change pushed to production. Thanks heaps for your hard work and getting this supported!

ebaauw commented 4 years ago

Above commit should add support for controlling the B1 by setting state.bri. It works for my old model lumi.curtain, but can some-one (@rale maybe) please test it on an actual B1?

Setting state.on still doesn't work - I need to refactor DeRestPluginPrivate::setLightState(), so state.on can be translated to state.bri.

@manup, I had to duplicate the body from DeRestPluginPrivate::writeAttribute() code, since deCONZ::ZclAttribute doesn't handle deCONZ::ZclSingleFloat correctly (it sends 8 bytes instead of 4). Same happens when trying to write the attribute in the GUI.

ebaauw commented 4 years ago

Above commit provides full support for the B1:

ebaauw commented 4 years ago

Can some-one please test and confirm that the B1 works in 2.05.75?

rale commented 4 years ago

It looks like state.bri is working correctly, but state.on is not.

Both true and false for on seem to result in bri being set to 0:

$ curl -X PUT -d '{"on":false }' -s http://127.0.0.1:8080/api/xxxxxxxxxx/lights/1/state | python -m json.tool
[
    {
        "success": {
            "/lights/1/state/bri": 0
        }
    }
]
$ curl -X PUT -d '{"on":true }' -s http://127.0.0.1:8080/api/xxxxxxxxxx/lights/1/state | python -m json.tool
[
    {
        "success": {
            "/lights/1/state/bri": 0
        }
    }
]

Setting on to true and bri to a value at the same time returns the intended bri value, but actually results in curtains moving to 0.

$ curl -X PUT -d '{"on": true, "bri":120 }' -s http://127.0.0.1:8080/api/xxxxxxxxxx/lights/1/state |  python -m json.tool
[
    {
        "success": {
            "/lights/1/state/bri": 120
        }
    }
]
ebaauw commented 4 years ago

Thanks for testing!

It looks like state.bri is working correctly

That's good news.

but state.on is not.

As the B1 has no Open or Close commands, on should be treated as bri 254 (true) or 0 (false). Looks like something is still going wrong there, between mapping on to bri, mapping bri to lift percentage, and inverting the lift percentage, because Xiaomi has the open and closed values reversed.

Both true and false for on seem to result in bri being set to 0

Do the curtains move alright, open for setting on to true, and close for setting on to false? Or do they move to 0 in both cases?

Setting on to true and bri to a value at the same time returns the intended bri value, but actually results in curtains moving to 0.

Not good. on should be ignored when bri is given.

rale commented 4 years ago

Do the curtains move alright, open for setting on to true, and close for setting on to false? Or do they move to 0 in both cases?

They move to 0 in both cases.

ebaauw commented 4 years ago

Can some-one please test and confirm that the B1 works in 2.05.76?

krastek commented 4 years ago

Just a quick feedback: I use Conbee II with Home Assistant 0.109.2 on top of RaspberryPi3. I updated the firmware to 2.05.76 and have successfuly addedd B1 to the system. I can open, close, set the position of the curtain from HA. The state is always reported as closed and position as 0. Deconz GUI gives me no possibility of moving the curtain. It doesn't report the correct state of the curtain either - it is always on with full brightness. Thank you for pushing this forward!

ebaauw commented 4 years ago

The B1 doesn’t use the Window Covering cluster. Set Present Value of the Analog Output cluster from the GUI.

Can you read that cluster in the GUI, and see if the state gets updated in HA? Can you check what the API responds when GETting the B1’s /lights resource?

krastek commented 4 years ago

Disclaimer: Please note that my knowledge on the subject of digging information from deconz is virtually non existent. I just happen to be using HA+Conbee and wanting to have a usable Aqara B1. Getting to your questions: I managed to "read" Analog Output Cluster/Present value and it got picked by HA. Unfortunately I don't know how to check the thing with API. I can do it, if I get instructions, though, but I won't be offended, if you'd prefer to get the information from someone with better understanding of all this.

ebaauw commented 4 years ago

I managed to "read" Analog Output Cluster/Present value and it got picked by HA.

So that's good news: at least the value gets propagated from the device through deCONZ through the REST API to HA. What worries me is that the device doesn't send a report attributes notification when it changes state. This is Xiaomi, it doesn't support configuration; it should just work. Could you power cycle the motor (disconnect the battery for 10 sec), fully open/close it (so it gets a feel for the distance to scale the percentage) and see if it updates after that?

Unfortunately I don't know how to check the thing with API. You need to do a GET of the corresponding /lights resource. I use ph for that, which is a little tool I wrote to troubleshoot for Homebridge Hue, but any REST API client (like postman or even curl) would do. See the README for a link to the API documentation.