Skip to content

Commit 4f9d36c

Browse files
committed
Tuya: Add support for tuya closable sensors
1 parent e39b814 commit 4f9d36c

6 files changed

Lines changed: 133 additions & 15 deletions

File tree

zigbeegeneric/integrationpluginzigbeegeneric.cpp

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -345,20 +345,6 @@ void IntegrationPluginZigbeeGeneric::createConnections(Thing *thing)
345345

346346
if (thing->thingClassId() == doorSensorThingClassId) {
347347
connectToIasZoneInputCluster(thing, endpoint, "closed", true);
348-
ZigbeeClusterIasZone *iasZoneCluster = endpoint->inputCluster<ZigbeeClusterIasZone>(ZigbeeClusterLibrary::ClusterIdIasZone);
349-
if (!iasZoneCluster) {
350-
qCWarning(dcZigbeeGeneric()) << "Could not find IAS zone cluster on" << thing << endpoint;
351-
} else {
352-
if (iasZoneCluster->hasAttribute(ZigbeeClusterIasZone::AttributeZoneStatus)) {
353-
qCDebug(dcZigbeeGeneric()) << thing << iasZoneCluster->zoneStatus();
354-
ZigbeeClusterIasZone::ZoneStatusFlags zoneStatus = iasZoneCluster->zoneStatus();
355-
thing->setStateValue(doorSensorClosedStateTypeId, !zoneStatus.testFlag(ZigbeeClusterIasZone::ZoneStatusAlarm1) && !zoneStatus.testFlag(ZigbeeClusterIasZone::ZoneStatusAlarm2));
356-
}
357-
connect(iasZoneCluster, &ZigbeeClusterIasZone::zoneStatusChanged, thing, [=](ZigbeeClusterIasZone::ZoneStatusFlags zoneStatus, quint8 extendedStatus, quint8 zoneId, quint16 delays) {
358-
qCDebug(dcZigbeeGeneric()) << "Zone status changed to:" << zoneStatus << extendedStatus << zoneId << delays;
359-
thing->setStateValue(doorSensorClosedStateTypeId, !zoneStatus.testFlag(ZigbeeClusterIasZone::ZoneStatusAlarm1) && !zoneStatus.testFlag(ZigbeeClusterIasZone::ZoneStatusAlarm2));
360-
});
361-
}
362348
}
363349

