|
| 1 | +#!/usr/bin/env ruby |
| 2 | +# frozen_string_literal: true |
| 3 | + |
| 4 | +# See documentation at the end of this file. |
| 5 | + |
| 6 | +require 'json' |
| 7 | +require 'net/http' |
| 8 | +require 'uri' |
| 9 | + |
| 10 | +if ARGV.length != 1 || ARGV.first != 'config' |
| 11 | + raise 'Error: plugin designed for the dirtyconfig protocol, must be run with the config argument' |
| 12 | +end |
| 13 | + |
| 14 | +address = ENV.fetch('address', nil) |
| 15 | +raise 'Error: address not set' if address.nil? |
| 16 | + |
| 17 | +uri_prefix = "http://#{address}/api/1/" |
| 18 | +responses = {} |
| 19 | + |
| 20 | +%w[ |
| 21 | + vitals |
| 22 | + wifi_status |
| 23 | + lifetime |
| 24 | +].each do |endpoint| |
| 25 | + responses[endpoint] = JSON.parse( |
| 26 | + Net::HTTP.get_response(URI("#{uri_prefix}#{endpoint}")).body |
| 27 | + ) |
| 28 | +end |
| 29 | + |
| 30 | +puts <<~MUNIN |
| 31 | + multigraph tesla_wall_connector_times |
| 32 | + graph_title Tesla Wall Connector Times |
| 33 | + graph_args --base 1000 --lower-limit 0 |
| 34 | + graph_scale no |
| 35 | + graph_vlabel Time (days) |
| 36 | + graph_category tesla |
| 37 | + poweron.label Power On Time |
| 38 | + poweron.draw AREA |
| 39 | + poweron.type GAUGE |
| 40 | + poweron.value #{responses['lifetime']['uptime_s'] / 86_400.0} |
| 41 | + uptime.label Uptime |
| 42 | + uptime.draw AREA |
| 43 | + uptime.type GAUGE |
| 44 | + uptime.value #{responses['vitals']['uptime_s'] / 86_400.0} |
| 45 | + charging.label Charging Time |
| 46 | + charging.type GAUGE |
| 47 | + charging.draw LINE2 |
| 48 | + charging.value #{responses['lifetime']['charging_time_s'] / 86_400.0} |
| 49 | + session.label Session |
| 50 | + session.type GAUGE |
| 51 | + session.draw LINE2 |
| 52 | + session.value #{responses['vitals']['session_s'] / 86_400.0} |
| 53 | +
|
| 54 | + multigraph tesla_wall_connector_power |
| 55 | + graph_title Tesla Wall Connector Power Output |
| 56 | + graph_args --base 1000 --lower-limit 0 |
| 57 | + graph_vlabel Power (W) |
| 58 | + graph_category tesla |
| 59 | + power.label Power output |
| 60 | + power.type DERIVE |
| 61 | + power.min 0 |
| 62 | + power.value #{(responses['vitals']['session_energy_wh'] * 3600.0).round} |
| 63 | +
|
| 64 | + multigraph tesla_wall_connector_cycles |
| 65 | + graph_title Tesla Wall Connector Cycle Counts |
| 66 | + graph_args --base 1000 --lower-limit 0 |
| 67 | + graph_scale no |
| 68 | + graph_category tesla |
| 69 | + contactor.label Contactor |
| 70 | + contactor.draw AREA |
| 71 | + contactor.type GAUGE |
| 72 | + contactor.value #{responses['lifetime']['contactor_cycles']} |
| 73 | + connector.label Connector |
| 74 | + connector.draw AREA |
| 75 | + connector.type GAUGE |
| 76 | + connector.value #{responses['lifetime']['connector_cycles']} |
| 77 | + contactor_loaded.label Contactor (loaded) |
| 78 | + contactor_loaded.draw AREA |
| 79 | + contactor_loaded.type GAUGE |
| 80 | + contactor_loaded.value #{responses['lifetime']['contactor_cycles_loaded']} |
| 81 | + alerts.label Alerts |
| 82 | + alerts.type GAUGE |
| 83 | + alerts.draw LINE2 |
| 84 | + alerts.value #{responses['lifetime']['alert_count']} |
| 85 | + thermal_foldbacks.label Thermal foldbacks |
| 86 | + thermal_foldbacks.type GAUGE |
| 87 | + thermal_foldbacks.draw LINE2 |
| 88 | + thermal_foldbacks.value #{responses['lifetime']['thermal_foldbacks']} |
| 89 | +
|
| 90 | + multigraph tesla_wall_connector_voltage |
| 91 | + graph_title Tesla Wall Connector Voltages |
| 92 | + graph_category tesla |
| 93 | + graph_vlabel Voltage (V) |
| 94 | + grid.label Grid |
| 95 | + grid.type GAUGE |
| 96 | + grid.value #{responses['vitals']['grid_v']} |
| 97 | + A.label A |
| 98 | + A.type GAUGE |
| 99 | + A.value #{responses['vitals']['voltageA_v']} |
| 100 | + B.label B |
| 101 | + B.type GAUGE |
| 102 | + B.value #{responses['vitals']['voltageB_v']} |
| 103 | + C.label C |
| 104 | + C.type GAUGE |
| 105 | + C.value #{responses['vitals']['voltageC_v']} |
| 106 | + relay_coil.label Relay coil |
| 107 | + relay_coil.type GAUGE |
| 108 | + relay_coil.value #{responses['vitals']['relay_coil_v']} |
| 109 | +
|
| 110 | + multigraph tesla_wall_connector_frequency |
| 111 | + graph_title Tesla Wall Connector Frequency |
| 112 | + graph_category tesla |
| 113 | + graph_args --base 1000 --lower-limit 0 |
| 114 | + graph_vlabel Frequency (Hz) |
| 115 | + grid.label Grid |
| 116 | + grid.type GAUGE |
| 117 | + grid.value #{responses['vitals']['grid_hz']} |
| 118 | +
|
| 119 | + multigraph tesla_wall_connector_current |
| 120 | + graph_title Tesla Wall Connector Currents |
| 121 | + graph_category tesla |
| 122 | + graph_args --base 1000 --lower-limit 0 |
| 123 | + graph_vlabel Current (A) |
| 124 | + vehicle.label Vehicle |
| 125 | + vehicle.type GAUGE |
| 126 | + vehicle.value #{responses['vitals']['vehicle_current_a']} |
| 127 | + A.label A |
| 128 | + A.type GAUGE |
| 129 | + A.value #{responses['vitals']['currentA_a']} |
| 130 | + B.label B |
| 131 | + B.type GAUGE |
| 132 | + B.value #{responses['vitals']['currentB_a']} |
| 133 | + C.label C |
| 134 | + C.type GAUGE |
| 135 | + C.value #{responses['vitals']['currentC_a']} |
| 136 | + N.label N |
| 137 | + N.type GAUGE |
| 138 | + N.value #{responses['vitals']['currentN_a']} |
| 139 | +
|
| 140 | + multigraph tesla_wall_connector_temperature |
| 141 | + graph_title Tesla Wall Connector Temperatures |
| 142 | + graph_category tesla |
| 143 | + graph_vlabel Temperature (°C) |
| 144 | + pcba.label PCBA |
| 145 | + pcba.type GAUGE |
| 146 | + pcba.value #{responses['vitals']['pcba_temp_c']} |
| 147 | + handle.label Handle |
| 148 | + handle.type GAUGE |
| 149 | + handle.value #{responses['vitals']['handle_temp_c']} |
| 150 | + mcu.label MCU |
| 151 | + mcu.type GAUGE |
| 152 | + mcu.value #{responses['vitals']['mcu_temp_c']} |
| 153 | +
|
| 154 | + multigraph tesla_wall_connector_wifi |
| 155 | + graph_title Tesla Wall Connector Wi-Fi |
| 156 | + graph_category tesla |
| 157 | + signal_strength.label Signal strength |
| 158 | + signal_strength.type GAUGE |
| 159 | + signal_strength.value #{responses['wifi_status']['wifi_signal_strength']} |
| 160 | + rssi.label RSSI |
| 161 | + rssi.type GAUGE |
| 162 | + rssi.value #{responses['wifi_status']['wifi_rssi']} |
| 163 | + snr.label SNR |
| 164 | + snr.type GAUGE |
| 165 | + snr.value #{responses['wifi_status']['wifi_snr']} |
| 166 | +MUNIN |
| 167 | + |
| 168 | +__END__ |
| 169 | + |
| 170 | +=pod |
| 171 | + |
| 172 | +=encoding utf8 |
| 173 | + |
| 174 | +=head1 NAME |
| 175 | + |
| 176 | +tesla_wall_connector - Munin plugin for graphing data from Tesla Wall |
| 177 | +Connector electric vehicle charging stations. |
| 178 | + |
| 179 | +=head1 CONFIGURATION |
| 180 | + |
| 181 | +Configuration in C</etc/munin/plugin-conf.d/munin-node>: |
| 182 | + |
| 183 | + [tesla_wall_connector] |
| 184 | + # IP address or hostname of your Tesla Wall Connector |
| 185 | + env.address 10.0.0.136 |
| 186 | + |
| 187 | +=head1 NOTES |
| 188 | + |
| 189 | +Requires the multigraph and dirtyconfig capabilities available in munin 2.0 |
| 190 | +and newer. |
| 191 | + |
| 192 | +Developed and tested with Tesla Wall Connector generation 3 firmware |
| 193 | +version 22.7.0+gbc6c1736fa3426, part number 1457768-02-G (from |
| 194 | +C</api/1/version>). |
| 195 | + |
| 196 | +=head1 KNOWN ISSUES |
| 197 | + |
| 198 | +The Tesla Wall Connector stops responding to queries on its REST |
| 199 | +API during charging for unknown reasons. |
| 200 | + |
| 201 | +=head1 AUTHOR |
| 202 | + |
| 203 | +Copyright © 2022 Kenyon Ralph < [email protected]> |
| 204 | + |
| 205 | +=head1 LICENSE |
| 206 | + |
| 207 | +This program is free software: you can redistribute it and/or modify it under |
| 208 | +the terms of the GNU General Public License as published by the Free Software |
| 209 | +Foundation, either version 3 of the License, or (at your option) any later |
| 210 | +version. |
| 211 | + |
| 212 | +This program is distributed in the hope that it will be useful, but WITHOUT |
| 213 | +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
| 214 | +FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. |
| 215 | + |
| 216 | +You should have received a copy of the GNU General Public License along with |
| 217 | +this program. If not, see L<https://www.gnu.org/licenses/>. |
| 218 | + |
| 219 | +=cut |
0 commit comments