Skip to content
Open
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion .homeycompose/app.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"Samotech",
"Silvercrest",
"Smart9",
"Zemismart",
"Zemismart",
"Zigbee",
"Woox",
"Sensor",
Expand Down
2 changes: 2 additions & 0 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ const { debug } = require('zigbee-clusters');
class tuyazigbee extends Homey.App {

onInit() {
//require('inspector').open(9222, '0.0.0.0', true);

this.log('Tuya Zigbee app is running...');

// Register the action card for christmas lights
Expand Down
92 changes: 92 additions & 0 deletions app.json
Original file line number Diff line number Diff line change
Expand Up @@ -10248,6 +10248,98 @@
}
]
},
{
"id": "temperaturesensor_ths317",
"name": {
"en": "Temperature Sensor THS317"
},
"class": "sensor",
"platforms": [
"local"
],
"connectivity": [
"zigbee"
],
"capabilities": [
"measure_temperature",
"measure_battery",
"alarm_battery"
],
"energy": {
"batteries": [
"AAA",
"AAA"
]
},
"images": {
"small": "/drivers/temperaturesensor_ths317/assets/images/small.png",
"large": "/drivers/temperaturesensor_ths317/assets/images/large.png",
"xlarge": "/drivers/temperaturesensor_ths317/assets/images/xlarge.png"
},
"zigbee": {
"manufacturerName": [
"_TZE200_iq4ygaai"
],
"productId": [
"TS0201"
],
"endpoints": {
"1": {
"clusters": [
0,
1,
61184,
1026
],
"bindings": [
1,
1026,
61184
]
}
},
"learnmode": {
"image": "/drivers/temperaturesensor_ths317/assets/learnmode.svg",
"instruction": {
"en": "hold button for 10 seconds to reset the device and enter learn mode"
}
}
},
"settings": [
{
"id": "temperature_offset",
"type": "number",
"label": {
"en": "Temperature offset (°C)"
},
"hint": {
"en": "Set a value to compensate a temperature offset.\nRange: -10 - 10, step size 0.1, \ndefault: 0 [°C]"
},
"value": 0,
"attr": {
"min": -10,
"max": 10,
"step": 0.1
}
},
{
"id": "batteryThreshold",
"type": "number",
"label": {
"en": "Battery Low Alarm Voltage Threshold (percent)"
},
"hint": {
"en": "This setting determines the threshold before a battery alarm is given."
},
"value": 20,
"attr": {
"step": 1,
"min": 10,
"max": 90
}
}
]
},
{
"id": "temphumidsensor",
"name": {
Expand Down
43 changes: 43 additions & 0 deletions drivers/temperaturesensor_ths317/assets/icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19 changes: 19 additions & 0 deletions drivers/temperaturesensor_ths317/assets/learnmode.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
101 changes: 101 additions & 0 deletions drivers/temperaturesensor_ths317/device.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
'use strict';

const { Cluster } = require('zigbee-clusters');
const TuyaSpecificCluster = require('../../lib/TuyaSpecificCluster');
const TuyaSpecificClusterDevice = require('../../lib/TuyaSpecificClusterDevice');
const { V1_TEMPHUMID_SENSOR_DATA_POINTS } = require('../../lib/TuyaDataPoints');
const { getDataValue } = require('../../lib/TuyaHelpers');

// Register Tuya cluster with Zigbee
Cluster.addCluster(TuyaSpecificCluster);

class temperaturesensor_ths317 extends TuyaSpecificClusterDevice {

async onNodeInit({ zclNode }) {
super.onNodeInit({ zclNode });

// Enable debug logging
//this.enableDebug();

this.printNode();

// Initialize reporting settings from the device settings
this.initializeReportingSettings();

// Listen for Tuya cluster responses
const tuyaCluster = this.zclNode.endpoints[1].clusters.tuya;
if (tuyaCluster) {
tuyaCluster.on("response", this.onTuyaClusterMessage.bind(this));
} else {
this.error('Tuya cluster not found on endpoint 1');
}
}

initializeReportingSettings() {
this.temperatureOffset = this.getSetting('temperature_offset')|| 0;
this.batteryThreshold = this.getSetting('batteryThreshold')|| 20;
}

onTuyaClusterMessage(message) {
this.log('Tuya cluster message:', message);

try {
// Use helper function to parse datapoint value
const value = getDataValue(message);
const dp = message.dp;

this.log(`Datapoint ${dp} report:`, value);

// Handle different datapoints
switch (dp) {
case V1_TEMPHUMID_SENSOR_DATA_POINTS.currentTemperature:
this.onTemperatureReport(value);
break;
case V1_TEMPHUMID_SENSOR_DATA_POINTS.batteryLevel:
this.onBatteryReport(value);
break;
default:
this.log(`Unknown datapoint ${dp} report:`, value);
}
} catch (error) {
this.error('Error processing Tuya cluster report:', error);
}
}

onTemperatureReport(measuredValue) {
const parsedValue = measuredValue / 10;
this.log('measure_temperature | temperatureMeasurement - measuredValue (temperature): ', parsedValue, ' + temperature offset ', this.temperatureOffset);
this.setCapabilityValue('measure_temperature', parsedValue + this.temperatureOffset).catch(this.error);
}

onBatteryReport(batteryPercentageRemaining) {
this.log("measure_battery | powerConfiguration - batteryPercentageRemaining (%): ", batteryPercentageRemaining);
this.setCapabilityValue('measure_battery', batteryPercentageRemaining).catch(this.error);
this.setCapabilityValue('alarm_battery', (batteryPercentageRemaining < this.batteryThreshold) ? true : false).catch(this.error);
}

async onSettings({oldSettings, newSettings, changedKeys}) {
// Update cached settings
if (changedKeys.includes('temperature_offset')) {
this.temperatureOffset = newSettings.temperature_offset;
this.log(`Temperature offset changed to ${this.temperatureOffset}`);

// Update temperature capability with new offset
this.onTemperatureReport(this.getCapabilityValue('measure_temperature')*10);
}

if (changedKeys.includes('batteryThreshold')) {
this.batteryThreshold = newSettings.batteryThreshold;
this.log(`Battery threshold changed to ${this.batteryThreshold}`);

// Update battery alarm with new threshold
this.onBatteryReport(this.getCapabilityValue('measure_battery'));
}
}

onDeleted() {
this.log('Temperature sensor THS317-ET-TY removed');
}
}

module.exports = temperaturesensor_ths317;
54 changes: 54 additions & 0 deletions drivers/temperaturesensor_ths317/driver.compose.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
{
"id": "temperaturesensor_ths317",
"name": {
"en": "Temperature Sensor THS317"
},
"class": "sensor",
"platforms": ["local"],
"connectivity": ["zigbee"],
"capabilities": [
"measure_temperature",
"measure_battery",
"alarm_battery"
],
"energy": {
"batteries": [
"AAA",
"AAA"
]
},
"images": {
"small": "{{driverAssetsPath}}/images/small.png",
"large": "{{driverAssetsPath}}/images/large.png",
"xlarge": "{{driverAssetsPath}}/images/xlarge.png"
},
"zigbee": {
"manufacturerName": [
"_TZE200_iq4ygaai"
],
"productId": [
"TS0201"
],
"endpoints": {
"1": {
"clusters": [
0,
1,
61184,
1026
],
"bindings": [
1,
1026,
61184
]
}
},
"learnmode": {
"image": "{{driverAssetsPath}}/learnmode.svg",
"instruction": {
"en": "hold button for 10 seconds to reset the device and enter learn mode"
}
}
}
}
34 changes: 34 additions & 0 deletions drivers/temperaturesensor_ths317/driver.settings.compose.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
[
{
"id": "temperature_offset",
"type": "number",
"label": {
"en": "Temperature offset (°C)"
},
"hint": {
"en": "Set a value to compensate a temperature offset.\nRange: -10 - 10, step size 0.1, \ndefault: 0 [°C]"
},
"value": 0,
"attr": {
"min": -10,
"max": 10,
"step": 0.1
}
},
{
"id": "batteryThreshold",
"type": "number",
"label": {
"en": "Battery Low Alarm Voltage Threshold (percent)"
},
"hint": {
"en": "This setting determines the threshold before a battery alarm is given."
},
"value": 20,
"attr": {
"step": 1,
"min": 10,
"max": 90
}
}
]