tesla-local-control / tesla-local-control-addon

Control your Tesla locally from HomeAssistant
Apache License 2.0
21 stars 2 forks source link

Error: context deadline exceeded #104

Closed aaserali closed 1 day ago

aaserali commented 1 month ago

I’m intermittently receiving this error when sending commands to my two cars. It retries 5 times, and it sometimes successful on a retry. Any thoughts on how to resolve this?

`[00:18:57] INFO: Received MQTT message; topic:tesla_ble/[redacted]/charging-set-amps msg:28 vin: [redacted] cmd:charging-set-amps

[00:18:57] NOTICE: Attempt 1/5 sending Set charging Amps to 28 to vin: [redacted] command:charging-set-amps 28

[00:19:17] ERROR: tesla-control send command:charging-set-amps 28 to vin: [redacted] failed exit status 1.

[00:19:17] ERROR: teslaCtrlSendCommand; Error: context deadline exceeded

[00:19:17] NOTICE: teslaCtrlSendCommand; Retrying in 5 seconds

[00:19:22] NOTICE: Attempt 2/5 sending Set charging Amps to 28 to vin: [redacted] command:charging-set-amps 28

[00:19:43] ERROR: tesla-control send command:charging-set-amps 28 to vin: [redacted] failed exit status 1.

[00:19:43] ERROR: teslaCtrlSendCommand; 2024/08/09 00:19:42 can't accept: listner timed out Error: context deadline exceeded

[00:19:43] NOTICE: teslaCtrlSendCommand; Retrying in 5 seconds

[00:19:48] NOTICE: Attempt 3/5 sending Set charging Amps to 28 to vin:[redacted] command:charging-set-amps 28

[00:20:08] ERROR: tesla-control send command:charging-set-amps 28 to vin: [redacted] failed exit status 1.

[00:20:08] ERROR: teslaCtrlSendCommand; Error: context deadline exceeded

[00:20:08] NOTICE: teslaCtrlSendCommand; Retrying in 5 seconds

[00:20:13] NOTICE: Attempt 4/5 sending Set charging Amps to 28 to vin: [redacted] command:charging-set-amps 28

[00:20:29] INFO: Command charging-set-amps 28 was successfully delivered to vin: [redacted] `

iainbullock commented 1 month ago

How far away is the Bluetooth adapter from the car(s)? Being closer improves the reliability of the connection. Mine is very close maybe 2 metres away and works well, though I do see this error sometimes.

aaserali commented 1 month ago

Mine is definitely farther away. Maybe 10 meters. The presence detection seems to be working correctly 100% so I assumed it was close enough to form a reliable connection, but I’ll try to move my Bluetooth adapter into the garage to see if that helps when sending commands.

iainbullock commented 1 month ago

Let us know how you get on. Presence detection is much less sensitive to distance than sending commands

aaserali commented 1 month ago

I have brought the Bluetooth adapter within 2 meters of my cars and I'm still running into errors. I am receiving both

[09:41:50] ERROR: teslaCtrlSendCommand; Error: ble: failed to enumerate device services: ATT request failed: input channel closed: io: read/write on closed pipe

and

[09:43:50] ERROR: teslaCtrlSendCommand; Error: context deadline exceeded

Any other thoughts? I am trying to optimize my solar generation to charge my car and after the API changes, I was hoping to use BLE to send charging commands.

aaserali commented 1 month ago

For reference, I am using a Raspberry Pi 4 Model B with the most recent HAOS.

iainbullock commented 1 month ago

Are you getting these errors all the time or just occasionally. Occasionally is normal. Other thoughts: is the car awake as it must be woken before other commands can be sent; are there any other processes using BT adapter? Eg HA Bluetooth presence detection; is the Pi using 2.4GHz WiFi (not sure if this is an issue some say it is)

@raphmur I think you have a similar hardware but no issues. Any thoughts?

aaserali commented 1 month ago

The cars are awake during my testing.

At first, the errors occurred about 50% of the time. Now they are occurring about 90+% of the time.

I don’t have any other integrations using Bluetooth as far as I know

But I think I’ve found some more information in my Home Assistant Core logs. It seems there is an error with the Bluetooth adapter in my Pi. I’ve tried troubleshooting this without success. I think I’m going to reinstall HAOS tomorrow to see if I can get it to work.

