Tesla Wall Charger (Gen3) API Statistics

The Gen 3 Tesla Wall Chargers with WIFI have an API available at a few URLs:

To parse these values into OpenHAB to be used for your rules create the following:

Tesla.Items

Group                       Tesla
Group                       WallCharger                                                                                            (Tesla)
Group                       gWallConnector_Vitals_Parse_json                                                                       (WallCharger)                            //JSON API: http://192.168.X.XX/api/1/vitals
Group                       gWallConnector_LifeTime_Parse_json                                                                     (WallCharger)                            //JSON API: http://192.168.X.XX/api/1/lifetime
Group                       gWallConnector_Version_Parse_json                                                                      (WallCharger)                            //JSON API: http://192.168.X.XX/api/1/version
//JSON
String                      G_Tesla_WallConnector_Vitals_JSON                         "Tesla WallConnector Vitals JSON: [%s]"
String                      G_Tesla_WallConnector_LifeTime_JSON                       "Tesla WallConnector LifeTime JSON: [%s]"
String                      G_Tesla_WallConnector_Version_JSON                        "Tesla WallConnector Version JSON: [%s]"
//Items parsed from http://192.168.X.XX/api/1/vitals
String                      G_Tesla_WallConnector_Vitals_contactor_closed             "contactor_closed"                           (gWallConnector_Vitals_Parse_json)
String                      G_Tesla_WallConnector_Vitals_vehicle_connected            "vehicle_connected"                          (gWallConnector_Vitals_Parse_json)
Number                      G_Tesla_WallConnector_Vitals_session_s                    "Sessions"                                   (gWallConnector_Vitals_Parse_json)
Number:ElectricPotential    G_Tesla_WallConnector_Vitals_grid_v                       "Grid Voltage"                               (gWallConnector_Vitals_Parse_json)
Number:Frequency            G_Tesla_WallConnector_Vitals_grid_hz                      "Grid Hertz"                                 (gWallConnector_Vitals_Parse_json)
Number:ElectricCurrent      G_Tesla_WallConnector_Vitals_vehicle_current_a            "Vehicle Amps"                               (gWallConnector_Vitals_Parse_json)
Number:ElectricCurrent      G_Tesla_WallConnector_Vitals_currentA_a                   "currentA_a"                                 (gWallConnector_Vitals_Parse_json)
Number:ElectricCurrent      G_Tesla_WallConnector_Vitals_currentB_a                   "currentB_a"                                 (gWallConnector_Vitals_Parse_json)
Number:ElectricCurrent      G_Tesla_WallConnector_Vitals_currentC_a                   "currentC_a"                                 (gWallConnector_Vitals_Parse_json)
Number:ElectricCurrent      G_Tesla_WallConnector_Vitals_currentN_a                   "currentN_a"                                 (gWallConnector_Vitals_Parse_json)
Number:ElectricPotential    G_Tesla_WallConnector_Vitals_voltageA_v                   "voltageA_v"                                 (gWallConnector_Vitals_Parse_json)
Number:ElectricPotential    G_Tesla_WallConnector_Vitals_voltageB_v                   "voltageB_v"                                 (gWallConnector_Vitals_Parse_json)
Number:ElectricPotential    G_Tesla_WallConnector_Vitals_voltageC_v                   "voltageC_v"                                 (gWallConnector_Vitals_Parse_json)
Number:ElectricPotential    G_Tesla_WallConnector_Vitals_relay_coil_v                 "relay_coil_v"                               (gWallConnector_Vitals_Parse_json)
Number:Temperature          G_Tesla_WallConnector_Vitals_pcba_temp_c                  "pcba_temp_c"                                (gWallConnector_Vitals_Parse_json)
Number:Temperature          G_Tesla_WallConnector_Vitals_handle_temp_c                "handle_temp_c"                              (gWallConnector_Vitals_Parse_json)
Number:Temperature          G_Tesla_WallConnector_Vitals_mcu_temp_c                   "mcu_temp_c"                                 (gWallConnector_Vitals_Parse_json)
Number:Time                 G_Tesla_WallConnector_Vitals_uptime_s                     "uptime_s"                                   (gWallConnector_Vitals_Parse_json)
Number                      G_Tesla_WallConnector_Vitals_input_thermopile_uv          "input_thermopile_uv"                        (gWallConnector_Vitals_Parse_json)
Number                      G_Tesla_WallConnector_Vitals_prox_v                       "prox_v"                                     (gWallConnector_Vitals_Parse_json)
Number:ElectricPotential    G_Tesla_WallConnector_Vitals_pilot_high_v                 "pilot_high_v"                               (gWallConnector_Vitals_Parse_json)
Number:ElectricPotential    G_Tesla_WallConnector_Vitals_pilot_low_v                  "pilot_low_v"                                (gWallConnector_Vitals_Parse_json)
Number:Energy               G_Tesla_WallConnector_Vitals_session_energy_wh            "session_energy_wh"                          (gWallConnector_Vitals_Parse_json)
Number                      G_Tesla_WallConnector_Vitals_config_status                "config_status"                              (gWallConnector_Vitals_Parse_json)
Number                      G_Tesla_WallConnector_Vitals_evse_state                   "evse_state"                                 (gWallConnector_Vitals_Parse_json)

