I've wanted to pull some basic information from my Tesla, but the primary API is polling-heavy and not really something I wanted running on my hub. The WebSocket API is complex to implement and I've done almost nothing in Groovy prior, so I didn't really want to go down that road again. Plus you can only have one WebSocket client active at a time, and that position is already occupied for me by running TeslaMate.
But wait! TeslaMate exposes a fairly rich MQTT surface, which I'm already consuming in another project, MMM-Powerwall. Hubitat has an MQTT client in-box. Thus was a potential match and solution made.
This is now available from HPM.
What you need:
- One or more Tesla vehicles on your Tesla account; nothing to do otherwise!
- A working install of TeslaMate, with the MQTT server reachable from the Hubitat
- Install these two drivers on your Hubitat, or search for TeslaMate in HPM
- Configure a new virtual device with the TeslaMate driver and point it to your MQTT server
It will pick up the vehicle(s) TeslaMate is issuing data about and create the child devices using the other driver, including renaming the child device whenever the vehicle's display name is published. The MQTT events can be very chatty, especially while driving or charging, so I took a note from OWM-Alerts: the behaviors are grouped into clusters of related information, and you only subscribe to the clusters you need. (I've entirely dropped a few properties I don't think anyone needs to automate, but if you need to trigger some action based on when your car color changes, they're easy to add back.)
It's my first Hubitat driver, and it was a big chunk to bite off. I drew heavily on a couple of other drivers for inspiration and reference:
- MQTT Link Driver by @jeubanks, GitHub - mydevbox/hubitat-mqtt-link
- Hubitat Parent/Child Examples by @mike.maxwell, GitHub - hubitat/HubitatPublic
- OpenWeatherMap-Alerts-Weather-Driver by @Matthew, OpenWeatherMap-Alerts-Weather-Driver
Important to note that because this is purely an MQTT consumer, it can't change anything about the car, only display it. Even though it has the Lock/Unlock commands, all those will do is log a warning that you can't do that.
Happy to engage here or on GitHub. Let me know what I missed, or even where my code could be neater.