AssertionError 2024-08-09 23:29:02.412 WARNING (MainThread) [bluetooth_auto_recovery.recover] Closing Bluetooth adapter hci0 [DC:A6:32:AF:A2:23] failed: [Errno 9] Bad file descriptor 2024-08-09 23:30:55.894 ERROR (MainThread) [habluetooth.scanner] hci0 (DC:A6:32:AF:A2:23): Error stopping scanner: [org.bluez.Error.Failed] No discovery started

This is strange to me because the Tesla Local Commands detects the presence of my cars’ BLE but the logs imply that the Pi’s Bluetooth adapter is deactivated

iainbullock commented 1 month ago

My experience is more with the docker version of the project rather than HAOS / add-on version. Not sure it makes a difference unless something in HA is causing an additional issue. The other devs (@raphmur @baylanger) are away at the moment but may well comment on their return

aaserali commented 1 month ago

I appreciate your help. I have a feeling that HAOS is causing the Bluetooth issues. Which OS are you running the docker version? I have some extra Pi’s in storage that I can grab and run the docker version on a different OS

iainbullock commented 1 month ago

I'm running Raspberry Pi OS on a RPi3b+. Use a Pi with built in BLE, rather than a third party USB if you can. I originally used a RPi1b with Chinese dongle and it wasn't reliable. The 3b+ has been great (albeit for 1 car)

Raspberry Pi OS Lite Release date: July 4th 2024 System: 64-bit Kernel version: 6.6 Debian version: 12 (bookworm)

raphmur commented 1 month ago

Hi there @aaserali I have the same hardware and I am about as far as you from the car. (The iBeacons integration reports 10-12meters). Proximity detection is always working well.

From time to time I have seen these issues, that started to increase frequency when the temperature in my garage incresed (hot wave in june / july).

You can try active cooling of the RPi board. You can try a kit like this with a fan. It improved the overall Pi temperature and most probably also the wifi/ble chip temperature. I used a passively cooled case before and the wifi/ble chip was not cooled and got very hot.

Screenshot_20240810_090813_Amazon Shopping.jpg

Please read this issue where I tried to document a bit #27

darek-margas commented 1 month ago

I wonder if there is anything what could be loaded into ESP32 and use BLE to control Telsa while integrating via MQTT.

iainbullock commented 1 month ago

I don't have experience of ESP32. Maybe I should get one and give it a try (but I haven't got time being realistic). Maybe the docker vesrion of this project would work?

aaserali commented 1 month ago

I reinstalled HAOS without any success. However, I installed the Docker version on a Raspberry Pi 4 Model B and things seem to be working great. This Pi is about 10 meters from one of the cars and I'm running into errors ~10% of the time. But if there is an error, the command will generally succeed on a retry. I haven't deployed the new key on the second car but will plan to do that tomorrow and hope for similar success.

Now once I get my Shelly energy meters wired up, I should be able to maximize my charging on solar. Thank you!

iainbullock commented 1 month ago

Good to hear thanks for the update.

10 metres is probably close to the limit in terms of distance but maybe it will be good enough. Having said that I get some errors even at 2 metres away

aaserali commented 2 weeks ago

I went on vacation, came back and started having issues with the Docker version again:

Error: failed to find BLE beacon

Error: context deadline exceeded

Error: ble: failed to enumerate device services: ATT request failed: input channel closed: io: read/write on closed pipe

Error: failed to find BLE beacon for XXX (XXX): can't dial: can't dial: connection canceled

After some troubleshooting, this is reproduced when I have 3 iPhone BLE keys active near the Teslas. If I turn off the Bluetooth on one of these three iPhones, the errors stop immediately.

I'm not sure if this is a Tesla limitation (perhaps a maximum of 3 BLE connections at any given time is allowed) but I just wanted to put this out there in case anyone else is having similar issues.

raphmur commented 1 week ago

Hi @aaserali I have just seen similar behaviour recently. Indeed having too many paired phones nearby might cause issues... Will look into this

raphmur commented 3 days ago

Hi @aaserali , the "context deadline exceeded" issue should be solved using autowake:

image

For the rest on "maximum number of BLE devices", eventually it works after few retries (as above)

raphmur commented 1 day ago

Version 0.2.2 has been released, including the autowake feature. The issue with "max number of devices" still exist, but it did not cause major crashes for me.

https://github.com/tesla-local-control/tesla-local-control-addon/releases/tag/v0.2.2