Skip to content

Commit

Permalink
Fix MotionSensor
Browse files Browse the repository at this point in the history
  • Loading branch information
seydx committed Nov 26, 2020
1 parent 74d3481 commit c2fb112
Showing 1 changed file with 40 additions and 41 deletions.
81 changes: 40 additions & 41 deletions src/accessories/outlet.js
Original file line number Diff line number Diff line change
Expand Up @@ -193,52 +193,51 @@ class OutletAccessory {
.getService(this.api.hap.Service.Outlet)
.getCharacteristic(this.api.hap.Characteristic.Amperes)
.updateValue(message.ENERGY.Current);

if(this.Telegram){

if(message.ENERGY.Power >= this.accessory.context.config.startValue && !this.accessory.context.started){

this.accessory.context.started = true;

if(message.ENERGY.Power >= this.accessory.context.config.startValue && !this.accessory.context.started){

this.accessory.context.started = true;

if(this.Telegram)
this.Telegram.send('started', this.accessory.displayName);

const motionAccessory = this.accessories.find(accessory => accessory.displayName === this.accessory.displayName + ' Motion');

if(motionAccessory) {

motionAccessory
.getService(this.api.hap.Service.MotionSensor)
.getCharacteristic(this.api.hap.Characteristic.MotionDetected)
.updateValue(1);

} else {

Logger.info('Started', this.accessory.displayName);

const motionAccessory = this.accessories.find(accessory => accessory.displayName === this.accessory.displayName + ' Motion');

if(motionAccessory) {

motionAccessory
.getService(this.api.hap.Service.MotionSensor)
.getCharacteristic(this.api.hap.Characteristic.MotionDetected)
.updateValue(1);

} else {

Logger.info('Started', this.accessory.displayName);

}

} else if(message.ENERGY.Power < this.accessory.context.config.startValue && this.accessory.context.started){

this.accessory.context.started = false;

}

} else if(message.ENERGY.Power < this.accessory.context.config.startValue && this.accessory.context.started){

this.accessory.context.started = false;

if(this.Telegram)
this.Telegram.send('finished', this.accessory.displayName);

const motionAccessory = this.accessories.find(accessory => accessory.displayName === this.accessory.displayName + ' Motion');

if(motionAccessory) {

motionAccessory
.getService(this.api.hap.Service.MotionSensor)
.getCharacteristic(this.api.hap.Characteristic.MotionDetected)
.updateValue(0);

} else {

Logger.info('Finished', this.accessory.displayName);

}


const motionAccessory = this.accessories.find(accessory => accessory.displayName === this.accessory.displayName + ' Motion');

if(motionAccessory) {

motionAccessory
.getService(this.api.hap.Service.MotionSensor)
.getCharacteristic(this.api.hap.Characteristic.MotionDetected)
.updateValue(0);

} else {

Logger.info('Finished', this.accessory.displayName);

}

}

break;
Expand Down

0 comments on commit c2fb112

Please sign in to comment.