364350
if (thing->thingClassId() == motionSensorThingClassId) {

zigbeetuya/README.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,12 @@ This plugin adds support for ZigBee devices by Tuya.
44

55
## Supported Things
66

7-
* Smart plugs with energy metering (TS011 plugs)
7+
* Smart plugs with energy metering
8+
* PIR motion sensors
9+
* Mm Wave presence sensors
10+
* Vibration sensors
11+
* H&T sensors
12+
* H&T Display sensors
13+
* AirHouseKeeper
14+
* Smoke sensors
15+
* Door/Window sensors
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
--> ZigbeeNode(0x1577, A4:C1:38:EB:34:5E:C9:DB, _TZ3000_7d8yme6f (0x1141), TS0203, End device, RxOn:false)
2+
ZigbeeNodeEndpoint(0x01, Zigbee::ZigbeeProfileHomeAutomation, Zigbee::HomeAutomationDeviceIasZone)
3+
Manufacturer: "_TZ3000_7d8yme6f"
4+
Model "TS0203"
5+
Input clusters ( 4 )
6+
- ZigbeeCluster(0x0000, Basic, Server)
7+
- ZigbeeClusterAttribute(0x0004, ZigbeeDataType(Character string, _TZ3000_7d8yme6f))
8+
- ZigbeeClusterAttribute(0x0005, ZigbeeDataType(Character string, TS0203))
9+
- ZigbeeCluster(0x0001, PowerConfiguration, Server)
10+
- ZigbeeCluster(0x0003, Identify, Server)
11+
- ZigbeeCluster(0x0500, IasZone, Server)
12+
- ZigbeeClusterAttribute(0x0000, ZigbeeDataType(16-bit bitmap, 0x04 0x00))
13+
Output clusters ( 8 )
14+
- ZigbeeCluster(0x0008, LevelControl, Client)
15+
- ZigbeeCluster(0x000a, Time, Client)
16+
- ZigbeeCluster(0x0019, OtaUpgrade, Client)
17+
- ZigbeeCluster(0x0004, Groups, Client)
18+
- ZigbeeCluster(0x0005, Scenes, Client)
19+
- ZigbeeCluster(0x0006, OnOff, Client)
20+
- ZigbeeCluster(0x1000, TouchlinkCommissioning, Client)
21+
- ZigbeeCluster(0x0003, Identify, Client)

zigbeetuya/integrationpluginzigbeetuya.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,16 @@ bool IntegrationPluginZigbeeTuya::handleNode(ZigbeeNode *node, const QUuid &/*ne
170170
return true;
171171
}
172172

173+
if (match(node, "TS0203", {"_TZ3000_7d8yme6f"})) {
174+
// Implements IAS Zone spec, but doesn't reply to ZoneType attribute, thus not handled properly by generic plugin
175+
ZigbeeNodeEndpoint *endpoint = node->getEndpoint(0x01);
176+
configurePowerConfigurationInputClusterAttributeReporting(endpoint);
177+
bindCluster(endpoint, ZigbeeClusterLibrary::ClusterIdIasZone);
178+
configureIasZoneInputClusterAttributeReporting(endpoint);
179+
enrollIasZone(endpoint, 0x42);
180+
createThing(closableSensorThingClassId, node);
181+
return true;
182+
}
173183
return false;
174184
}
175185

@@ -667,6 +677,16 @@ void IntegrationPluginZigbeeTuya::createConnections(Thing *thing)
667677

668678
});
669679
}
680+
681+
if (info->thing()->thingClassId() == closableSensorThingClassId) {
682+
ZigbeeNodeEndpoint *endpoint = node->getEndpoint(1);
683+
if (!endpoint) {
684+
qCWarning(dcZigbeeTuya()) << "Unable to find endpoint 1 on node" << node;
685+
info->finish(Thing::ThingErrorHardwareNotAvailable, QT_TR_NOOP("Unable to find endpoint 1 on Zigbee node."));
686+
return;
687+
}
688+
connectToIasZoneInputCluster(thing, endpoint, "closed", true);
689+
}
670690
}
671691

672692
void IntegrationPluginZigbeeTuya::executeAction(ThingActionInfo *info)

zigbeetuya/integrationpluginzigbeetuya.json

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -703,6 +703,86 @@
703703
"defaultValue": false
704704
}
705705
]
706+
},
707+
{
708+
"id": "82a859f0-41ed-4a53-93b0-260a1435ac75",
709+
"name": "closableSensor",
710+
"displayName": "Door/window sensor",
711+
"createMethods": ["auto"],
712+
"interfaces": ["closablesensor", "battery", "wirelessconnectable"],
713+
"paramTypes": [
714+
{
715+
"id": "06a60993-2ce7-484d-9ffd-13020be8fa78",
716+
"name": "ieeeAddress",
717+
"displayName": "IEEE adress",
718+
"type": "QString",
719+
"defaultValue": "00:00:00:00:00:00:00:00"
720+
},
721+
{
722+
"id": "7850cdee-7d65-48f9-a08a-4cabe9c20594",
723+
"name": "networkUuid",
724+
"displayName": "Zigbee network UUID",
725+
"type": "QString",
726+
"defaultValue": ""
727+
}
728+
],
729+
"stateTypes": [
730+
{
731+
"id": "6d4523c2-66f1-4fbf-b0d9-bd11a1920b50",
732+
"name": "closed",
733+
"displayName": "Closed",
734+
"displayNameEvent": "Opened or closed",
735+
"type": "bool",
736+
"defaultValue": false
737+
},
738+
{
739+
"id": "948bc2da-23fb-44fd-a74c-c917bf657bf0",
740+
"name": "tampered",
741+
"displayName": "Tampered",
742+
"displayNameEvent": "Tampered",
743+
"type": "bool",
744+
"defaultValue": false
745+
},
746+
{
747+
"id": "34a8f7f1-19f8-47be-a1b2-4d7ea52fee1e",
748+
"name": "batteryLevel",
749+
"displayName": "Battery level",
750+
"displayNameEvent": "Battery level changed",
751+
"type": "int",
752+
"minValue": 0,
753+
"maxValue": 100,
754+
"unit": "Percentage",
755+
"defaultValue": 50
756+
},
757+
{
758+
"id": "455e1ebc-5534-4053-8db3-c0b6b79f8c41",
759+
"name": "batteryCritical",
760+
"displayName": "Battery critical",
761+
"displayNameEvent": "Battery critical changed",
762+
"type": "bool",
763+
"defaultValue": false
764+
},
765+
{
766+
"id": "10d8aa94-943e-40f6-a10e-0ac77bcdecd3",
767+
"name": "connected",
768+
"displayName": "Connected",
769+
"displayNameEvent": "Connected or disconnected",
770+
"type": "bool",
771+
"defaultValue": false,
772+
"cached": false
773+
},
774+
{
775+
"id": "4ef57e47-2b83-4d41-8cfb-21bf2f5ee62d",
776+
"name": "signalStrength",
777+
"displayName": "Signal strength",
778+
"displayNameEvent": "Signal strength changed",
779+
"type": "uint",
780+
"minValue": 0,
781+
"maxValue": 100,
782+
"unit": "Percentage",
783+
"defaultValue": 0
784+
}
785+
]
706786
}
707787
]
708788
}

zigbeetuya/meta.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,8 @@
99
],
1010
"categories": [
1111
"socket",
12+
"sensor",
13+
"door",
14+
"energy"
1215
]
1316
}

0 commit comments

Comments
 (0)