Add support for Tesla Powerwall

Hello everybody. I’m new to HO, so sorry if I have some stupid questions :wink:

I also added my Powerwall 2 into HO a few days ago. It also worked nearly 24 hours and I recorded data from 2021-02-07 20:38 until 2021-02-08 19:28. After that, no new data was recorded. Trying to play around with the integration did not help so I tried to remove and again add it. When I try to add it again, I get only the error “Unknown Error” after entering the IP address.

grafik

In addition, after trying to add the Tesla Powerwall integration, I get the following error in the log

Core Log
2021-02-10 19:59:08 ERROR (MainThread) [homeassistant.components.powerwall.config_flow] Unexpected exception
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/powerwall/config_flow.py", line 64, in async_step_user
    info = await validate_input(self.hass, user_input)
  File "/usr/src/homeassistant/homeassistant/components/powerwall/config_flow.py", line 27, in validate_input
    site_info = await hass.async_add_executor_job(power_wall.get_site_info)
  File "/usr/local/lib/python3.8/concurrent/futures/thread.py", line 57, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/local/lib/python3.8/site-packages/tesla_powerwall/__init__.py", line 112, in get_site_info
    return SiteInfo(self._api.get_site_info())
  File "/usr/local/lib/python3.8/site-packages/tesla_powerwall/api.py", line 224, in get_site_info
    return self.get("site_info")
  File "/usr/local/lib/python3.8/site-packages/tesla_powerwall/api.py", line 103, in get
    return self._process_response(response)
  File "/usr/local/lib/python3.8/site-packages/tesla_powerwall/api.py", line 62, in _process_response
    raise AccessDeniedError(
tesla_powerwall.error.AccessDeniedError: Access denied for resource /api/site_info: Unable to GET to resource

Here is the content of various api sites of the Powerwall, I can access via the browser. Apparently, I’m running version 20.49.0. When trying to access any of the pages without logging in, I get a 403 error.

/api/site_info
  "max_system_energy_kWh": 0,
  "max_system_power_kW": 0,
  "site_name": "MY_NAME",
  "timezone": "Europe/Berlin",
  "max_site_meter_power_kW": 1000000000,
  "min_site_meter_power_kW": -1000000000,
  "nominal_system_energy_kWh": 27,
  "nominal_system_power_kW": 10,
  "grid_code": {
    "grid_code": "50Hz_230V_1_VDE4105_2018_Germany",
    "grid_voltage_setting": 230,
    "grid_freq_setting": 50,
    "grid_phase_setting": "Single",
    "country": "Germany",
    "state": "*",
    "distributor": "*",
    "utility": "*",
    "retailer": "*",
    "region": "VDE4105:2018"
/api/meters/site
[
  {
    "id": 0,
    "location": "site",
    "type": "neurio_mb",
    "cts": [
      true,
      true,
      true,
      false
    ],
    "inverted": [
      false,
      false,
      false,
      false
    ],
    "connection": {
      "serial_port": "/dev/ttymxc1",
      "baud": 115200,
      "modbus_id": 1,
      "short_id": "Tesla-0.0.7(2)",
      "device_serial": "0x000004714B017A8B",
      "neurio_connected": true,
      "disable_echo": true,
      "https_conf": {}
    },
    "real_power_scale_factor": 1,
    "Cached_readings": {
      "last_communication_time": "2021-02-10T19:34:14.290213152+01:00",
      "instant_power": 379.5035629272461,
      "instant_reactive_power": -855.8155517578125,
      "instant_apparent_power": 936.1854586058273,
      "frequency": 49.99971389770508,
      "energy_exported": 3204976.4024683805,
      "energy_imported": 1264833.5805239363,
      "instant_average_voltage": 234.78902689615884,
      "instant_total_current": 0,
      "i_a_current": 0,
      "i_b_current": 0,
      "i_c_current": 0,
      "v_l1n": 234.21629333496094,
      "v_l2n": 234.25747680664062,
      "v_l3n": 235.893310546875,
      "last_phase_voltage_communication_time": "2021-02-10T19:34:14.290204485+01:00",
      "real_power_a": 224.6822052001953,
      "real_power_b": 80.3097152709961,
      "real_power_c": 74.51164245605469,
      "reactive_power_a": -340.9933166503906,
      "reactive_power_b": -284.2757568359375,
      "reactive_power_c": -230.54647827148438,
      "last_phase_power_communication_time": "0001-01-01T00:00:00Z",
      "energy_exported_a": 1761675.663888889,
      "energy_exported_b": 1136651.7466666666,
      "energy_exported_c": 1907697.838611111,
      "energy_imported_a": 982981.7441666666,
      "energy_imported_b": 1684993.8566666667,
      "energy_imported_c": 197906.85861111112,
      "serial_number": "0x000004714B017A8B",
      "version": "Tesla-0.0.7(2)",
      "timeout": 1500000000
    }
  }
]
/api/meters/aggregates
{
  "site": {
    "last_communication_time": "2021-02-10T19:35:41.790690217+01:00",
    "instant_power": 374.6804389953613,
    "instant_reactive_power": -838.6568603515625,
    "instant_apparent_power": 918.5481809793631,
    "frequency": 49.99971389770508,
    "energy_exported": 3204976.4024683805,
    "energy_imported": 1264842.5433017144,
    "instant_average_voltage": 234.4982706705729,
    "instant_total_current": 0,
    "i_a_current": 0,
    "i_b_current": 0,
    "i_c_current": 0,
    "last_phase_voltage_communication_time": "0001-01-01T00:00:00Z",
    "last_phase_power_communication_time": "0001-01-01T00:00:00Z",
    "timeout": 1500000000
  },
  "battery": {
    "last_communication_time": "2021-02-10T19:35:41.790144887+01:00",
    "instant_power": -60,
    "instant_reactive_power": 10,
    "instant_apparent_power": 60.8276253029822,
    "frequency": 49.994,
    "energy_exported": 932880,
    "energy_imported": 1186530,
    "instant_average_voltage": 233.75,
    "instant_total_current": -0.1,
    "i_a_current": 0,
    "i_b_current": 0,
    "i_c_current": 0,
    "last_phase_voltage_communication_time": "0001-01-01T00:00:00Z",
    "last_phase_power_communication_time": "0001-01-01T00:00:00Z",
    "timeout": 1500000000
  },
  "load": {
    "last_communication_time": "2021-02-10T19:35:41.789851555+01:00",
    "instant_power": 325.2219996409865,
    "instant_reactive_power": -787.4931194493327,
    "instant_apparent_power": 852.0063158395733,
    "frequency": 49.99971389770508,
    "energy_exported": 0,
    "energy_imported": 3981514.2811111123,
    "instant_average_voltage": 234.4982706705729,
    "instant_total_current": 1.3868844265289435,
    "i_a_current": 0,
    "i_b_current": 0,
    "i_c_current": 0,
    "last_phase_voltage_communication_time": "0001-01-01T00:00:00Z",
    "last_phase_power_communication_time": "0001-01-01T00:00:00Z",
    "timeout": 1500000000
  },
  "solar": {
    "last_communication_time": "2021-02-10T19:35:41.789851555+01:00",
    "instant_power": 10.264152646064758,
    "instant_reactive_power": 44.61656951904297,
    "instant_apparent_power": 45.78199542603306,
    "frequency": 49.99971389770508,
    "energy_exported": 6175404.397503827,
    "energy_imported": 106.25722604848852,
    "instant_average_voltage": 234.61654154459634,
    "instant_total_current": 0,
    "i_a_current": 0,
    "i_b_current": 0,
    "i_c_current": 0,
    "last_phase_voltage_communication_time": "0001-01-01T00:00:00Z",
    "last_phase_power_communication_time": "0001-01-01T00:00:00Z",
    "timeout": 1500000000
  }
}
/api/status
{
  "start_time": "2021-02-08 19:37:02 +0800",
  "up_time_seconds": "48h0m2.672586969s",
  "is_new": false,
  "version": "20.49.0",
  "git_hash": "42eb71218f889a3aa3635b7b57cffe1de76b7438",
  "commission_count": 0,
  "device_type": "hec",
  "sync_type": "v1"
}

I would like to test the reworked code from your post by putting it into the init.py. But I cannot find the folder /usr/local/lib/python3.8/concurrent/futures/ nor usr/src/homeassistant/homeassistant/components/powerwall/. Maybe because I removed the integration before?

How could I get this working so I could test this on my site as well?