feat(teslamate_vehicle): read Tesla charge state from TeslaMate MQTT - #139
Conversation
…iver Optional TeslaMate SoC next to tesla_vehicle (BLE proxy) and tesla_cloud (Fleet API). Emits DerVehicle, binds Tesla+VIN, ages vendor data, and never wakes or starts a charge. Signed-off-by: Cursor Agent <cursoragent@cursor.com>
Every replay was marked stale, so Core dropped the car between two TeslaMate messages. A replay now carries soc_fresh=false and lets Core age it; stale=true is left for when TeslaMate reports itself unhealthy. TeslaMate publishes a topic only when its value changes, but sends `healthy` with every update. A healthy=true while the car is awake now counts as a fresh reading of the retained values. An empty time_to_full_charge or charger_actual_current, which TeslaMate sends when charging ends, now clears the old value. `starting` is not a TeslaMate state and leaves the awake set. The changelog no longer says FTW never talks to Tesla's cloud, which stops being true once tesla_cloud lands, and the catalog notes say no car has run the driver yet. Signed-off-by: Fredrik Ahlgren <fredrik@sourceful-labs.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 22b417fe6f
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| local err = host.mqtt_subscribe(base_topic .. "/#") | ||
| if type(err) == "string" and err ~= "" then |
There was a problem hiding this comment.
Handle a false subscription result as failure
When host.mqtt_subscribe rejects the subscription and returns false, this condition treats it as success because it only recognizes nonempty strings. The repository contract in spec/host-api.md states that this API returns true/false, so the driver will misleadingly log that it subscribed and then remain permanently silent because it never retries the failed subscription.
Useful? React with 👍 / 👎.
Adds
teslamate_vehicle, a read-only driver that reads a Tesla's charge state from the owner's TeslaMate MQTT broker. It is one of three vehicle drivers for srcfl/ftw#1442, next to #140 (Tesla Fleet API) and #141 (VW Group).What it does
teslamate/cars/{car_id}/#and emitsvehicle(DerVehicle):soc,charge_limit_pct,charging_state,time_to_full_min,charge_amps,charger_actual_current,staleandsoc_fresh.Teslaplus that VIN.online,charging,driving,updating) and has just read it: a changed charge field, or thehealthymessage TeslaMate sends with every update. Retained values from a sleeping car emit nothing at subscribe.soc_fresh=false, so Core ages it from the observation. It stops emitting 15 minutes after the last fresh reading.read_only = true,verification_status = "experimental". Leavestesla_vehicle(BLE proxy) untouched.Where it came from
A Cursor cloud agent wrote the first commit against
mainat92adaf0. The Cursor GitHub App can only reachsrcfl/ftw, so its push here failed with 403, and the patch was applied unchanged from Fredrik's machine. The second commit fixes what review found.Fixed in review
stale=true. Core skips a stale vehicle reading, so the car would have dropped out of Core between two TeslaMate messages. Replays now carrysoc_fresh=falseonly;stale=trueis left for when TeslaMate reports itself unhealthy.healthywith every update (not retained; seevehicle_subscriber.exin TeslaMate), which now counts as a fresh reading while the car is awake.time_to_full_chargeandcharger_actual_current. The old values used to linger; they now clear.startingis not a TeslaMate state and left the awake set.Evidence
make test-driver ID=teslamate_vehicle: 38 passed, 14 skippedmake check: 4641 passed, 881 skippednot_recorded.Still open
healthywith every update. That is true in TeslaMate's source today but not documented. If it changes, the driver falls back to fresh-on-change only.{ip, vin}, so owners must write the YAML by hand.How to test
Enable MQTT in TeslaMate (
MQTT_HOST), then:After merge the driver is in the signed
drivers-betachannel. Until an FTW release bundles it, put the Lua file on the box as a local override at the path the YAML names. Check that the vehicle shows the SoC while the car is awake, and report what happens when it sleeps and wakes.Merge notes
CHANGELOG.md,index.yaml,devices.yaml,support-status.jsonandSUPPORT_STATUS.md. Merge one, rebase the next and rerun the generators;make checkshows any drift.drivers/BUNDLED_SOURCE.json.🤖 Generated with Claude Code