-
Notifications
You must be signed in to change notification settings - Fork 2
/
teslawallconnector-exporter.py
executable file
·124 lines (106 loc) · 5.7 KB
/
teslawallconnector-exporter.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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#!/usr/bin/python3 -u
import json
import sys
import time
import requests
from prometheus_client import start_http_server, Gauge
contactor_closed = Gauge('contactor_closed', 'Indicates if contactor is closed')
vehicle_connected = Gauge('vehicle_connected', 'Indicates if vehicle is connected')
session_s = Gauge('session_s', 'Number of second the vehicle is currently being charged')
grid_v = Gauge('grid_v', 'Current voltage of grid')
grid_hz = Gauge('grid_hz', 'Current grid frequency')
vehicle_current_a = Gauge('vehicle_current_a', 'Current amps to vehicle')
currentA_a = Gauge('currentA_a', 'Current amps phase 1')
currentB_a = Gauge('currentB_a', 'Current amps phase 2')
currentC_a = Gauge('currentC_a', 'Current amps phase 3')
currentN_a = Gauge('currentN_a', 'Current amps neutral')
voltageA_v = Gauge('voltageA_v', 'Current voltage phase 1')
voltageB_v = Gauge('voltageB_v', 'Current voltage phase 2')
voltageC_v = Gauge('voltageC_v', 'Current voltage phase 3')
relay_coil_v = Gauge('relay_coil_v', 'Current voltage relay coil')
pcba_temp_c = Gauge('pcba_temp_c', 'Current temperature PCBA')
handle_temp_c = Gauge('handle_temp_c', 'Current temperature handle')
mcu_temp_c = Gauge('mcu_temp_c', 'Current temperature MCU')
uptime_s = Gauge('uptime_s', 'Uptime in seconds')
input_thermopile_uv = Gauge('input_thermopile_uv', 'Thermopile element uv')
prox_v = Gauge('prox_v', 'Prox voltage')
pilot_high_v = Gauge('pilot_high_v', 'Pilot high voltage')
pilot_low_v = Gauge('pilot_low_v', 'Pilot high voltage')
session_energy_wh = Gauge('session_energy_wh', 'Used energy of this charging session')
config_status = Gauge('config_status', 'Config status')
evse_state = Gauge('evse_state', 'Evse state')
wifi_signal_strength = Gauge('wifi_signal_strength', 'WiFi signal strength')
wifi_rssi = Gauge('wifi_rssi', 'WiFi RSSI')
wifi_snr = Gauge('wifi_snr', 'WiFi SNR')
wifi_connected = Gauge('wifi_connected', 'WiFi connected')
internet = Gauge('internet', 'Internet connected')
contactor_cycles = Gauge('contactor_cycles', 'Contactor cycles')
contactor_cycles_loaded = Gauge('contactor_cycles_loaded', 'Contactor cycles loaded')
alert_count = Gauge('alert_count', 'Alert count')
thermal_foldbacks = Gauge('thermal_foldbacks', 'Thermal foldbacks')
charge_starts = Gauge('charge_starts', 'Charge starts')
energy_wh = Gauge('energy_wh', 'Total energy')
connector_cycles = Gauge('connector_cycles', 'Connector cycles')
uptime_total_s = Gauge('uptime_total_s', 'Total uptime')
charging_time_s = Gauge('charging_time_s', 'Total charging time')
wall_connector_info = Gauge('wall_connector_info', 'Tesla wall connector info',
['firmware_version', 'part_number', 'serial_number'])
if __name__ == '__main__':
print("Tesla wall connector exporter v0.3\n")
ip_address = '192.168.178.64'
server_port = 3225
if len(sys.argv) > 1:
ip_address = sys.argv[1]
print("IP: " + ip_address)
print("Port: " + str(server_port) + "\n")
start_http_server(server_port)
while True:
response = json.loads(requests.get('http://' + ip_address + '/api/1/vitals').content.decode('UTF-8'))
contactor_closed.set(response['contactor_closed'])
vehicle_connected.set(response['vehicle_connected'])
session_s.set(response['session_s'])
grid_v.set(response['grid_v'])
grid_hz.set(response['grid_hz'])
vehicle_current_a.set(response['vehicle_current_a'])
currentA_a.set(response['currentA_a'])
currentB_a.set(response['currentB_a'])
currentC_a.set(response['currentC_a'])
currentN_a.set(response['currentN_a'])
voltageA_v.set(response['voltageA_v'])
voltageB_v.set(response['voltageB_v'])
voltageC_v.set(response['voltageC_v'])
relay_coil_v.set(response['relay_coil_v'])
pcba_temp_c.set(response['pcba_temp_c'])
handle_temp_c.set(response['handle_temp_c'])
mcu_temp_c.set(response['mcu_temp_c'])
uptime_s.set(response['uptime_s'])
input_thermopile_uv.set(response['input_thermopile_uv'])
prox_v.set(response['prox_v'])
pilot_high_v.set(response['pilot_high_v'])
pilot_low_v.set(response['pilot_low_v'])
session_energy_wh.set(response['session_energy_wh'])
config_status.set(response['config_status'])
evse_state.set(response['evse_state'])
response = json.loads(requests.get('http://' + ip_address + '/api/1/wifi_status').content.decode('UTF-8'))
wifi_signal_strength.set(response['wifi_signal_strength'])
wifi_rssi.set(response['wifi_rssi'])
wifi_snr.set(response['wifi_snr'])
wifi_connected.set(response['wifi_connected'])
internet.set(response['internet'])
response = requests.get('http://' + ip_address + '/api/1/lifetime').content.decode('UTF-8')
response = response.replace('"avg_startup_temp":nan,', '')
response = json.loads(response)
contactor_cycles.set(response['contactor_cycles'])
contactor_cycles_loaded.set(response['contactor_cycles_loaded'])
alert_count.set(response['alert_count'])
thermal_foldbacks.set(response['thermal_foldbacks'])
charge_starts.set(response['charge_starts'])
energy_wh.set(response['energy_wh'])
connector_cycles.set(response['connector_cycles'])
uptime_total_s.set(response['uptime_s'])
charging_time_s.set(response['charging_time_s'])
response = json.loads(requests.get('http://' + ip_address + '/api/1/version').content.decode('UTF-8'))
wall_connector_info.labels(firmware_version=response['firmware_version'],
part_number=response['part_number'],
serial_number=response['serial_number']).set(1)
time.sleep(10)