This repository has been archived by the owner on Nov 1, 2018. It is now read-only.
forked from karioja/vedirect
-
Notifications
You must be signed in to change notification settings - Fork 4
/
vedirect_signalk.py
97 lines (83 loc) · 2.7 KB
/
vedirect_signalk.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#!/usr/bin/python
from vedirect import vedirect
import json
import sys
key_base = 'electrical.chargers.victron.'
error_codes = {
0: 'No error',
2: 'Battery voltage too high',
17: 'Charger temperature too high',
18: 'Charger over current',
19: 'Charger current reversed',
20: 'Bulk time limit exceeded',
21: 'Current sensor issue (sensor bias/sensor broken)',
26: 'Terminals overheated',
33: 'Input voltage too high (solar panel)',
34: 'Input current too high (solar panel)',
38: 'Input shutdown (due to excessive battery voltage)',
116: 'Factory calibration data lost',
117: 'Invalid/incompatible firmware',
119: 'User settings invalid'
}
def conv_error(code):
return error_codes[int(code)]
device_state_map= {
0: 'not charging',
2: 'fault',
3: 'charging bulk',
4: 'charging absorption',
5: 'charging float'
}
def conv_mode(code):
return device_state_map[int(code)]
values = {
'LOAD': { 'key': 'load' },
'H19': { 'key': 'yieldTotal', 'mx': 0.01 },
'VPV': { 'key': 'panelVoltage', 'mx': 0.001 },
'ERR': { 'key': 'error', 'f': conv_error },
'FW': { 'key': 'firmwareVersion', 'mx': 0.01 },
'I': { 'key': 'current', 'mx': 0.001 },
'H21': { 'key': 'maximumPowerToday', 'f': int }, #W
'IL': { 'key': 'loadCurrent', 'mx': 0.001},
'PID': { 'key': 'productId' },
'H20': { 'key': 'yieldToday', 'mx': 0.01 }, #kWh
'H23': { 'key': 'maximumPowerYesterday', 'f': int }, #W
'H22': { 'key': 'yieldYesterday', 'mx': 0.01 }, #kWh
'HSDS': { 'key': 'daySequenceNumber', 'f': int },
'SER#': { 'key': 'serialNumber' },
'V': { 'key': 'batteryVoltage', 'mx': 0.001 },
'CS': { 'key': 'mode', 'f': conv_mode} ,
'PPV': { 'key': 'panelPower', 'f': int }
}
def print_data_callback(data):
updates = []
for k in data.keys():
if not values.has_key(k):
continue
info = values[k]
key = key_base + info['key']
value = data[k]
if info.has_key('mx'):
value = float(value) * info['mx']
elif info.has_key('f'):
func = info['f']
value = func(value)
updates.append({"path": key, "value": value})
if k == 'CS':
updates.append({'path': key_base + 'modeValue',
'value': int(data[k])})
delta = {
"updates": [
{
"source": {
"label": "victron_1"
},
"values": updates
}
]
}
print json.dumps(delta)
sys.stdout.flush()
if __name__ == '__main__':
ve = vedirect('/dev/ve-direct')
ve.read_data_callback(print_data_callback)