Skip to content

Commit aa0dfe1

Browse files
committed
disable the new station_name field by default to avoid breaking existing installs
1 parent 651dbfb commit aa0dfe1

File tree

4 files changed

+22
-6
lines changed

4 files changed

+22
-6
lines changed

CHANGELOG.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
## New features
77
- Refactor and improve history and detailed data collection including consistent timezone usage - @cooldil
88
- Add --dryrun CLI arg for skipping writes to InfluxDB - @garthweb
9-
- Include station_name field in all new InfluxDB datapoints, to distinguish similarly named channel devices within a single account - @garthweb
9+
- New configuration option to include station_name field in all new InfluxDB datapoints, to distinguish similarly named channel devices within a single account - @garthweb
1010

1111
## Other changes
1212
- Upgrade to pyemvue 0.18.6 - @jertel

README.md

+6
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,12 @@ Be aware that the included dashboard assumes your device name contains the word
157157
]
158158
```
159159

160+
### Station Names
161+
162+
If you intend to run multiple Vue systems under the same account, where the channel names duplicate or look similar across those Vue systems then you may want to consider enabling the `addStationField` config parameter. This will include an additional field named 'station_name' in the InfluxDB event record, to help distinguish channel names across those Vue systems or 'stations'.
163+
164+
Note that enabling this at a later time will cause issues due to queries matching multiple records. Therefore if you are installing Vuegraf for the first time and think this could be useful then enable it at the start.
165+
160166
# Running
161167
Vuegraf can be run either as a container (recommended), or as a host process.
162168

src/vuegraf/vuegraf.py

+14-5
Original file line numberDiff line numberDiff line change
@@ -111,17 +111,17 @@ def createDataPoint(accountName, deviceName, chanName, watts, timestamp, detaile
111111
if influxVersion == 2:
112112
dataPoint = influxdb_client.Point('energy_usage') \
113113
.tag('account_name', accountName) \
114-
.tag('station_name', deviceName) \
115114
.tag('device_name', chanName) \
116115
.tag(tagName, detailed) \
117116
.field('usage', watts) \
118117
.time(time=timestamp)
118+
if addStationField:
119+
dataPoint.tag('station_name', deviceName)
119120
else:
120121
dataPoint = {
121122
'measurement': 'energy_usage',
122123
'tags': {
123124
'account_name': accountName,
124-
'station_name': deviceName,
125125
'device_name': chanName,
126126
tagName: detailed,
127127
},
@@ -130,6 +130,9 @@ def createDataPoint(accountName, deviceName, chanName, watts, timestamp, detaile
130130
},
131131
'time': timestamp
132132
}
133+
if addStationField:
134+
dataPoint['tags']['station_name'] = deviceName
135+
133136
return dataPoint
134137

135138
def dumpPoints(label, usageDataPoints):
@@ -146,22 +149,27 @@ def getLastDBTimeStamp(deviceName, chanName, pointType, fooStartTime, fooStopTim
146149
# Get timestamp of last record in database
147150
# Influx v2
148151
if influxVersion == 2:
152+
stationFilter = ""
153+
if addStationField:
154+
stationFilter = ' r.station_name == "' + deviceName + '" and '
149155
timeCol = '_time'
150156
result = query_api.query('from(bucket:"' + bucket + '") ' +
151157
'|> range(start: -3w) ' +
152158
'|> filter(fn: (r) => ' +
153159
' r._measurement == "energy_usage" and ' +
154160
' r.' + tagName + ' == "' + pointType + '" and ' +
155-
' r._field == "usage" and ' +
156-
' r.station_name == "' + deviceName + '" and ' +
161+
' r._field == "usage" and ' + stationFilter +
157162
' r.device_name == "' + chanName + '")' +
158163
'|> last()')
159164

160165
if len(result) > 0 and len(result[0].records) > 0:
161166
lastRecord = result[0].records[0]
162167
timeStr = lastRecord['_time'].isoformat()
163168
else: # Influx v1
164-
result = influx.query('select last(usage), time from energy_usage where (station_name = \'' + station_name + '\' AND device_name = \'' + chanName + '\' AND ' + tagName + ' = \'' + pointType + '\')')
169+
stationFilter = ""
170+
if addStationField:
171+
stationFilter = 'station_name = \'' + station_name + '\' AND '
172+
result = influx.query('select last(usage), time from energy_usage where (' + stationFilter + 'device_name = \'' + chanName + '\' AND ' + tagName + ' = \'' + pointType + '\')')
165173
if len(result) > 0:
166174
timeStr = next(result.get_points())['time']
167175

@@ -437,6 +445,7 @@ def extractDataPoints(device, usageDataPoints, pointType=None, historyStartTime=
437445
if 'tagValue_day' in config['influxDb']:
438446
tagValue_day = config['influxDb']['tagValue_day']
439447

448+
addStationField = getConfigValue('addStationField', False)
440449
maxHistoryDays = getConfigValue('maxHistoryDays', 720)
441450
historyDays = min(args.historydays, maxHistoryDays)
442451
history = historyDays > 0

vuegraf.json.sample

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"token": "<my-secret-token>"
88
},
99
"updateIntervalSecs": 60,
10+
"addStationField": false,
1011
"detailedDataEnabled": true,
1112
"detailedDataSecondsEnabled": true,
1213
"detailedDataHoursEnabled": true,

0 commit comments

Comments
 (0)