Skip to content

Commit 26d9dfd

Browse files
committed
added onTime to deal with #193
1 parent a0542e1 commit 26d9dfd

File tree

5 files changed

+67
-16
lines changed

5 files changed

+67
-16
lines changed

lib/configurationsrv/html/assets/de.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,10 @@
370370
"Show measured values as graph on the frontpage":"Zeigt einen Graph des Messwertes auf der Startseite an",
371371
"Unlock mode":"Unlock Modus",
372372
"What to do when HomeKit will unlock the door":"Was soll getan werden, wenn Homekit die Tür aufschliesst",
373-
"This service provides a filling sensor":"Dieser Service stellt einen Füllstandssensor bereit."
373+
"This service provides a filling sensor":"Dieser Service stellt einen Füllstandssensor bereit.",
374+
"On Time":"Einschaltzeit",
375+
"HAP will switch off this device automatically after the given seconds. Set this to 0 to turn off this feature.":
376+
"HAP wird das Gerät automatisch nach der angegebenen Anzahl der Sekunden ausschalten. Stelle den Wert auf 0 um die Funktion zu deaktivieren."
374377
}
375378

376379

lib/services/HomeMaticDimmerAccessory.js

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ class HomeMaticDimmerAccessory extends HomeMaticAccessory {
4040
let settings = this.getDeviceSettings()
4141
this.useRampTime = settings.useRampTime || false
4242
this.rampTime = settings.rampTime || 500
43+
this.onTime = this.getDeviceSettings().OnTime
44+
45+
self.debugLog('Init light RampTime %s onTime %s', this.rampTime, this.onTime)
4346

4447
this.lightBulbService = this.getService(Service.Lightbulb)
4548

@@ -55,9 +58,15 @@ class HomeMaticDimmerAccessory extends HomeMaticAccessory {
5558
.on('set', (value, callback) => {
5659
self.debugLog('set ON %s', value)
5760
self.isWorking = true
58-
61+
self.lightWasTurnedOn = value
5962
clearTimeout(self.timer)
6063
self.timer = setTimeout(async () => {
64+
self.debugLog('OnTime is %s LWTO is %s', self.onTime, self.lightWasTurnedOn)
65+
if ((self.lightWasTurnedOn === true) && (self.onTime !== undefined) && (parseInt(self.onTime) > 0)) {
66+
self.debugLog('set OnTime to %s', self.onTime)
67+
await self.setValue('ON_TIME', self.onTime)
68+
}
69+
6170
if (self.useRampTime === true) {
6271
await self.setValueForDataPointNameWithSettingsKey('ramp', null, parseFloat(self.rampTime) / 1000)
6372
}
@@ -71,6 +80,7 @@ class HomeMaticDimmerAccessory extends HomeMaticAccessory {
7180
self.setValueForDataPointNameWithSettingsKey('level', null, self.oldLevel)
7281
}
7382
}, self.delayOnSet)
83+
self.debugLog('LWTO is %s', self.lightWasTurnedOn)
7484
if (callback) {
7585
callback()
7686
}
@@ -93,6 +103,13 @@ class HomeMaticDimmerAccessory extends HomeMaticAccessory {
93103
clearTimeout(self.timer)
94104
self.timer = setTimeout(async () => {
95105
self.debugLog('set bn %s', hkvalue)
106+
// do this just once
107+
self.debugLog('OnTime is %s LWTO is %s', self.onTime, self.lightWasTurnedOn)
108+
if ((self.lightWasTurnedOn === true) && (self.onTime !== undefined) && (parseInt(self.onTime) > 0)) {
109+
self.debugLog('set OnTime to %s', self.onTime)
110+
await self.setValue('ON_TIME', self.onTime)
111+
}
112+
self.lightWasTurnedOn = false
96113
self.isWorking = true
97114
if (self.useRampTime === true) {
98115
await self.setValueForDataPointNameWithSettingsKey('ramp', null, parseFloat(self.rampTime) / 1000)
@@ -165,6 +182,12 @@ class HomeMaticDimmerAccessory extends HomeMaticAccessory {
165182
default: 500,
166183
label: 'Ramp time in ms',
167184
hint: 'uses a dimmer ramp time to slowly set the new level'
185+
},
186+
'OnTime': {
187+
type: 'number',
188+
default: 0,
189+
label: 'On Time',
190+
hint: 'HAP will switch off this device automatically after the given seconds. Set this to 0 to turn off this feature.'
168191
}
169192
}
170193
}

lib/services/HomeMaticIPPowerMeterSwitchAccessory.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ class HomeMaticIPPowerMeterSwitchAccessory extends HomeMaticPowerMeterSwitchAcce
3737
'HmIP-BSM': {
3838
roChannel: 4,
3939
switch: '4.STATE',
40+
ontime: '4.ON_TIME',
4041
power: 'POWER',
4142
current: 'CURRENT',
4243
voltage: 'VOLTAGE',
@@ -46,6 +47,7 @@ class HomeMaticIPPowerMeterSwitchAccessory extends HomeMaticPowerMeterSwitchAcce
4647
'*': {
4748
roChannel: 3,
4849
switch: '3.STATE',
50+
ontime: '3.ON_TIME',
4951
power: 'POWER',
5052
current: 'CURRENT',
5153
voltage: 'VOLTAGE',

lib/services/HomeMaticPowerMeterSwitchAccessory.js

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ const HomeMaticPowerMeterAccessory = require(path.join(__dirname, 'HomeMaticPowe
3333

3434
class HomeMaticPowerMeterSwitchAccessory extends HomeMaticPowerMeterAccessory {
3535
initAccessoryService (Service) {
36-
this.log.debug('[PMSWITCH] initAccessoryService')
36+
this.debugLog('initAccessoryService')
3737
this.service = this.getService(new Service.Outlet(this._name))
3838
this.service.addOptionalCharacteristic(this.eve.Characteristic.TotalConsumption)
3939
this.service.addOptionalCharacteristic(this.eve.Characteristic.ElectricCurrent)
@@ -48,22 +48,28 @@ class HomeMaticPowerMeterSwitchAccessory extends HomeMaticPowerMeterAccessory {
4848
super.publishServices(Service, Characteristic)
4949
let self = this
5050
let readOnly = this.isReadOnly()
51+
let onTime = this.getDeviceSettings().OnTime
5152

5253
if (this.getDataPointNameFromSettings('switch', null)) {
53-
this.log.debug('[PMSWITCH] adding isOn isOnCharacteristic')
54+
this.debugLog('adding isOn isOnCharacteristic')
5455
this.isOnCharacteristic = this.service.getCharacteristic(Characteristic.On)
5556
this.isOnCharacteristic.on('get', async (callback) => {
56-
self.log.debug('[PMSWITCH] get state fetch CCU State')
57+
self.debugLog('get state fetch CCU State')
5758

5859
let state = await self.getValueForDataPointNameWithSettingsKey('switch', null, true)
59-
self.log.debug('[PMSWITCH] get state %s', state)
60+
self.debugLog('get state %s', state)
6061
self.currentStatus = self.isTrue(state)
6162
callback(null, self.currentStatus)
6263
})
6364

64-
this.isOnCharacteristic.on('set', (value, callback) => {
65-
self.log.debug('[PMSWITCH] set %s', value)
65+
this.isOnCharacteristic.on('set', async (value, callback) => {
66+
self.debugLog('set %s', value)
6667
if (!readOnly) {
68+
if ((self.isTrue(value)) && (onTime) && (parseInt(onTime) > 0)) {
69+
self.debugLog('set onTime %s seconds', onTime)
70+
await self.setValueForDataPointNameWithSettingsKey('ontime', null, onTime)
71+
}
72+
6773
self.setValueForDataPointNameWithSettingsKey('switch', null, value)
6874
} else {
6975
// check the state 1 sec later to reset the homekit state
@@ -81,7 +87,7 @@ class HomeMaticPowerMeterSwitchAccessory extends HomeMaticPowerMeterAccessory {
8187
// }
8288

8389
this.registerAddressWithSettingsKeyForEventProcessingAtAccessory('switch', null, (newValue) => {
84-
self.log.debug('[PMSWITCH] event state %s', newValue)
90+
self.debugLog('event state %s', newValue)
8591
self.currentStatus = self.isTrue(newValue)
8692
if (self.isTrue(newValue)) {
8793
self.updateLastActivation()
@@ -115,6 +121,7 @@ class HomeMaticPowerMeterSwitchAccessory extends HomeMaticPowerMeterAccessory {
115121
'*': {
116122
roChannel: 1,
117123
switch: '1.STATE',
124+
ontime: '1.ON_TIME',
118125
power: 'POWER',
119126
current: 'CURRENT',
120127
voltage: 'VOLTAGE',
@@ -132,6 +139,12 @@ class HomeMaticPowerMeterSwitchAccessory extends HomeMaticPowerMeterAccessory {
132139
default: 'Power',
133140
label: 'Logging for',
134141
hint: 'Eve is only able to log on option.'
142+
},
143+
'OnTime': {
144+
type: 'number',
145+
default: 0,
146+
label: 'On Time',
147+
hint: 'HAP will switch off this device automatically after the given seconds. Set this to 0 to turn off this feature.'
135148
}
136149
}
137150
}

lib/services/HomeMaticSwitchAccessory.js

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class HomeMaticSwitchAccessory extends HomeMaticAccessory {
3636
let self = this
3737
var service
3838
let subType = this.getDeviceSettings().Type || 'Lightbulb'
39-
39+
let onTime = this.getDeviceSettings().OnTime
4040
let readOnly = this.isReadOnly()
4141

4242
switch (subType) {
@@ -54,7 +54,7 @@ class HomeMaticSwitchAccessory extends HomeMaticAccessory {
5454
break
5555
}
5656

57-
this.log.debug('[SWITCH] creating Service %s', subType)
57+
this.debugLog('[SWITCH] creating Service %s', subType)
5858
this.isOnCharacteristic = service.getCharacteristic(Characteristic.On)
5959

6060
this.isOnCharacteristic.on('get', (callback) => {
@@ -63,18 +63,22 @@ class HomeMaticSwitchAccessory extends HomeMaticAccessory {
6363
})
6464
})
6565

66-
this.isOnCharacteristic.on('set', (value, callback) => {
66+
this.isOnCharacteristic.on('set', async (value, callback) => {
6767
if (!readOnly) {
68-
self.log.debug('[Switch] set switch %s', value)
69-
68+
self.debugLog('[Switch] set switch %s', value)
69+
if ((value === true) && (onTime) && (parseInt(onTime) > 0)) {
70+
self.debugLog('set onTime %s seconds', onTime)
71+
await self.setValue('ON_TIME', onTime)
72+
}
73+
self.debugLog('set value %s', value)
7074
if (value === false) {
7175
self.setValue('STATE', 0)
7276
} else {
7377
self.setValue('STATE', 1)
7478
}
7579
} else {
7680
// check the state to reset the HomeKit State
77-
self.log.debug('[Switch] is readOnly .. skipping')
81+
self.debugLog('[Switch] is readOnly .. skipping')
7882
setTimeout(() => {
7983
self.getValue('STATE', true)
8084
}, 1000)
@@ -83,7 +87,7 @@ class HomeMaticSwitchAccessory extends HomeMaticAccessory {
8387
})
8488

8589
this.registerAddressForEventProcessingAtAccessory(this.buildAddress('STATE'), (newValue) => {
86-
self.log.debug('[SWITCH] event state %s', newValue)
90+
self.debugLog('[SWITCH] event state %s', newValue)
8791
// Add a Log Entry for Eve
8892
self.addLogEntry({status: self.isTrue(newValue) ? 1 : 0})
8993
// Set Last Activation if the switch is on
@@ -119,6 +123,12 @@ class HomeMaticSwitchAccessory extends HomeMaticAccessory {
119123
default: 'Lightbulb',
120124
label: 'Subtype of this device',
121125
hint: 'A switch can have different sub types'
126+
},
127+
'OnTime': {
128+
type: 'number',
129+
default: 0,
130+
label: 'On Time',
131+
hint: 'HAP will switch off this device automatically after the given seconds. Set this to 0 to turn off this feature.'
122132
}
123133
}
124134
}

0 commit comments

Comments
 (0)