Skip to content

Commit

Permalink
Support Xiaomi WXKG02LM switch
Browse files Browse the repository at this point in the history
Setup

* start sensor search
* press both buttons until LEDs start to blink

Button events

* left button: 1002
* right button: 2002
* both buttons: 3002


Issues #249

#165
  • Loading branch information
manup committed Nov 3, 2017
1 parent 6c0b89a commit e395207
Showing 1 changed file with 37 additions and 3 deletions.
40 changes: 37 additions & 3 deletions de_web_plugin.cpp
Expand Up @@ -110,6 +110,7 @@ static const SupportedDevice supportedDevices[] = {
{ VENDOR_JENNIC, "lumi.sensor_motion", jennicMacPrefix },
{ VENDOR_JENNIC, "lumi.sensor_switch", jennicMacPrefix },
{ VENDOR_JENNIC, "lumi.sensor_cube", jennicMacPrefix },
{ VENDOR_JENNIC, "lumi.sensor_86sw2", jennicMacPrefix },
{ VENDOR_UBISYS, "D1", ubisysMacPrefix },
{ VENDOR_NONE, "Z716A", netvoxMacPrefix },
{ 0, 0, 0 }
Expand Down Expand Up @@ -2544,6 +2545,13 @@ void DeRestPluginPrivate::addSensorNode(const deCONZ::Node *node)
{
fpOpenCloseSensor.inClusters.push_back(ci->id());
}
else if (modelId == QLatin1String("lumi.sensor_86sw2"))
{
if (i->endpoint() == 0x01) // create sensor only for first endpoint
{
fpSwitch.inClusters.push_back(ci->id());
}
}
else if (modelId.startsWith(QLatin1String("lumi.sensor_switch")))
{
fpSwitch.inClusters.push_back(ci->id());
Expand Down Expand Up @@ -3369,7 +3377,20 @@ void DeRestPluginPrivate::updateSensorNode(const deCONZ::NodeEvent &event)
// filter endpoint
if (event.endpoint() != i->fingerPrint().endpoint)
{
continue;
if ((event.node()->address().ext() & macPrefixMask) == jennicMacPrefix)
{
if (i->modelId() == QLatin1String("lumi.sensor_86sw2"))
{ // 3 endpoints: 1 sensor
}
else
{
continue;
}
}
else
{
continue;
}
}

// assume data must be in server cluster attribute
Expand Down Expand Up @@ -3832,8 +3853,16 @@ void DeRestPluginPrivate::updateSensorNode(const deCONZ::NodeEvent &event)
{
// TODO better button handler
quint32 button;
if (ia->numericValue().u8 == 0) { button = S_BUTTON_1 + S_BUTTON_ACTION_INITIAL_PRESS; }
else { button = S_BUTTON_1 + S_BUTTON_ACTION_SHORT_RELEASED; }

if (i->modelId() == QLatin1String("lumi.sensor_86sw2"))
{
button = (S_BUTTON_1 * event.endpoint()) + S_BUTTON_ACTION_SHORT_RELEASED;
}
else
{
if (ia->numericValue().u8 == 0) { button = S_BUTTON_1 + S_BUTTON_ACTION_INITIAL_PRESS; }
else { button = S_BUTTON_1 + S_BUTTON_ACTION_SHORT_RELEASED; }
}

item->setValue(button);

Expand Down Expand Up @@ -9366,6 +9395,11 @@ void DeRestPluginPrivate::delayedFastEnddeviceProbe()
return;
}

if (modelId.startsWith(QLatin1String("lumi.")))
{
return; // Xiaomi devices won't respond to ZCL read
}

deCONZ::ApsDataRequest apsReq;
std::vector<quint16> attributes;

Expand Down

27 comments on commit e395207

@etique57
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!!!

I've built the latest greatest following the readme instructions (even using 2.04.85 packages).

Once done, I restarted. The version shown in the settings is 2.04.84, is it normal?

I think I can make the aqara switch join the network (it seems to blink properly) but unfortunately nothing show up in the interface.

Am I doing something wrong?

@manup
Copy link
Member Author

@manup manup commented on e395207 Nov 4, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To build the latest commits replace:

git checkout -b mybranch V2_04_84

with

git checkout -b mybranch master

otherwise you'll get only commits up to 2.04.84.

@etique57
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok thanks, indeed I think I've built the plugin to 2.04.85 now (shows up in the interface). I checked the de_web_plugin.cpp file and I had the latest file.

But unfortunately the switch still doesn't appear in the interface when I add it.

I feel stupid to ask, but the "sensor search" is started from the "devices" menu, right?

@manup
Copy link
Member Author

@manup manup commented on e395207 Nov 4, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The switch currently only shows up in the REST API not in the app interface. It will be added to show up in devices/switches (Phoscon app).

I feel stupid to ask, but the "sensor search" is started from the "devices" menu, right?

Yes currently there is no wizard available for the switch so it must be added via devices > sensors > Add new sensor > Other. On success there should be a message Sensor ready.

From there custom rules must be created via REST API. It will take some time until this is supported via Phoscon app since, unlike other switches the Xiaomi switch doesn't control a group to which lights can be added, therefore integration takes more time here.

Later on we want to add an editor which allows to specify actions for any button of any switch. This will make configuring switches a lot easier than the current group based limited approach.

@etique57
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@manup thanks.

I must be missing something still that you think is obvious ;) But I'm very basic... I see no sensors submenu anywhere in the webinteface (which I guess is the Phoscon app as you call it).

So I guess there is another "menu" I should be able to access (from the command line?). Or maybe I need to update the web interface to a higher version.

@manup
Copy link
Member Author

@manup manup commented on e395207 Nov 4, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry my bad, thought you refer to the new beta Phoscon app.

In the "old" webapp you need to open the network via Menu > Settings > Open Network; then add the switch as described above. But it will be only visible in the REST API not the webapp itself.

@etique57
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No problem @manup ;) I requested an invite on the new beta app.

