-
Notifications
You must be signed in to change notification settings - Fork 99
Teslamate MQTT Integration
The Tesla Streaming API is very peculiar. It has limitations such as only allowing one client at a time and improper management could lead to the vehicle not going to sleep.
However, having a streaming connection to Home Assistant could be very beneficial, especially for location data. Real Time location updates could allow Home Assistant to perform functions like opening your garage door when your car is parked in your driveway.
To balance this, the Tesla integration for Home Assistant has added support to update its entities via MQTT updates from TeslaMate - thus gaining the benefit of real-time information, while 'outsourcing' the harder challenge of maintaining the streaming API to TeslaMate.
Currently, the following values can be updated via MQTT
- latitude
- longitude
- shift_state
- speed
- heading
- is_climate_on
- inside_temp
- outside_temp
- tpms_pressure_fl
- tpms_pressure_fr
- tpms_pressure_rl
- tpms_pressure_rr
- locked
- sentry_mode
- odometer
- battery_level
- usable_battery_level
- charge_energy_added
- charger_actual_current
- charger_power
- charger_voltage
- time_to_full_charge
- charge_limit_soc
- A running instance of TeslaMate
- A MQTT Broker (the Mosquitto Add-on for Home Assistant is recommended)
- The MQTT integration enabled in Home Assistant and configured with your MQTT broker.
This Assumes you already have a working instance of TeslaMate.
Update the MQTT env variables so that TeslaMate publishes to the same MQTT broker you have configured in Home Assistant. Note, the MQTT_NAMESPACE
configuration is not supported by the Tesla component.
For advanced users, you could use the bundled version MQTT broker of TeslaMate, then set up a MQTT bridge to connect the 2 brokers (similar to the Hisense TV configuration), but that is not covered here.
You need to determine your Car ID in Tesla Mate.
If you only have one Tesla, your car ID will be 1
.
If you have multiple Tesla's configured in TeslaMate, you can do the following to determine the CarID of each car.
- In Home Assistant, Navigate to Settings > Devices & Services
- Click "Configure" for the MQTT integration
- Enter
teslamate/cars/#
into the Listen to a Topic - Click "Start Listening"
If the TeslaMate MQTT integration has been been configured correctly, you should see messages received on topics teslamate/cars/<car ID>/<data category>
There is an entry for the odometer, teslamate/cars/<car ID>/odometer
. Use this to match up each car to its Car ID.
- In Home Assistant, Navigate to Settings > Devices & Services
- Click "Configure" for the Tesla Custom integration
- Check "Sync Data from TeslaMate via MQTT"
- Click "Submit"
- Navigate to your Tesla Car Device
- Under "Configuration", Enable the
Teslamate id
entity. - Wait for 30 seconds, then refresh the page
- Enter your TeslaMate ID for the Car you are currently viewing (again, most likely this will be
1
)- You may need to enable the entity when you set the value.
- Sample entity for a car named "Onyx" would be
text.onyx_teslamate_id
- Click out of the Text Box so Home Assistant saves the new value.
You can confirm the configuration is working by enabling Debug Logs for the Tesla Custom integration. You will see log entries about updating entities from MQTT in the Tesla Logs in Home Assistant.
To standardize the data, Teslamate values are converted to imperial before being saved into the integration, since Tesla's API returns imperial units.
If you'd like to display attributes in metric units, the easiest way is to add new sensor templates with the conversion. The following is an example for speed:
- sensor:
- name: "Tesla Speed"
device_class: speed
unit_of_measurement: "km/h"
state: >
{% if state_attr('device_tracker.thunderfury_location_tracker', 'speed') == None %}
0
{% else %}
{{ (state_attr('device_tracker.thunderfury_location_tracker', 'speed') | float * 1.609) | round }}
{% endif %}
This will create a sensor sensor.tesla_speed
displaying speed in km/h