Skip to content

Instantly share code, notes, and snippets.

@vddgil
Created October 13, 2018 12:21
Show Gist options
  • Save vddgil/352d3808a76ed19348612a07e2c3f165 to your computer and use it in GitHub Desktop.
Save vddgil/352d3808a76ed19348612a07e2c3f165 to your computer and use it in GitHub Desktop.
CustomWindowCovering.js
'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