//Items parsed from http://192.168.X.XX/api/1/lifetime
Number                      G_Tesla_WallConnector_Lifetime_contactor_cycles           "contactor_cycles"                           (gWallConnector_LifeTime_Parse_json)
Number                      G_Tesla_WallConnector_Lifetime_contactor_cycles_loaded    "contactor_cycles_loaded"                    (gWallConnector_LifeTime_Parse_json)
Number                      G_Tesla_WallConnector_Lifetime_thermal_foldbacks          "thermal_foldbacks"                          (gWallConnector_LifeTime_Parse_json)
Number:Temperature          G_Tesla_WallConnector_Lifetime_avg_startup_temp           "avg_startup_temp"                           (gWallConnector_LifeTime_Parse_json)
Number                      G_Tesla_WallConnector_Lifetime_charge_starts              "charge_starts"                              (gWallConnector_LifeTime_Parse_json)
Number:Energy               G_Tesla_WallConnector_Lifetime_energy_wh                  "energy_wh"                                  (gWallConnector_LifeTime_Parse_json)
Number                      G_Tesla_WallConnector_Lifetime_connector_cycles           "connector_cycles"                           (gWallConnector_LifeTime_Parse_json)
Number:Time                 G_Tesla_WallConnector_Lifetime_uptime_s                   "uptime_s"                                   (gWallConnector_LifeTime_Parse_json)
Number:Time                 G_Tesla_WallConnector_Lifetime_charging_time_s            "charging_time_s"                            (gWallConnector_LifeTime_Parse_json)

//Items parsed from http://192.168.X.XX/api/1/version
String                      G_Tesla_WallConnector_Version_firmware_version            "firmware_version"                           (gWallConnector_Version_Parse_json)
String                      G_Tesla_WallConnector_Version_part_number                 "part_number"                                (gWallConnector_Version_Parse_json)
String                      G_Tesla_WallConnector_Version_serial_number               "serial_number"                              (gWallConnector_Version_Parse_json)

Tesla.rules

val String filename = "Tesla.rules"
rule "Retrieve JSON Values from API"
when
    Time cron "0/30 * * * * ?"
then
    //val String apiURL = sendHttpGetRequest("http://192.168.X.XX/api/1/vitals")
G_Tesla_WallConnector_Vitals_JSON.sendCommand(sendHttpGetRequest("http://192.168.X.XX/api/1/vitals"))
G_Tesla_WallConnector_LifeTime_JSON.sendCommand(sendHttpGetRequest("http://192.168.X.XX/api/1/lifetime"))
G_Tesla_WallConnector_Version_JSON.sendCommand(sendHttpGetRequest("http://192.168.X.XX/api/1/version"))
end

rule "Tesla WallCharger: Parse JSON output for /vitals"
when
   Item G_Tesla_WallConnector_Vitals_JSON changed
then
logInfo(filename+".R1", "### Tesla WallCharger: Parse JSON output for /vitals ###")

{
   val String json = (G_Tesla_WallConnector_Vitals_JSON.state as StringType).toString
   gWallConnector_Vitals_Parse_json.members.forEach [ value |
      var String name = value.name.replace('G_Tesla_WallConnector_Vitals_','$.')
      value.postUpdate(transform("JSONPATH", name, json).replaceAll('"',''))
   ]
}
end

rule "Tesla WallCharger: Parse JSON output for /lifetime"
when
   Item G_Tesla_WallConnector_LifeTime_JSON changed
then
logInfo(filename+".R2", "### Tesla WallCharger: Parse JSON output for /lifetime ###")
{
   val String json = (G_Tesla_WallConnector_LifeTime_JSON.state as StringType).toString
   gWallConnector_LifeTime_Parse_json.members.forEach [ value |
      var String name = value.name.replace('G_Tesla_WallConnector_Lifetime_','$.')
      value.postUpdate(transform("JSONPATH", name, json).replaceAll('"',''))
   ]
}
end

rule "Tesla WallCharger: Parse JSON output for /version"
when
   Item G_Tesla_WallConnector_Version_JSON changed
then
logInfo(filename+".R3", "### Tesla WallCharger: Parse JSON output for /version ###")
{
   val String json = (G_Tesla_WallConnector_Version_JSON.state as StringType).toString
   gWallConnector_Version_Parse_json.members.forEach [ value |
      var String name = value.name.replace('G_Tesla_WallConnector_Version_','$.')
      value.postUpdate(transform("JSONPATH", name, json).replaceAll('"',''))
   ]
}

end

1 Like