From 26d9dfd313536db84a22d7b6503c2f8962c80314 Mon Sep 17 00:00:00 2001
From: Thomas Kluge
Date: Mon, 5 Oct 2020 19:26:08 +0200
Subject: [PATCH] added onTime to deal with #193
---
lib/configurationsrv/html/assets/de.json | 5 +++-
lib/services/HomeMaticDimmerAccessory.js | 25 ++++++++++++++++-
.../HomeMaticIPPowerMeterSwitchAccessory.js | 2 ++
.../HomeMaticPowerMeterSwitchAccessory.js | 27 ++++++++++++++-----
lib/services/HomeMaticSwitchAccessory.js | 24 ++++++++++++-----
5 files changed, 67 insertions(+), 16 deletions(-)
diff --git a/lib/configurationsrv/html/assets/de.json b/lib/configurationsrv/html/assets/de.json
index 52e4d52..563e50b 100644
--- a/lib/configurationsrv/html/assets/de.json
+++ b/lib/configurationsrv/html/assets/de.json
@@ -370,7 +370,10 @@
"Show measured values as graph on the frontpage":"Zeigt einen Graph des Messwertes auf der Startseite an",
"Unlock mode":"Unlock Modus",
"What to do when HomeKit will unlock the door":"Was soll getan werden, wenn Homekit die Tür aufschliesst",
- "This service provides a filling sensor":"Dieser Service stellt einen Füllstandssensor bereit."
+ "This service provides a filling sensor":"Dieser Service stellt einen Füllstandssensor bereit.",
+ "On Time":"Einschaltzeit",
+ "HAP will switch off this device automatically after the given seconds. Set this to 0 to turn off this feature.":
+ "HAP wird das Gerät automatisch nach der angegebenen Anzahl der Sekunden ausschalten. Stelle den Wert auf 0 um die Funktion zu deaktivieren."
}
diff --git a/lib/services/HomeMaticDimmerAccessory.js b/lib/services/HomeMaticDimmerAccessory.js
index 7305c4c..cec4edd 100644
--- a/lib/services/HomeMaticDimmerAccessory.js
+++ b/lib/services/HomeMaticDimmerAccessory.js
@@ -40,6 +40,9 @@ class HomeMaticDimmerAccessory extends HomeMaticAccessory {
let settings = this.getDeviceSettings()
this.useRampTime = settings.useRampTime || false
this.rampTime = settings.rampTime || 500
+ this.onTime = this.getDeviceSettings().OnTime
+
+ self.debugLog('Init light RampTime %s onTime %s', this.rampTime, this.onTime)
this.lightBulbService = this.getService(Service.Lightbulb)
@@ -55,9 +58,15 @@ class HomeMaticDimmerAccessory extends HomeMaticAccessory {
.on('set', (value, callback) => {
self.debugLog('set ON %s', value)
self.isWorking = true
-
+ self.lightWasTurnedOn = value
clearTimeout(self.timer)
self.timer = setTimeout(async () => {
+ self.debugLog('OnTime is %s LWTO is %s', self.onTime, self.lightWasTurnedOn)
+ if ((self.lightWasTurnedOn === true) && (self.onTime !== undefined) && (parseInt(self.onTime) > 0)) {
+ self.debugLog('set OnTime to %s', self.onTime)
+ await self.setValue('ON_TIME', self.onTime)
+ }
+
if (self.useRampTime === true) {
await self.setValueForDataPointNameWithSettingsKey('ramp', null, parseFloat(self.rampTime) / 1000)
}
@@ -71,6 +80,7 @@ class HomeMaticDimmerAccessory extends HomeMaticAccessory {
self.setValueForDataPointNameWithSettingsKey('level', null, self.oldLevel)
}
}, self.delayOnSet)
+ self.debugLog('LWTO is %s', self.lightWasTurnedOn)
if (callback) {
callback()
}
@@ -93,6 +103,13 @@ class HomeMaticDimmerAccessory extends HomeMaticAccessory {
clearTimeout(self.timer)
self.timer = setTimeout(async () => {
self.debugLog('set bn %s', hkvalue)
+ // do this just once
+ self.debugLog('OnTime is %s LWTO is %s', self.onTime, self.lightWasTurnedOn)
+ if ((self.lightWasTurnedOn === true) && (self.onTime !== undefined) && (parseInt(self.onTime) > 0)) {
+ self.debugLog('set OnTime to %s', self.onTime)
+ await self.setValue('ON_TIME', self.onTime)
+ }
+ self.lightWasTurnedOn = false
self.isWorking = true
if (self.useRampTime === true) {
await self.setValueForDataPointNameWithSettingsKey('ramp', null, parseFloat(self.rampTime) / 1000)
@@ -165,6 +182,12 @@ class HomeMaticDimmerAccessory extends HomeMaticAccessory {
default: 500,
label: 'Ramp time in ms',
hint: 'uses a dimmer ramp time to slowly set the new level'
+ },
+ 'OnTime': {
+ type: 'number',
+ default: 0,
+ label: 'On Time',
+ hint: 'HAP will switch off this device automatically after the given seconds. Set this to 0 to turn off this feature.'
}
}
}
diff --git a/lib/services/HomeMaticIPPowerMeterSwitchAccessory.js b/lib/services/HomeMaticIPPowerMeterSwitchAccessory.js
index 3788b31..520bc4b 100644
--- a/lib/services/HomeMaticIPPowerMeterSwitchAccessory.js
+++ b/lib/services/HomeMaticIPPowerMeterSwitchAccessory.js
@@ -37,6 +37,7 @@ class HomeMaticIPPowerMeterSwitchAccessory extends HomeMaticPowerMeterSwitchAcce
'HmIP-BSM': {
roChannel: 4,
switch: '4.STATE',
+ ontime: '4.ON_TIME',
power: 'POWER',
current: 'CURRENT',
voltage: 'VOLTAGE',
@@ -46,6 +47,7 @@ class HomeMaticIPPowerMeterSwitchAccessory extends HomeMaticPowerMeterSwitchAcce
'*': {
roChannel: 3,
switch: '3.STATE',
+ ontime: '3.ON_TIME',
power: 'POWER',
current: 'CURRENT',
voltage: 'VOLTAGE',
diff --git a/lib/services/HomeMaticPowerMeterSwitchAccessory.js b/lib/services/HomeMaticPowerMeterSwitchAccessory.js
index ab005ad..9689d02 100644
--- a/lib/services/HomeMaticPowerMeterSwitchAccessory.js
+++ b/lib/services/HomeMaticPowerMeterSwitchAccessory.js
@@ -33,7 +33,7 @@ const HomeMaticPowerMeterAccessory = require(path.join(__dirname, 'HomeMaticPowe
class HomeMaticPowerMeterSwitchAccessory extends HomeMaticPowerMeterAccessory {
initAccessoryService (Service) {
- this.log.debug('[PMSWITCH] initAccessoryService')
+ this.debugLog('initAccessoryService')
this.service = this.getService(new Service.Outlet(this._name))
this.service.addOptionalCharacteristic(this.eve.Characteristic.TotalConsumption)
this.service.addOptionalCharacteristic(this.eve.Characteristic.ElectricCurrent)
@@ -48,22 +48,28 @@ class HomeMaticPowerMeterSwitchAccessory extends HomeMaticPowerMeterAccessory {
super.publishServices(Service, Characteristic)
let self = this
let readOnly = this.isReadOnly()
+ let onTime = this.getDeviceSettings().OnTime
if (this.getDataPointNameFromSettings('switch', null)) {
- this.log.debug('[PMSWITCH] adding isOn isOnCharacteristic')
+ this.debugLog('adding isOn isOnCharacteristic')
this.isOnCharacteristic = this.service.getCharacteristic(Characteristic.On)
this.isOnCharacteristic.on('get', async (callback) => {
- self.log.debug('[PMSWITCH] get state fetch CCU State')
+ self.debugLog('get state fetch CCU State')
let state = await self.getValueForDataPointNameWithSettingsKey('switch', null, true)
- self.log.debug('[PMSWITCH] get state %s', state)
+ self.debugLog('get state %s', state)
self.currentStatus = self.isTrue(state)
callback(null, self.currentStatus)
})
- this.isOnCharacteristic.on('set', (value, callback) => {
- self.log.debug('[PMSWITCH] set %s', value)
+ this.isOnCharacteristic.on('set', async (value, callback) => {
+ self.debugLog('set %s', value)
if (!readOnly) {
+ if ((self.isTrue(value)) && (onTime) && (parseInt(onTime) > 0)) {
+ self.debugLog('set onTime %s seconds', onTime)
+ await self.setValueForDataPointNameWithSettingsKey('ontime', null, onTime)
+ }
+
self.setValueForDataPointNameWithSettingsKey('switch', null, value)
} else {
// check the state 1 sec later to reset the homekit state
@@ -81,7 +87,7 @@ class HomeMaticPowerMeterSwitchAccessory extends HomeMaticPowerMeterAccessory {
// }
this.registerAddressWithSettingsKeyForEventProcessingAtAccessory('switch', null, (newValue) => {
- self.log.debug('[PMSWITCH] event state %s', newValue)
+ self.debugLog('event state %s', newValue)
self.currentStatus = self.isTrue(newValue)
if (self.isTrue(newValue)) {
self.updateLastActivation()
@@ -115,6 +121,7 @@ class HomeMaticPowerMeterSwitchAccessory extends HomeMaticPowerMeterAccessory {
'*': {
roChannel: 1,
switch: '1.STATE',
+ ontime: '1.ON_TIME',
power: 'POWER',
current: 'CURRENT',
voltage: 'VOLTAGE',
@@ -132,6 +139,12 @@ class HomeMaticPowerMeterSwitchAccessory extends HomeMaticPowerMeterAccessory {
default: 'Power',
label: 'Logging for',
hint: 'Eve is only able to log on option.'
+ },
+ 'OnTime': {
+ type: 'number',
+ default: 0,
+ label: 'On Time',
+ hint: 'HAP will switch off this device automatically after the given seconds. Set this to 0 to turn off this feature.'
}
}
}
diff --git a/lib/services/HomeMaticSwitchAccessory.js b/lib/services/HomeMaticSwitchAccessory.js
index bf31dfe..fc1856b 100644
--- a/lib/services/HomeMaticSwitchAccessory.js
+++ b/lib/services/HomeMaticSwitchAccessory.js
@@ -36,7 +36,7 @@ class HomeMaticSwitchAccessory extends HomeMaticAccessory {
let self = this
var service
let subType = this.getDeviceSettings().Type || 'Lightbulb'
-
+ let onTime = this.getDeviceSettings().OnTime
let readOnly = this.isReadOnly()
switch (subType) {
@@ -54,7 +54,7 @@ class HomeMaticSwitchAccessory extends HomeMaticAccessory {
break
}
- this.log.debug('[SWITCH] creating Service %s', subType)
+ this.debugLog('[SWITCH] creating Service %s', subType)
this.isOnCharacteristic = service.getCharacteristic(Characteristic.On)
this.isOnCharacteristic.on('get', (callback) => {
@@ -63,10 +63,14 @@ class HomeMaticSwitchAccessory extends HomeMaticAccessory {
})
})
- this.isOnCharacteristic.on('set', (value, callback) => {
+ this.isOnCharacteristic.on('set', async (value, callback) => {
if (!readOnly) {
- self.log.debug('[Switch] set switch %s', value)
-
+ self.debugLog('[Switch] set switch %s', value)
+ if ((value === true) && (onTime) && (parseInt(onTime) > 0)) {
+ self.debugLog('set onTime %s seconds', onTime)
+ await self.setValue('ON_TIME', onTime)
+ }
+ self.debugLog('set value %s', value)
if (value === false) {
self.setValue('STATE', 0)
} else {
@@ -74,7 +78,7 @@ class HomeMaticSwitchAccessory extends HomeMaticAccessory {
}
} else {
// check the state to reset the HomeKit State
- self.log.debug('[Switch] is readOnly .. skipping')
+ self.debugLog('[Switch] is readOnly .. skipping')
setTimeout(() => {
self.getValue('STATE', true)
}, 1000)
@@ -83,7 +87,7 @@ class HomeMaticSwitchAccessory extends HomeMaticAccessory {
})
this.registerAddressForEventProcessingAtAccessory(this.buildAddress('STATE'), (newValue) => {
- self.log.debug('[SWITCH] event state %s', newValue)
+ self.debugLog('[SWITCH] event state %s', newValue)
// Add a Log Entry for Eve
self.addLogEntry({status: self.isTrue(newValue) ? 1 : 0})
// Set Last Activation if the switch is on
@@ -119,6 +123,12 @@ class HomeMaticSwitchAccessory extends HomeMaticAccessory {
default: 'Lightbulb',
label: 'Subtype of this device',
hint: 'A switch can have different sub types'
+ },
+ 'OnTime': {
+ type: 'number',
+ default: 0,
+ label: 'On Time',
+ hint: 'HAP will switch off this device automatically after the given seconds. Set this to 0 to turn off this feature.'
}
}
}