thing-it-device-enocean-ip
Advanced tools
Comparing version 0.1.17 to 0.1.18
@@ -8,2 +8,14 @@ module.exports = { | ||
deviceTypes: ["enocean-ip/gateway"], | ||
dataTypes:{ | ||
sensorType:{ | ||
family: "enumeration", | ||
values: [{ | ||
id: "SOLARSENSOR", | ||
label: "Solar Sensor" | ||
}, { | ||
id: "BATTERYSENSOR", | ||
label: "Battery Sensor" | ||
}] | ||
} | ||
}, | ||
services: [], | ||
@@ -69,8 +81,9 @@ events: [{ | ||
}, { | ||
label: "Enable Ghoste Ticks", | ||
id: "enableGhosteTicks", | ||
label: "Sensor Type", | ||
id: "sensorType", | ||
type: { | ||
id: "boolean" | ||
family: "reference", | ||
id: "sensorType" | ||
}, | ||
defaultValue: true | ||
defaultValue: "SOLARSENSOR" | ||
}] | ||
@@ -102,2 +115,3 @@ }, | ||
this.ticksTimestampsArray = []; | ||
this.ticCountArray = []; | ||
@@ -134,28 +148,27 @@ if (!this.configuration.ghostTickInterval) { | ||
//console.log('Device ' + telegram.friendlyId + ' is processing ', telegram.functions); | ||
if (this.configuration.sensorType === "BATTERYSENSOR"){ | ||
for (var n in telegram.functions) { | ||
if (telegram.functions[n].key === 'motionDetected') { | ||
for (var n in telegram.functions) { | ||
if (telegram.functions[n].key === 'motionDetected') { | ||
if (telegram.functions[n].value === 'true') { | ||
this.publishEvent('tic', {}); | ||
if (telegram.functions[n].value === 'true') { | ||
this.publishEvent('tic', {}); | ||
this.state.lastMotionTimestamp = moment().toISOString(); | ||
this.state.lastMotionTimestamp = moment().toISOString(); | ||
this.ticksTimestampsArray.unshift(Date.now()); | ||
this.updateTicksOverTime(); | ||
this.publishStateChange(); | ||
this.ticksTimestampsArray.unshift(Date.now()); | ||
this.updateTicksOverTime(); | ||
this.publishStateChange(); | ||
if (this.occupancyTimeout) { | ||
clearTimeout(this.occupancyTimeout); | ||
} | ||
if (this.occupancyTimeout) { | ||
clearTimeout(this.occupancyTimeout); | ||
} | ||
if (!this.state.occupied) { | ||
this.state.occupied = true; | ||
this.publishEvent('motionDetected', {}); | ||
this.publishStateChange(); | ||
} | ||
if (!this.state.occupied) { | ||
this.state.occupied = true; | ||
this.publishEvent('motionDetected',{}); | ||
this.publishStateChange(); | ||
} | ||
// Simulates repeated ticks | ||
// Simulates repeated ticks | ||
if (this.configuration.enableGhosteTicks) { | ||
if (this.configuration.ghostTickInterval) { | ||
@@ -165,3 +178,2 @@ this.tickRepeatInterval = setInterval(() => { | ||
this.publishEvent('tic', {}); | ||
this.state.lastMotionTimestamp = moment().toISOString(); | ||
@@ -175,18 +187,65 @@ | ||
} | ||
} | ||
this.occupancyTimeout = setTimeout(() => { | ||
this.state.occupied = false; | ||
this.publishEvent('noMoreMotion', {}); | ||
this.publishStateChange(); | ||
}, this.configuration.releaseTime * 1000); | ||
this.occupancyTimeout = setTimeout(() => { | ||
this.state.occupied = false; | ||
this.publishEvent('noMoreMotion', {}); | ||
this.publishStateChange(); | ||
}, this.configuration.releaseTime * 1000); | ||
} else { | ||
if (this.tickRepeatInterval) { | ||
clearInterval(this.tickRepeatInterval); | ||
} else { | ||
if (this.tickRepeatInterval) { | ||
clearInterval(this.tickRepeatInterval); | ||
} | ||
} | ||
break; | ||
} | ||
} | ||
break; | ||
} | ||
else{ | ||
let ticCounter; | ||
let tic; | ||
let duration; | ||
let dataArray = []; | ||
dataArray = telegram.telegramInfo.data.match(/.{1,2}/g); | ||
if(dataArray[3] === "0D"){ | ||
this.publishEvent('tic',{}); | ||
this.state.lastMotionTimestamp = moment().toISOString(); | ||
this.ticksTimestampsArray.unshift(Date.now()); | ||
if (this.occupancyTimeout) { | ||
clearTimeout(this.occupancyTimeout); | ||
} | ||
if (!this.state.occupied) { | ||
this.state.occupied = true; | ||
this.publishEvent('motionDetected', {}); | ||
this.publishStateChange(); | ||
} | ||
} | ||
else{ | ||
if (this.tickRepeatInterval) { | ||
clearInterval(this.tickRepeatInterval); | ||
} | ||
} | ||
ticCounter = dataArray[1]+dataArray[2]; | ||
this.ticCountArray.unshift(parseInt(ticCounter,16)); | ||
if(this.ticCountArray[0] < this.ticCountArray[1]) tic = this.ticCountArray[0]+(65535-this.ticCountArray[1]); | ||
else tic = this.ticCountArray[0]-this.ticCountArray[1]; | ||
duration = (this.ticksTimestampsArray[0]-this.ticksTimestampsArray[1])/60000; | ||
this.state.ticksPerMinute = Math.round(tic/duration); | ||
this.publishStateChange(); | ||
this.occupancyTimeout = setTimeout(() => { | ||
this.state.occupied = false; | ||
this.publishEvent('noMoreMotion', {}); | ||
this.publishStateChange(); | ||
}, this.configuration.releaseTime * 1000); | ||
} | ||
@@ -193,0 +252,0 @@ } |
@@ -50,4 +50,4 @@ module.exports = { | ||
this.state = {ambientTemperature: 20, | ||
surfaceTemperature: 20}; | ||
this.state = {ambientTemperature: 0, | ||
surfaceTemperature: 0}; | ||
@@ -54,0 +54,0 @@ if (this.isSimulated()) { |
@@ -66,5 +66,5 @@ module.exports = { | ||
this.state = {currentChannel1: 1.0, | ||
currentChannel2: 1.0, | ||
currentChannel3: 1.0, | ||
this.state = {currentChannel1: 0.0, | ||
currentChannel2: 0.0, | ||
currentChannel3: 0.0, | ||
powerFailure: false}; | ||
@@ -71,0 +71,0 @@ |
@@ -73,5 +73,5 @@ module.exports = { | ||
this.state = { | ||
temperature1: 20.0, | ||
temperature2: 22.5, | ||
temperature3: 25.0, | ||
temperature1: 0.0, | ||
temperature2: 0.0, | ||
temperature3: 0.0, | ||
batteryFailing: false | ||
@@ -78,0 +78,0 @@ }; |
{ | ||
"name": "thing-it-device-enocean-ip", | ||
"version": "0.1.17", | ||
"version": "0.1.18", | ||
"description": "[thing-it-node] Device Plugin for EnOcean IP products.", | ||
@@ -5,0 +5,0 @@ "authors": "Marc Gille", |
85457
1801