How to Enable or Disable Vehicles in TeslaMate: Complete Guide

You can enable or disable vehicles in TeslaMate by toggling the enabled boolean field in the CarSettings record, which the supervisor uses to filter active vehicles during startup and hide them from the web interface.

TeslaMate is an open-source data logger for Tesla vehicles that stores configuration details in a structured CarSettings schema. Managing which vehicles actively sync data and appear in the dashboard relies on a single database flag that controls supervisor behavior and UI visibility.

Understanding the CarSettings Schema

Vehicle configuration in TeslaMate centers on the CarSettings struct defined in lib/teslamate/settings/car_settings.ex. The schema includes a critical boolean field that defaults to active:

field :enabled, :boolean, default: true

This field persists in the database and determines whether a vehicle receives API polling, appears in the LiveView dashboard, and consumes system resources. When enabled is set to false, the vehicle remains in the database but enters a dormant state.

How the Vehicle Supervisor Filters Enabled Vehicles

During application startup, the TeslaMate.Vehicles supervisor initializes child processes for each configured vehicle. In lib/teslamate/vehicles.ex, the init/1 function explicitly filters out any car whose settings.enabled flag is false:

def init(opts) do
  children =
    opts
    |> Keyword.get_lazy(:vehicles, &list_vehicles!/0)
    |> Enum.map(&{Keyword.get(opts, :vehicle, Vehicle), car: create_or_update!(&1)})
    |> Enum.uniq_by(fn {_mod, car: %Car{id: id}} -> id end)
    |> Enum.filter(fn {_mod, car: %Car{settings: settings}} -> settings.enabled end)
    
  Supervisor.init(children, strategy: :one_for_one)
end

Consequences of disabling a vehicle include:

  • No API polling – The vehicle worker does not start, halting all Tesla API requests.
  • UI removal – The vehicle disappears from the main dashboard and Grafana dashboards.
  • Resource conservation – Eliminates background processes for sold or inactive vehicles.

Methods to Enable or Disable Vehicles

Using the Web UI (SettingsLive)

The most straightforward approach involves the Settings page in the TeslaMate web interface. The SettingsLive module in lib/teslamate_web/live/settings_live/index.ex handles toggle switches via the handle_event/3 callback:

def handle_event("change", params, %{assigns: %{car_settings: settings, car: id}} = socket) do
  params = params["car_settings_#{id}"]

  settings
  |> get_in([id, :original])
  |> Settings.update_car_settings(params)
  |> case do
    {:ok, car_settings} ->
      socket
      |> assign(:car_settings, put_in(settings, [id, :original], car_settings))
      |> assign(:car_settings, put_in(settings, [id, :changeset], Settings.change_car_settings(car_settings)))
      
    {:error, changeset} ->
      assign(socket, :car_settings, put_in(settings, [id, :changeset], changeset))
  end
  |> then(&{:noreply, &1})
end

When you click the enable/disable switch in the UI, the LiveView sends a "change" event that invokes Settings.update_car_settings/2, persisting the new state to the database immediately.

Direct Database Update via Console

For advanced users or automation scripts, you can toggle the enabled flag directly from an Elixir shell (IEx) session:


# Fetch existing settings for vehicle ID 1

{:ok, car_settings} = TeslaMate.Settings.get_car_settings(1)

# Disable the vehicle

{:ok, updated} = TeslaMate.Settings.update_car_settings(car_settings, %{enabled: false})

IO.puts("Vehicle #{updated.car_id} is now #{if updated.enabled, do: "enabled", else: "disabled"}")

To re-enable, simply pass %{enabled: true} to the same function. The TeslaMate.Settings module in lib/teslamate/settings.ex handles the database transaction and validation.

Summary

  • The enabled boolean in CarSettings (defined in lib/teslamate/settings/car_settings.ex) controls vehicle visibility and activity.
  • The supervisor filters disabled vehicles during initialization in lib/teslamate/vehicles.ex, preventing them from spawning worker processes.
  • Web UI toggles trigger Settings.update_car_settings/2 in lib/teslamate_web/live/settings_live/index.ex for immediate changes.
  • Console updates allow programmatic control via the TeslaMate.Settings context module.
  • Changes persist across restarts because the flag is stored in the database, not in volatile memory.

Frequently Asked Questions

What happens when I disable a vehicle in TeslaMate?

When you disable a vehicle, the TeslaMate.Vehicles supervisor removes it from the active child process list during the next initialization cycle. The vehicle stops receiving Tesla API updates, ceases consuming polling quota, and disappears from the web interface and Grafana dashboards. Historical data remains intact in the database.

Can I re-enable a vehicle after disabling it?

Yes. Simply toggle the Enabled switch in the Settings page or update the CarSettings record via the console with %{enabled: true}. The supervisor will automatically include the vehicle in its child list on the next application start, or immediately if the application is running.

Does disabling a vehicle affect historical data?

No. Disabling a vehicle only stops future data collection and API polling. All existing drives, charges, states, and statistics remain preserved in the PostgreSQL database. Re-enabling the vehicle resumes data collection from the current state without affecting past records.

Where is the enabled flag stored in TeslaMate?

The enabled flag is stored in the car_settings database table, managed by the TeslaMate.Settings.CarSettings Ecto schema. The TeslaMate.Settings context module provides the public API for reading and updating this value through functions like get_car_settings/1 and update_car_settings/2.

Have a question about this repo?

These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:

Share the following with your agent to get started:
curl -s "https://instagit.com/install.md"

Works with
Claude Codex Cursor VS Code OpenClaw Any MCP Client

Maintain an open-source project? Get it listed too →