From 7088ef2521f046c89d918a51626e7f2b91da530d Mon Sep 17 00:00:00 2001 From: herrfrei Date: Fri, 4 Oct 2024 11:10:28 +0200 Subject: [PATCH 1/2] Added action to switch sentry mode on/off --- components/tesla_ble_vehicle/tesla_ble_vehicle.cpp | 7 +++++++ components/tesla_ble_vehicle/tesla_ble_vehicle.h | 3 ++- packages/client.yml | 10 ++++++++++ 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/components/tesla_ble_vehicle/tesla_ble_vehicle.cpp b/components/tesla_ble_vehicle/tesla_ble_vehicle.cpp index 6eada09..7fa09a4 100644 --- a/components/tesla_ble_vehicle/tesla_ble_vehicle.cpp +++ b/components/tesla_ble_vehicle/tesla_ble_vehicle.cpp @@ -1224,6 +1224,9 @@ namespace esphome std::string action_str; switch (action) { + case SET_SENTRY_SWITCH: + action_str = "setSentrySwitch"; + break; case SET_CHARGING_SWITCH: action_str = "setChargingSwitch"; break; @@ -1247,6 +1250,10 @@ namespace esphome ESP_LOGI(TAG, "[%s] Building message..", action_str.c_str()); switch (action) { + case SET_SENTRY_SWITCH: + return_code = tesla_ble_client_->buildSentrySwitchMessage( + static_cast(param), message_buffer, &message_length); + break; case SET_CHARGING_SWITCH: return_code = tesla_ble_client_->buildChargingSwitchMessage( static_cast(param), message_buffer, &message_length); diff --git a/components/tesla_ble_vehicle/tesla_ble_vehicle.h b/components/tesla_ble_vehicle/tesla_ble_vehicle.h index 54fc459..09974df 100644 --- a/components/tesla_ble_vehicle/tesla_ble_vehicle.h +++ b/components/tesla_ble_vehicle/tesla_ble_vehicle.h @@ -29,7 +29,8 @@ typedef enum BLE_CarServer_VehicleAction_E { SET_CHARGING_SWITCH, SET_CHARGING_AMPS, - SET_CHARGING_LIMIT + SET_CHARGING_LIMIT, + SET_SENTRY_SWITCH } BLE_CarServer_VehicleAction; namespace esphome diff --git a/packages/client.yml b/packages/client.yml index b64c2a5..2ddeaa5 100644 --- a/packages/client.yml +++ b/packages/client.yml @@ -71,6 +71,16 @@ switch: turn_off_action: - lambda: id(tesla_ble_vehicle_id)->sendCarServerVehicleActionMessage(SET_CHARGING_SWITCH, 0); + - platform: template + name: "Sentry switch" + optimistic: true + assumed_state: false # we can't read the state + restore_mode: RESTORE_DEFAULT_OFF + turn_on_action: + - lambda: id(tesla_ble_vehicle_id)->sendCarServerVehicleActionMessage(SET_SENTRY_SWITCH, 1); + turn_off_action: + - lambda: id(tesla_ble_vehicle_id)->sendCarServerVehicleActionMessage(SET_SENTRY_SWITCH, 0); + - platform: ble_client ble_client_id: ble_tesla_id name: "BLE Connection" From b1b04b6e0e2a4222a10b8b5127520a7656d1ebc8 Mon Sep 17 00:00:00 2001 From: herrfrei Date: Sun, 6 Oct 2024 07:55:02 +0200 Subject: [PATCH 2/2] Changed restore_mode for sentry switch --- packages/client.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/client.yml b/packages/client.yml index 2ddeaa5..ed738f8 100644 --- a/packages/client.yml +++ b/packages/client.yml @@ -74,7 +74,7 @@ switch: - platform: template name: "Sentry switch" optimistic: true - assumed_state: false # we can't read the state + assumed_state: true # we can't read the state restore_mode: RESTORE_DEFAULT_OFF turn_on_action: - lambda: id(tesla_ble_vehicle_id)->sendCarServerVehicleActionMessage(SET_SENTRY_SWITCH, 1);