Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 48 additions & 3 deletions influxdb/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,33 @@ config_description = [{'name': 'url',
'description': 'Optional interval overrides',
'repeat': True,
'min': 0,
'content': [{'name': 'component', 'type': 'str'},
{'name': 'interval', 'type': 'int'}]}]
'content': [{'name': 'component', 'type': 'str'},
{'name': 'interval', 'type': 'int'}]},
{'name': 'tags',
'type': 'section',
'description': 'Additional tags which are added based on the name of a power sensor',
'repeat': True,
'min': 0,
'content': [{'name': 'name',
'type': 'str',
'description': 'name of the power input'},
{'name': 'tags',
'type': 'section',
'repeat': True,
'description': 'Key/Value pairs indicating the additional tags to be added for the selected name. Don\'t use name, type or id as key',
'content': [{'name': 'tag key',
'type': 'str',
'description': 'tag key'},
{'name': 'tag value',
'type': 'str',
'description': 'tag value'}]},
]
}]
```

The ```url``` and ```database``` parameters are self-explaining. The ```intervals``` parameter allows to override
the build-in intervals on which data will be pushed. The components are documented below, the interval is the frequency
(in seconds) with which the data should be sent (approximately).
(in seconds) with which the data should be sent (approximately). The ```tags``` parameter allows to add additional tags to the power metrics. As such you can add additional logical tags to your measurements linked to the name of the sensor. More detail and an example is provided below.

## Data

Expand Down Expand Up @@ -236,3 +256,28 @@ Example:
```
energy,type=fibaro,id=13,name=xbox360 power=253.4,counter=58223.0
```

### Additional tags on power metrics

Suppose you have multiple power sensors deployed, possibly across multiple modules. By default, only 3 tags are added to your measurement:

* type: hardcoded to openmotics
* name: the name you chose for this power sensor
* id: the device ID

Without any additional tags, you can only encode additional metadata in the name and afterwards use regular expressions within influxdb to create more powerful queries. By adding additional tags, writing such queries becomes much easier and straight forward.

Imagine you have several measuring points for a single room. Some are outlets, others on lights. Or you have multiple lines covering a single device (multi phase). You can now add additional tags to each measurement, encoding the actual location or a device name.

As an example: have a house with 2 floors, each floor has 2 rooms. Every room has 2 sensors, one for all outlets and one covering all lights. The sensors are named according to their position on the module, e.g., no information encoded in the name. We could now add tags to the sensors.

sensor_1, room=kitchen, floor=groundfloor, category=outlet
sensor_2, room=kitchen, floor=groundfloor, category=light
sensor_3, room=badroom, floor=upper, category=outlet
sensor_3, room=bedroom, floor=upper, category=light

In influxdb, we now have the power to calculate overall light consumption or get the values for the entire groundfloor.

Tag name and tag value can be specified independently for each sensor.


36 changes: 34 additions & 2 deletions influxdb/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class InfluxDB(OMPluginBase):
"""

name = 'InfluxDB'
version = '1.2.2'
version = '1.2.3'
interfaces = [('config', '1.0')]

config_description = [{'name': 'url',
Expand All @@ -37,7 +37,27 @@ class InfluxDB(OMPluginBase):
'repeat': True,
'min': 0,
'content': [{'name': 'component', 'type': 'str'},
{'name': 'interval', 'type': 'int'}]}]
{'name': 'interval', 'type': 'int'}]},
{'name': 'tags',
'type': 'section',
'description': 'Additional tags which are added based on the name of a power sensor',
'repeat': True,
'min': 0,
'content': [{'name': 'name',
'type': 'str',
'description': 'name of the power input'},
{'name': 'tags',
'type': 'section',
'repeat': True,
'description': 'Key/Value pairs indicating the additional tags to be added for the selected name. Don\'t use name, type or id as key',
'content': [{'name': 'tag key',
'type': 'str',
'description': 'tag key'},
{'name': 'tag value',
'type': 'str',
'description': 'tag value'}]},
]
}]

default_config = {'url': '', 'database': 'openmotics'}

Expand Down Expand Up @@ -71,6 +91,14 @@ def _read_config(self):
self._intervals = {}
for item in intervals:
self._intervals[item['component']] = item['interval']

tags = self._config.get('tags',[])
self._tags = {}
for item in tags:
self._tags[item['name']] = {}
for tagdef in item['tags']:
self._tags[item['name']][tagdef['tag key']] = tagdef['tag value']

username = self._config.get('username', '')
password = self._config.get('password', '')
self._auth = None if username == '' else (username, password)
Expand Down Expand Up @@ -540,6 +568,10 @@ def _run_power_openmotics(self, interval):
data = {'type': 'openmotics',
'id': device_id,
'name': device['name']}

tags = self._tags.get(device['name'], "")
data.update(tags)

values = {'voltage': device['voltage'],
'current': device['current'],
'frequency': device['frequency'],
Expand Down