In the mean time, I'm following the REST API doc :)

@pietervandersluis
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello :-), I've got a single button version of the Aqara switch here and it doesn't seem to be detected.

If tried to make some sense of the changes made to the code above and it seems like the only difference would be the number of buttons and the ModelID.

If you'd like I could probably send more information about the switch.

@manup
Copy link
Member Author

@manup manup commented on e395207 Nov 4, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please provide the model id as reported in basic cluster.
I think it should be enough to add the model id on various places.

@pietervandersluis
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm guessing that the model_id would then be: 0x7816?

screen shot 2017-11-04 at 16 49 43

@pietervandersluis
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The other two hex numbered devices are Aqara door sensors.

@manup
Copy link
Member Author

@manup manup commented on e395207 Nov 4, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, it is the field Model.

Here: lumi.sensor_86sw2

image

If it is not visible you may need to rejoin the switch.

@pietervandersluis
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The model field is empty. I did install the beta 2.04.85, with te master version of the deconz-rest-plugin

empty

@manup
Copy link
Member Author

@manup manup commented on e395207 Nov 4, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it visible in the basic cluster view?

(click on second circle of the switch node)

@pietervandersluis
Copy link

@pietervandersluis pietervandersluis commented on e395207 Nov 4, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is saying only this; which looks nothing like lumi.sensor_86sw2

screen shot 2017-11-04 at 17 03 59

@manup
Copy link
Member Author

@manup manup commented on e395207 Nov 4, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nearly there :) now open the "Cluster info" panel from menu and click on the "Basic" cluster

@etique57
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can see it in the rest api :) now I can create my first rule, yay!

@pietervandersluis
Copy link

@pietervandersluis pietervandersluis commented on e395207 Nov 4, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The model id is also empty there, but I also tried the reset factory button and I think it is decoupled now or something.

screen shot 2017-11-04 at 17 17 01

@pietervandersluis
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oke I've tried to fetch the information from a bulb
and it worked. trying the switch again

@pietervandersluis
Copy link

@pietervandersluis pietervandersluis commented on e395207 Nov 4, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Jeeej found it :-D, I had to add it again.

screen shot 2017-11-04 at 17 22 42

@manup
Copy link
Member Author

@manup manup commented on e395207 Nov 4, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

excellent :) I'll add it

@pietervandersluis
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:-D, Wow thank you

@etique57
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@manup sorry to bother again, I can create a rule which seems correct (I even use the ep id for the BIND event), but I cannot get it to work.

Do you have an example of a rule that works with this button?

Thanks!

@ebaauw
Copy link
Collaborator

@ebaauw ebaauw commented on e395207 Nov 4, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

excellent :) I'll add it

Just a single button with only buttonevent value 1002?

@pietervandersluis
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How can I check this for you?

@pietervandersluis
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is te result:

Before press:

% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 312 100 312 0 0 3870 0 --:--:-- --:--:-- --:--:-- 4216
{
"config": {
"on": true,
"reachable": true
},
"ep": 1,
"etag": "baa02b3bb25ed9ac68ad9bd2bdb405a1",
"manufacturername": "LUMI",
"mode": 1,
"modelid": "lumi.sensor_86sw1",
"name": "lumi.sensor_86sw1 15",
"state": {
"buttonevent": 1002,
"lastupdated": "2017-11-04T19:14:12"
},
"type": "ZHASwitch",
"uniqueid": "00:15:8d:00:01:2a:34:44-01-0006"
}

After pressing:

% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 312 100 312 0 0 4534 0 --:--:-- --:--:-- --:--:-- 4875
{
"config": {
"on": true,
"reachable": true
},
"ep": 1,
"etag": "92434baa2a93a98e50b3aff433e67bb2",
"manufacturername": "LUMI",
"mode": 1,
"modelid": "lumi.sensor_86sw1",
"name": "lumi.sensor_86sw1 15",
"state": {
"buttonevent": 1002,
"lastupdated": "2017-11-04T19:15:08"
},
"type": "ZHASwitch",
"uniqueid": "00:15:8d:00:01:2a:34:44-01-0006"
}

@etique57
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I had to get rid of the BIND for a PUT and it works perfect :)

Please sign in to comment.