Skip to content

Commit

Permalink
Fix motion_sensor_2 luminance and zoneStatus report handling
Browse files Browse the repository at this point in the history
  • Loading branch information
Mikael Berg committed Jan 7, 2025
1 parent 2b38c9e commit e6cfa4e
Showing 1 changed file with 17 additions and 19 deletions.
36 changes: 17 additions & 19 deletions drivers/motion_sensor_2/device.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@

const { ZigBeeDevice } = require('homey-zigbeedriver');
const { CLUSTER } = require('zigbee-clusters');
const TuyaSpecificCluster = require('../../lib/TuyaSpecificCluster');

Cluster.addCluster(TuyaSpecificCluster);
require('../../lib/TuyaSpecificCluster');

class motion_sensor_2 extends ZigBeeDevice {

Expand Down Expand Up @@ -40,26 +38,26 @@ 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 = this.onZoneStatusAttributeReport.bind(this);

// 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));
zclNode.endpoints[1].clusters[CLUSTER.POWER_CONFIGURATION.NAME]
.on('attr.batteryPercentageRemaining', this.onBatteryPercentageRemainingAttributeReport.bind(this));

// measure_luminance handler
zclNode.endpoints[1].clusters[CLUSTER.ILLUMINANCE_MEASUREMENT.NAME]
.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);
onZoneStatusAttributeReport({ zoneStatus, extendedStatus, zoneId, delay }) {
this.log('onZoneStatusChanged received:', zoneStatus, extendedStatus, zoneId, delay);
this.setCapabilityValue('alarm_motion', zoneStatus.alarm1).catch(this.error);
}

// Handle battery status attribute reports
Expand All @@ -70,19 +68,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 +357,4 @@ module.exports = motion_sensor_2;
"bindings": {}
}
}
} */
} */

0 comments on commit e6cfa4e

Please sign in to comment.