Open chicagoandy opened 1 year ago
We've explored this. Issue is only one application can access the streaming API at a time. This means this may block the official app. HA doesn't need information this often. Also, we're not using a websocket library so we'd have to import another dependency to even handle this. If someone wants to try a PR they can.
Hey Team,
I was thinking about how i can get more-realtime updates on my tesla, specifically its location so I can automate things like opening the garage door when i enter my driveway.
Rather then trying to implement the Websocket API in this Component, Could we make use of MQTT from Teslamate https://docs.teslamate.org/docs/integrations/mqtt/
The idea is that we could subscribe to the MQTT topics from Teslamate, and update the backend data in the _car variable in the TeslaCar class.
I just wanted to table the idea before i write any code. But if writing code and doing a PoC helps get the idea across, let me know
I'd be ok with the PR but you'd have to make it optional. Also, HA natively supports MQTT, so you can already make MQTT sensors to do this. MQTT allows autodiscovery, so you could make it on the Teslamate side without even touching this component. So you may want to consider where it makes sense to do it.
Yeah, so i did have MQTT sensors set up initially,. The TeslaMate docs even specically call this out https://docs.teslamate.org/docs/integrations/home_assistant
But it means every "Value" is duplicated. Once from the MQTT sensor, and once from this integration.
Ideally, I'd still have 1 entity per value, and that entity just always has the latest info from either this components own refresh cycle, or from the MQTT publish.
And yeah, I'd make it optional in the configFlow options.
I'll work on a PR and see how far I get. It will be a bit gross, because i'd have to update variables that are "owned" by teslajsonpy, OR, do a bit of an overhaul on the Car data storage. I'll see where I end up.
Early days, not prod ready. But gives you an idea of how i expected the connection to work.
https://github.com/Megabytemb/tesla/tree/teslamate
it backs of the home assistant MQTT integration. I've yet to add logic that ignores everything if you don't have the mqtt integration configured.
view pull request here
Alright, @alandtse has been awesome and merged my code into Dev.
You can try out the new connection by following this guide!
https://github.com/alandtse/tesla/wiki/Teslamate-MQTT-Intergration
Please let me know if you run into any issues or have feature requests.
Currently data-updates while driving appear to be limited to a 60-second refresh timeout. There is a streaming API that is available while the vehicle is in motion, this will give near-real-time updates to the following: speed,odometer, soc, elevation, est_heading est_lat, est_lng, power, shift_state, range, est_range, heading
A reference implementation of this is available (via TeslaMate, in Ruby). https://github.com/adriankumpf/teslamate/commit/a691784926eed4c6ac08b98b2d8c60f1b7950d89#diff-9f70483b27cf0755e732038378b0d7682e404eca39594eddd76036c3b0d7a772
Note this appears to mirror the approach taken by the official Tesla app.