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

Fix support for PIR/illumination sensor _TZE200_3towulqd #1027

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 18 additions & 16 deletions drivers/motion_sensor_2/device.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const { ZigBeeDevice } = require('homey-zigbeedriver');
const { CLUSTER } = require('zigbee-clusters');
const TuyaSpecificCluster = require('../../lib/TuyaSpecificCluster');

Cluster.addCluster(TuyaSpecificCluster);
CLUSTER.addCluster(TuyaSpecificCluster);

class motion_sensor_2 extends ZigBeeDevice {

Expand All @@ -31,7 +31,7 @@ class motion_sensor_2 extends ZigBeeDevice {
},{
endpointId: 1,
cluster: CLUSTER.ILLUMINANCE_MEASUREMENT,
attributeName: 'IlluminanceMeasured',
attributeName: 'measuredValue',
minInterval: 60, // Minimum interval (1 minute)
maxInterval: 3600, // Maximum interval (1 hour)
minChange: 10, // Report changes above 10 lux
Expand All @@ -40,27 +40,29 @@ class motion_sensor_2 extends ZigBeeDevice {
}

// alarm_motion handler
zclNode.endpoints[1].clusters[CLUSTER.IAS_ZONE.NAME]
.on('attr.zoneStatus', this.onZoneStatusAttributeReport.bind(this));
zclNode.endpoints[1].clusters[CLUSTER.IAS_ZONE.NAME]
.onZoneStatusChangeNotification = payload => {
this.onZoneStatusChangeNotification(payload);
};

// measure_battery and alarm_battery handler
zclNode.endpoints[1].clusters[CLUSTER.POWER_CONFIGURATION.NAME]
.on('attr.batteryPercentageRemaining', this.onBatteryPercentageRemainingAttributeReport.bind(this));

// measure_illuminance handler
zclNode.endpoints[1].clusters[CLUSTER.ILLUMINANCE_MEASUREMENT.NAME]
.on('attr.IlluminanceMeasured', this.onIlluminanceMeasuredAttributeReport.bind(this));
.on('attr.measuredValue', this.onIlluminanceMeasuredAttributeReport.bind(this));

// Tuya specific cluster handler
zclNode.endpoints[1].clusters.tuya.on("reporting", value => this.processResponse(value));

}

// Handle motion status attribute reports
onZoneStatusAttributeReport(status) {
this.log("Motion status: ", status.alarm1);
this.setCapabilityValue('alarm_motion', status.alarm1).catch(this.error);
}
// Handle motion status alarms
onZoneStatusChangeNotification({zoneStatus, extendedStatus, zoneId, delay}) {
this.log("Motion status: ", zoneStatus.alarm1);
this.setCapabilityValue('alarm_motion', zoneStatus.alarm1).catch(this.error);
}

// Handle battery status attribute reports
onBatteryPercentageRemainingAttributeReport(batteryPercentageRemaining) {
Expand All @@ -70,19 +72,19 @@ class motion_sensor_2 extends ZigBeeDevice {
this.setCapabilityValue('measure_battery', batteryLevel).catch(this.error);
this.setCapabilityValue('alarm_battery', batteryLevel < batteryThreshold).catch(this.error);
}

// Handle illuminance attribute reports
onIlluminanceMeasuredAttributeReport(measuredValue) {
const luxValue = Math.round(Math.pow(10, ((measuredValue - 1) / 10000))); // Convert measured value to lux
this.log('measure_illuminance | Illuminance (lux):', luxValue);
this.setCapabilityValue('measure_illuminance', luxValue).catch(this.error);
this.log('measure_luminance | Illuminance (lux):', luxValue);
this.setCapabilityValue('measure_luminance', luxValue).catch(this.error);
}

// Process Tuya-specific data
processResponse(data) {
this.log('Tuya-specific cluster data:', data);
}

// Handle device removal
onDeleted() {
this.log('Motion Sensor removed');
Expand Down Expand Up @@ -359,4 +361,4 @@ module.exports = motion_sensor_2;
"bindings": {}
}
}
} */
} */