Skip to content

Commit

Permalink
Merge branch 'develop' of https://github.com/smarthomeNG/plugins into…
Browse files Browse the repository at this point in the history
… develop
  • Loading branch information
aschwith committed Nov 21, 2024
2 parents d820b95 + 42ef62b commit 3eea4c9
Show file tree
Hide file tree
Showing 21 changed files with 2,247 additions and 111 deletions.
29 changes: 17 additions & 12 deletions database/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ def __init__(self, sh, *args, **kwargs):
if self._removeold_cycle == self._dump_cycle:
self._removeold_cycle += 2
self._precision = self.get_parameter_value('precision')
self._time_precision = self.get_parameter_value('time_precision')
self.count_logentries = self.get_parameter_value('count_logentries')
self.max_delete_logentries = self.get_parameter_value('max_delete_logentries')
self.max_reassign_logentries = self.get_parameter_value('max_reassign_logentries')
Expand Down Expand Up @@ -1115,21 +1116,21 @@ def _series(self, func, start, end='now', count=100, ratio=1, update=False, step
sid = item + '|' + func + '|' + str(start) + '|' + str(end) + '|' + str(count)
func, expression = self._expression(func)
queries = {
'avg': 'MIN(time), ' + self._precision_query('AVG(val_num * duration) / AVG(duration)'),
'avg': self._time_precision_query('MIN(time)') + ', ' + self._precision_query('AVG(val_num * duration) / AVG(duration)'),
'avg.order': 'ORDER BY time ASC',
'integrate': 'MIN(time), SUM(val_num * duration)',
'diff': 'MIN(time), (val_num - LAG(val_num,1) OVER (ORDER BY val_num))',
'duration': 'MIN(time), duration',
'integrate': self._time_precision_query('MIN(time)') + ', SUM(val_num * duration)',
'diff': self._time_precision_query('MIN(time)') + ', (val_num - LAG(val_num,1) OVER (ORDER BY val_num))',
'duration': self._time_precision_query('MIN(time)') + ', duration',
# differentiate (d/dt) is scaled to match the conversion from d/dt (kWh) = kWh: time is in ms, val_num in kWh, therefore scale by 1000ms and 3600s/h to obtain the result in kW:
'differentiate': 'MIN(time), (val_num - LAG(val_num,1) OVER (ORDER BY val_num)) / ( (time - LAG(time,1) OVER (ORDER BY val_num)) / (3600 * 1000) )',
'count': 'MIN(time), SUM(CASE WHEN val_num{op}{value} THEN 1 ELSE 0 END)'.format(**expression['params']),
'countall': 'MIN(time), COUNT(*)',
'min': 'MIN(time), MIN(val_num)',
'max': 'MIN(time), MAX(val_num)',
'on': 'MIN(time), ' + self._precision_query('SUM(val_bool * duration) / SUM(duration)'),
'differentiate': self._time_precision_query('MIN(time)') + ', (val_num - LAG(val_num,1) OVER (ORDER BY val_num)) / ( (time - LAG(time,1) OVER (ORDER BY val_num)) / (3600 * 1000) )',
'count': self._time_precision_query('MIN(time)') + ', SUM(CASE WHEN val_num{op}{value} THEN 1 ELSE 0 END)'.format(**expression['params']),
'countall': self._time_precision_query('MIN(time)') + ', COUNT(*)',
'min': self._time_precision_query('MIN(time)') + ', MIN(val_num)',
'max': self._time_precision_query('MIN(time)') + ', MAX(val_num)',
'on': self._time_precision_query('MIN(time)') + ', ' + self._precision_query('SUM(val_bool * duration) / SUM(duration)'),
'on.order': 'ORDER BY time ASC',
'sum': 'MIN(time), SUM(val_num)',
'raw': 'time, val_num',
'sum': self._time_precision_query('MIN(time)') + ', SUM(val_num)',
'raw': self._time_precision_query('time') + ', val_num',
'raw.order': 'ORDER BY time ASC',
'raw.group': ''
}
Expand Down Expand Up @@ -1241,6 +1242,10 @@ def _precision_query(self, query):
return 'ROUND({}, {})'.format(query, self._precision)
return query

def _time_precision_query(self, query):
if self._time_precision < 3:
return 'ROUND({}, {})'.format(query, self._time_precision - 3)
return query

def _fetch_log(self, item, columns, start, end, step=None, count=100, group='', order=''):
_item = self.items.return_item(item)
Expand Down
7 changes: 7 additions & 0 deletions database/plugin.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,13 @@ parameters:
de: 'Genauigkeit der aus der Datenbank ausgelesenen Werte (Nachkommastellen).'
en: 'Precision of values read from database (digits after comma).'

time_precision:
type: int
default: 3
description:
de: 'Genauigkeit der aus der Datenbank ausgelesenen Zeitwerte (Nachkommastellen (für Sekunden)).'
en: 'Precision of time values read from database (digits after comma (for seconds).'

count_logentries:
type: bool
default: False
Expand Down
6 changes: 3 additions & 3 deletions enocean/protocol/eep_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ def _parse_eep_A5_07_03(self, payload, status):
self.logger.error(f"Occupancy sensor issued error code: {payload[0]}")
else:
result['SVC'] = payload[0] / 255.0 * 5.0 # supply voltage in volts
result['ILL'] = payload[1] << 2 + (payload[2] & 0xC0) >> 6 # 10 bit illumination in lux
result['ILL'] = (payload[1] << 2) + ((payload[2] & 0xC0) >> 6) # 10 bit illumination in lux
result['PIR'] = (payload[3] & 0x80) == 0x80 # Movement flag, 1:motion detected
self.logger.debug(f"Occupancy: PIR:{result['PIR']} illumination: {result['ILL']}lx, voltage: {result['SVC']}V")
return result
Expand Down Expand Up @@ -240,7 +240,7 @@ def _parse_eep_A5_12_01(self, payload, status):
self.logger.debug("Processing A5_12_01: powermeter: Unit is Watts")
else:
self.logger.debug("Processing A5_12_01: powermeter: Unit is kWh")
value = (payload[0] << 16 + payload[1] << 8 + payload[2]) / divisor
value = ((payload[0] << 16) + (payload[1] << 8) + payload[2]) / divisor
self.logger.debug(f"Processing A5_12_01: powermeter: {value} W")

# It is confirmed by Eltako that with the use of multiple repeaters in an Eltako network, values can be corrupted in random cases.
Expand Down Expand Up @@ -326,7 +326,7 @@ def _parse_eep_A5_38_08(self, payload, status):
def _parse_eep_A5_3F_7F(self, payload, status):
self.logger.debug("Processing A5_3F_7F")
results = {'DI_3': (payload[3] & 1 << 3) == 1 << 3, 'DI_2': (payload[3] & 1 << 2) == 1 << 2, 'DI_1': (payload[3] & 1 << 1) == 1 << 1, 'DI_0': (payload[3] & 1 << 0) == 1 << 0}
results['AD_0'] = ((payload[1] & 0x03) << 8 + payload[2]) * 1.8 / pow(2, 10)
results['AD_0'] = (((payload[1] & 0x03) << 8) + payload[2]) * 1.8 / pow(2, 10)
results['AD_1'] = (payload[1] >> 2) * 1.8 / pow(2, 6)
results['AD_2'] = payload[0] * 1.8 / pow(2, 8)
return results
Expand Down
Loading

0 comments on commit 3eea4c9

Please sign in to comment.