Commit 345ee52
feat(mqtt): add opt-in Home Assistant MQTT discovery (#5543)
* feat(mqtt): add opt-in Home Assistant MQTT discovery
Add an MQTT_HOME_ASSISTANT_DISCOVERY env var that, when enabled, makes
VehicleSubscriber publish HA discovery config payloads (one per entity)
to homeassistant/<component>/teslamate_<car_id>/<object_id>/config on
startup, mirroring the manual configuration documented in
website/docs/integrations/home_assistant.md.
* docs: fix malformed environment variables table
Fix the header separator row, which gained an extra column, and the MQTT_HOME_ASSISTANT_DISCOVERY_PREFIX row, which had a trailing empty cell. Addresses review comment on #5543.
* docs: reword MQTT_HOME_ASSISTANT_DISCOVERY_URL wording
MQTT_HOME_ASSISTANT_DISCOVERY_URL is optional; clarify that setting MQTT_HOME_ASSISTANT_DISCOVERY does not require it. Addresses review comment on #5543.
* feat(mqtt): validate MQTT_HOME_ASSISTANT_DISCOVERY_PREFIX
Validate the discovery prefix like MQTT_NAMESPACE: empty values fall back to the default so topics never get a leading '/', and MQTT wildcards are rejected. Addresses review comment on #5543.
* feat(mqtt): clear Home Assistant discovery configs on disable
Call HomeAssistant.clear/3 so retained discovery configs (and the entities in Home Assistant) are removed when discovery is disabled. Addresses review comment on #5543.
* feat(mqtt): clear Home Assistant discovery configs for removed vehicles on startup
* feat(mqtt): make discovery entity IDs match the manual mqtt_sensors.yaml
Prefix the discovery object_id with tesla_ so Home Assistant generates the same
entity IDs as the documented manual configuration (e.g. sensor.tesla_speed
instead of sensor.speed), avoiding broken dashboards and automations on
migration. Drop the _km suffix from the battery range sensors to match the
manual unique_ids. Document that the manual mqtt_sensors.yaml must be removed
before enabling discovery to avoid duplicate unique_id errors. Addresses review
comment on #5543.
* fix(mqtt): use state_class total_increasing for charge_energy_added discovery entity
* feat(mqtt): add charging_state discovery entity
* test(mqtt): use plain ExUnit.Case in home_assistant_test
* feat(mqtt): scope discovery topics and unique_ids by MQTT namespace
* feat(vehicles): add Summary type definition
* docs(mqtt): simplify discovered entities note
* feat(nix): add Home Assistant MQTT discovery options
* fix(mqtt): scope startup discovery cleanup by MQTT namespace
Pass the namespace to HomeAssistant.clear/3 in clear_removed_vehicles/2 so a namespaced instance clears its own discovery topics instead of the un-namespaced ones of a sibling instance sharing the broker.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
* refactor(test): extract shared drain_discovery_configs helper
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
* docs(mqtt): explain startup discovery cleanup timing
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
* feat(mqtt): reject MQTT wildcards in MQTT_NAMESPACE
Align with validate_discovery_prefix!: a namespace containing + or # would produce unpublishable state and discovery topics, so fail fast at boot.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
* docs: update changelog
---------
Co-authored-by: Jakob Lichterfeld <jakob-lichterfeld@gmx.de>
Co-authored-by: Claude Fable 5 <noreply@anthropic.com>1 parent 2c99541 commit 345ee52
16 files changed
Lines changed: 1312 additions & 65 deletions
File tree
- config
- lib/teslamate
- mqtt
- pubsub
- vehicles/vehicle
- nix
- test
- support
- teslamate
- mqtt/pubsub
- vehicles
- website/docs
- configuration
- installation
- integrations
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
7 | 11 | | |
8 | 12 | | |
9 | 13 | | |
| |||
14 | 18 | | |
15 | 19 | | |
16 | 20 | | |
| 21 | + | |
17 | 22 | | |
18 | 23 | | |
19 | 24 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
15 | | - | |
16 | | - | |
17 | | - | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
18 | 29 | | |
19 | 30 | | |
20 | 31 | | |
| |||
181 | 192 | | |
182 | 193 | | |
183 | 194 | | |
184 | | - | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
185 | 200 | | |
186 | 201 | | |
187 | 202 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
19 | | - | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
20 | 27 | | |
21 | 28 | | |
22 | 29 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
| 4 | + | |
| 5 | + | |
4 | 6 | | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
5 | 10 | | |
| 11 | + | |
6 | 12 | | |
7 | 13 | | |
8 | 14 | | |
| |||
12 | 18 | | |
13 | 19 | | |
14 | 20 | | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
15 | 35 | | |
16 | | - | |
17 | | - | |
| 36 | + | |
| 37 | + | |
18 | 38 | | |
19 | 39 | | |
20 | 40 | | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
21 | 65 | | |
0 commit comments