Created
October 13, 2018 12:21
-
-
Save vddgil/352d3808a76ed19348612a07e2c3f165 to your computer and use it in GitHub Desktop.
CustomWindowCovering.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
// Position state: | |
// Characteristic.PositionState.DECREASING = 0; | |
// Characteristic.PositionState.INCREASING = 1; | |
// Characteristic.PositionState.STOPPED = 2; | |
var HandlerPattern = require('/usr/local/lib/node_modules/homebridge-knx/lib/addins/handlerpattern.js'); | |
var log = require('/usr/local/lib/node_modules/homebridge/node_modules/debug')('CustomWindowCovering'); | |
class CustomWindowCovering extends HandlerPattern { | |
onKNXValueChange(field, oldValue, newValue) { | |
log('INFO: onKNXValueChange(' + field + ", "+ oldValue + ", "+ newValue+ ")"); | |
if(field === "CurrentPosition") { | |
var oldDecimalValue = 100 - (oldValue * 100 / 255); | |
var newDecimalValue = 100 - (newValue * 100 / 255); | |
this.myAPI.setValue("PositionState", 2) | |
this.myAPI.setValue("CurrentPosition", parseInt(newDecimalValue)) | |
} | |
if(field === "TotallyOpened" && newValue === 1){ | |
this.myAPI.setValue("PositionState", 2) | |
this.myAPI.setValue("CurrentPosition", 100) | |
} | |
if(field === "TotallyClosed" && newValue === 1){ | |
this.myAPI.setValue("PositionState", 2) | |
this.myAPI.setValue("CurrentPosition", 0) | |
} | |
} | |
onHKValueChange(field, oldValue, newValue) { | |
log('INFO: onHKValueChange(' + field + ", "+ oldValue + ", "+ newValue+ ")"); | |
if(field === "TargetPosition") { | |
this.myAPI.knxWrite("TargetPosition", newValue, "DPT5.001") | |
} | |
} | |
} | |
module.exports= CustomWindowCovering; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment