Tesla Powerwall Integration Grid Services Sensor

Add a binary sensor to the existing Tesla Powerwall integration to show if Grid Services is currently active.

With Tesla rolling out firmware updates that now need authentication when calling the api it prompted me to finally migrate from RESTful sensors to the Powerwall integration.
The integration covers all of the RESTful sensors I previously used except for Grid Services:

binary_sensor:
  - platform: rest
    resource: https://10.0.99.40/api/system_status/grid_status
    verify_ssl: false
    method: GET
    name: Grid Services
    scan_interval: 60
    value_template: "{{ value_json.grid_services_active == true }}"  

There are a few additional endpoints that would be useful to include in the Tesla integration.

Grid Services is one.

{
  "grid_status": "SystemGridConnected",
  "grid_services_active": false
}

{
  "grid_status": "SystemGridConnected",
  "grid_services_active": true
}

The other end points I would be interested in from the localAPI include:

For access to real_mode (operation):

https://192.168.86.123/api/operation
{
  "real_mode": "self_consumption",
  "backup_reserve_percent": 84.8
}

For access to three phase power readings (site & solar):

https://192.168.86.123/api/meters/site
[
  {
    "id": 0,
    "location": "site",
    "type": "synchrometerX",
    "cts": [
      true,
      true,
      true,
      false
    ],
    "inverted": [
      false,
      false,
      false,
      false
    ],
    "connection": {
      "short_id": "XXX",
      "device_serial": "XXX",
      "https_conf": {}
    },
    "Cached_readings": {
      "last_communication_time": "2023-10-08T16:56:51.360245447+10:00",
      "instant_power": -14305,
      "instant_reactive_power": 1088,
      "instant_apparent_power": 14346.31552002116,
      "frequency": 0,
      "energy_exported": 13939207.663568825,
      "energy_imported": 14119276.769605972,
      "instant_average_voltage": 416.6217277499258,
      "instant_average_current": 60.043,
      "i_a_current": 17.354,
      "i_b_current": 21.912,
      "i_c_current": 20.777,
      "last_phase_voltage_communication_time": "2023-10-08T16:56:51.360332942+10:00",
      "v_l1n": 238.63,
      "v_l2n": 241.59,
      "v_l3n": 241.39000000000001,
      "last_phase_power_communication_time": "2023-10-08T16:56:51.360245447+10:00",
      "real_power_a": -4123,
      "real_power_b": -5216,
      "real_power_c": -4966,
      "reactive_power_a": -86,
      "reactive_power_b": 742,
      "reactive_power_c": 432,
      "last_phase_energy_communication_time": "0001-01-01T00:00:00Z",
      "serial_number": "JBL21257Y4F0DN",
      "version": "fe55682a96e0c6",
      "timeout": 1500000000,
      "instant_total_current": 60.043
    }
  }
]

https://192.168.86.123/api/meters/solar
[
  {
    "id": 0,
    "location": "solar",
    "type": "synchrometerY",
    "cts": [
      true,
      true,
      true,
      false
    ],
    "inverted": [
      false,
      false,
      false,
      false
    ],
    "connection": {
      "short_id": "XXX",
      "device_serial": "XXX",
      "https_conf": {}
    },
    "real_power_scale_factor": 1,
    "ct_voltage_references": {
      "ct1": "Phase1",
      "ct2": "Phase2",
      "ct3": "Phase3"
    },
    "Cached_readings": {
      "last_communication_time": "2023-10-08T16:57:56.931565207+10:00",
      "instant_power": 275,
      "instant_reactive_power": 575,
      "instant_apparent_power": 637.3774391990981,
      "frequency": 0,
      "energy_exported": 89661.39227781232,
      "energy_imported": 38271036.02136998,
      "instant_average_voltage": 416.1713945399579,
      "instant_average_current": 2.997,
      "i_a_current": 0.9785,
      "i_b_current": 1.032,
      "i_c_current": 0.9865,
      "last_phase_voltage_communication_time": "2023-10-08T16:57:56.831077425+10:00",
      "v_l1n": 238.4,
      "v_l2n": 240.72,
      "v_l3n": 241.69,
      "last_phase_power_communication_time": "2023-10-08T16:57:56.931565207+10:00",
      "real_power_a": 95,
      "real_power_b": 107,
      "real_power_c": 73,
      "reactive_power_a": 183,
      "reactive_power_b": 195,
      "reactive_power_c": 197,
      "last_phase_energy_communication_time": "0001-01-01T00:00:00Z",
      "serial_number": "JBL21257Y4F0DN",
      "version": "fe55682a96e0c6",
      "timeout": 1500000000,
      "instant_total_current": 2.997
    }
  }
]

System Status provides information on batteries and inverters. (nominal_full_pack_energy is useful for monitoring degradation over time

https://192.168.86.123/api/system_status

{
  "command_source": "Schedule",
  "battery_target_power": 15000,
  "battery_target_reactive_power": 0,
  "nominal_full_pack_energy": 42122,
  "nominal_energy_remaining": 34801,
  "max_power_energy_remaining": 0,
  "max_power_energy_to_be_charged": 0,
  "max_charge_power": 15000,
  "max_discharge_power": 15000,
  "max_apparent_power": 15000,
  "instantaneous_max_discharge_power": 28040,
  "instantaneous_max_charge_power": 21000,
  "instantaneous_max_apparent_power": 16500,
  "hardware_capability_charge_power": 0,
  "hardware_capability_discharge_power": 0,
  "grid_services_power": -15200.840161901351,
  "system_island_state": "SystemGridConnected",
  "available_blocks": 3,
  "available_charger_blocks": 0,
  "battery_blocks": [
    {
      "Type": "",
      "PackagePartNumber": "3012170-10-B",
      "PackageSerialNumber": "XXX",
      "disabled_reasons": [],
      "pinv_state": "PINV_GridFollowing",
      "pinv_grid_state": "Grid_Compliant",
      "nominal_energy_remaining": 11021,
      "nominal_full_pack_energy": 13359,
      "p_out": 4720,
      "q_out": -420,
      "v_out": 239.70000000000002,
      "f_out": 50.044,
      "i_out": -104,
      "energy_charged": 9129060,
      "energy_discharged": 8144720,
      "off_grid": false,
      "vf_mode": false,
      "wobble_detected": false,
      "charge_power_clamped": false,
      "backup_ready": true,
      "OpSeqState": "Active",
      "version": "63bc46d8c35d6e"
    },
    {
      "Type": "",
      "PackagePartNumber": "3012170-05-C",
      "PackageSerialNumber": "XXX",
      "disabled_reasons": [],
      "pinv_state": "PINV_GridFollowing",
      "pinv_grid_state": "Grid_Compliant",
      "nominal_energy_remaining": 11894,
      "nominal_full_pack_energy": 14392,
      "p_out": 5140,
      "q_out": -1000,
      "v_out": 242.9,
      "f_out": 50.044,
      "i_out": -110.4,
      "energy_charged": 4549260,
      "energy_discharged": 4023610,
      "off_grid": false,
      "vf_mode": false,
      "wobble_detected": false,
      "charge_power_clamped": false,
      "backup_ready": true,
      "OpSeqState": "Active",
      "version": "63bc46d8c35d6e"
    },
    {
      "Type": "",
      "PackagePartNumber": "3012170-05-C",
      "PackageSerialNumber": "XXX",
      "disabled_reasons": [],
      "pinv_state": "PINV_GridFollowing",
      "pinv_grid_state": "Grid_Compliant",
      "nominal_energy_remaining": 11886,
      "nominal_full_pack_energy": 14371,
      "p_out": 5120,
      "q_out": -650,
      "v_out": 240.9,
      "f_out": 50.045,
      "i_out": -110.5,
      "energy_charged": 4547710,
      "energy_discharged": 4015250,
      "off_grid": false,
      "vf_mode": false,
      "wobble_detected": false,
      "charge_power_clamped": false,
      "backup_ready": true,
      "OpSeqState": "Active",
      "version": "63bc46d8c35d6e"
    }
  ],
  "ffr_power_availability_high": 16500,
  "ffr_power_availability_low": 14642,
  "load_charge_constraint": 0,
  "max_sustained_ramp_rate": 3750000,
  "grid_faults": [
    {
      "timestamp": 1694839971658,
      "alert_name": "PINV_a008_vfCheckRocof",
      "alert_is_fault": false,
      "decoded_alert": "[{\"name\":\"PINV_alertID\",\"value\":\"PINV_a008_vfCheckRocof\"},{\"name\":\"PINV_alertType\",\"value\":\"Warning\"}]",
      "alert_raw": {
        "value": "576460752303423488n",
        "type": "Big Number"
      },
      "git_hash": "63bc46d8c35d6e",
      "site_uid": "XXX",
      "ecu_type": "TEPINV",
      "ecu_package_part_number": "1081100-33-V",
      "ecu_package_serial_number": "XXX"
    },
    {
      "timestamp": 1687982031227,
      "alert_name": "PINV_a008_vfCheckRocof",
      "alert_is_fault": false,
      "decoded_alert": "[{\"name\":\"PINV_alertID\",\"value\":\"PINV_a008_vfCheckRocof\"},{\"name\":\"PINV_alertType\",\"value\":\"Warning\"}]",
      "alert_raw": {
        "value": "576460752303423488n",
        "type": "Big Number"
      },
      "git_hash": "63bc46d8c35d6e",
      "site_uid": "XXX",
      "ecu_type": "TEPINV",
      "ecu_package_part_number": "1081100-33-V",
      "ecu_package_serial_number": "XXX"
    },
    {
      "timestamp": 1687883925371,
      "alert_name": "PINV_a004_vfCheckUnderVoltage",
      "alert_is_fault": false,
      "decoded_alert": "[{\"name\":\"PINV_alertID\",\"value\":\"PINV_a004_vfCheckUnderVoltage\"},{\"name\":\"PINV_alertType\",\"value\":\"Warning\"},{\"name\":\"PINV_a004_uv_amplitude\",\"value\":26,\"units\":\"Vrms\"}]",
      "alert_raw": {
        "value": "288258963454033920n",
        "type": "Big Number"
      },
      "git_hash": "63bc46d8c35d6e",
      "site_uid": "XXX",
      "ecu_type": "TEPINV",
      "ecu_package_part_number": "1081100-33-V",
      "ecu_package_serial_number": "XXX"
    },
    {
      "timestamp": 1687636209720,
      "alert_name": "PINV_a008_vfCheckRocof",
      "alert_is_fault": false,
      "decoded_alert": "[{\"name\":\"PINV_alertID\",\"value\":\"PINV_a008_vfCheckRocof\"},{\"name\":\"PINV_alertType\",\"value\":\"Warning\"}]",
      "alert_raw": {
        "value": "576460752303423488n",
        "type": "Big Number"
      },
      "git_hash": "63bc46d8c35d6e",
      "site_uid": "XXX",
      "ecu_type": "TEPINV",
      "ecu_package_part_number": "1081100-33-V",
      "ecu_package_serial_number": "XXX"
    },
    {
      "timestamp": 1687463761970,
      "alert_name": "PINV_a004_vfCheckUnderVoltage",
      "alert_is_fault": false,
      "decoded_alert": "[{\"name\":\"PINV_alertID\",\"value\":\"PINV_a004_vfCheckUnderVoltage\"},{\"name\":\"PINV_alertType\",\"value\":\"Warning\"},{\"name\":\"PINV_a004_uv_amplitude\",\"value\":181,\"units\":\"Vrms\"}]",
      "alert_raw": 288429387756339200,
      "git_hash": "63bc46d8c35d6e",
      "site_uid": "XXX",
      "ecu_type": "TEPINV",
      "ecu_package_part_number": "1081100-33-V",
      "ecu_package_serial_number": "XXX"
    }
  ],
  "can_reboot": "Power flow is too high",
  "smart_inv_delta_p": 0,
  "smart_inv_delta_q": -1740,
  "last_toggle_timestamp": "2023-06-16T15:39:45.481228+10:00",
  "solar_real_power_limit": 1.7976931348623157e+308,
  "score": 10000,
  "blocks_controlled": 3,
  "primary": true,
  "auxiliary_load": 0,
  "all_enable_lines_high": true,
  "inverter_nominal_usable_power": 16500,
  "expected_energy_remaining": 0
}