-
Notifications
You must be signed in to change notification settings - Fork 55
/
Copy pathAirQualityCO2.js
75 lines (65 loc) · 2.07 KB
/
AirQualityCO2.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/* Module - Simple handler for a CO2 sensor
* AirQualityCO2.js
* Matevz Gacnik, @matevzg
*/
/* jshint esversion: 6, strict: true, node: true */
'use strict';
/**
* @type {HandlerPattern}
*/
var HandlerPattern = require('./handlerpattern.js');
var log = require('debug')('AirQualityCO2');
/**
* @extends HandlerPattern
*/
class AirQualityCO2 extends HandlerPattern {
/*******************************************************************************************************************
* onKNXValueChange is invoked if a bus value for one of the bound addresses is received
*
*/
onKNXValueChange(field, oldValue, knxValue) {
console.log('INFO: onKNXValueChange(' + field + ", "+ oldValue + ", "+ knxValue+ ")");
if (field === "CarbonDioxideLevel") {
// CarbonDioxideLevel is DPT9.001
if (knxValue > this.myAPI.getLocalConstant("PoorAirQuality")) this.myAPI.setValue("AirQuality", 5);
else if (knxValue >= this.myAPI.getLocalConstant("InferiorAirQuality")) this.myAPI.setValue("AirQuality", 4);
else if (knxValue >= this.myAPI.getLocalConstant("FairAirQuality")) this.myAPI.setValue("AirQuality", 3);
else if (knxValue >= this.myAPI.getLocalConstant("GoodAirQuality")) this.myAPI.setValue("AirQuality", 2);
else if (knxValue >= this.myAPI.getLocalConstant("ExcellentAirQuality")) this.myAPI.setValue("AirQuality", 2);
else if (knxValue < this.myAPI.getLocalConstant("ExcellentAirQuality")) this.myAPI.setValue("AirQuality", 1);
// inform HomeKit
this.myAPI.setValue("CarbonDioxideLevel", knxValue);
}
}
}
module.exports = AirQualityCO2;
/* Example configuration
* Add this service to an exitsing device
{
"ServiceType": "AirQualitySensor",
"ServiceName": "CO2 Sensor",
"Handler": "AirQualityCO2",
"Characteristics": [
{
"Type": "AirQuality"
},
{
"Type": "CarbonDioxideLevel",
"Listen": [
"0/2/12"
],
"DPT": "DPT9"
}
],
"KNXReadRequests": [
"0/2/12"
],
"LocalConstants": {
"ExcellentAirQuality": 900,
"GoodAirQuality": 1000,
"FairAirQuality": 1100,
"InferiorAirQuality": 1300,
"PoorAirQuality": 1500
}
}
*/