Want to take your smart home to the next level and monitor your car’s performance data in real-time? By combining an Esp32 Obd2 Reader with Home Assistant, you can unlock a wealth of information about your vehicle directly within your home automation system. This guide will walk you through the process of setting up your ESP32 OBD2 reader, specifically focusing on WiCAN, to seamlessly integrate with Home Assistant using MQTT and Node-RED.
This powerful combination allows you to monitor parameters like engine temperature, fuel level, and battery voltage, create custom dashboards, and even trigger automations based on your car’s data. Imagine automatically turning on your garage lights when your car returns home and its engine temperature is above a certain threshold! Let’s dive into how you can achieve this integration.
What You’ll Need
Before we begin, ensure you have the following components ready:
- ESP32 OBD2 Reader (WiCAN): This device will act as the bridge between your car’s OBD2 port and your home network. WiCAN is a popular and capable option for this purpose.
- Home Assistant: Your central smart home platform. Make sure you have Home Assistant already installed and running.
- Home Assistant Mosquitto Broker Add-on: MQTT (Message Queuing Telemetry Transport) is a lightweight messaging protocol that WiCAN will use to communicate with Home Assistant. Mosquitto Broker will handle these messages within Home Assistant.
- Home Assistant Node-RED Add-on: Node-RED is a flow-based programming tool that simplifies the creation of automations and data processing. We’ll use it to manage the data coming from WiCAN.
- Home WiFi Network: Both WiCAN and your Home Assistant server need to be connected to your WiFi network.
Now, let’s get started with the step-by-step integration process.
Step-by-Step Guide to Connect WiCAN ESP32 OBD2 Reader to Home Assistant
Follow these steps to successfully connect your WiCAN ESP32 OBD2 reader to Home Assistant.
1. Install Mosquitto Broker in Home Assistant
MQTT Broker is essential for communication between WiCAN and Home Assistant.
- Navigate to Supervisor in your Home Assistant sidebar.
- Go to the Add-on Store tab.
- Search for “Mosquitto Broker” and click on it.
- Click the Install button.
- Once installed, go to the Configuration tab. For basic setup, you usually don’t need to change the default configuration.
- Go back to the Info tab and click Start to start the Mosquitto Broker.
2. Create a Dedicated Home Assistant User for WiCAN
For security and organization, it’s best to create a separate user account specifically for WiCAN’s MQTT access.
- In Home Assistant, go to Settings and then People.
- Click “+ Add Person”.
- Create a username (e.g.,
wican_user
) and a strong password. - You can leave the other fields as default. Click Create.
- Note down these credentials, as you’ll need them later to configure WiCAN.
3. Connect to WiCAN and Configure WiFi and MQTT Settings
Now, let’s configure WiCAN to connect to your WiFi and MQTT broker.
- Power up your WiCAN ESP32 OBD2 reader by plugging it into your car’s OBD2 port.
- WiCAN will create a WiFi access point (AP) with a name like
WiCAN_xxxxxxxxxxxx
. - On your computer or smartphone, connect to this WiCAN WiFi network.
- Open a web browser and go to
http://192.168.80.1/
. This will open the WiCAN configuration page. - Set the “Mode” to
Ap+Station
. This allows WiCAN to connect to your WiFi network while still providing a local access point for initial configuration if needed. - Enter your Home WiFi network’s SSID and Password in the “Station” section.
- Enable MQTT by toggling the switch.
- Fill in the MQTT settings using the Home Assistant user credentials you created in Step 2 and your Home Assistant’s IP address.
- MQTT Server: This is usually your Home Assistant’s IP address. If Home Assistant is running on
homeassistant.local
, you can usehomeassistant.local
or the IP address of your Home Assistant server. - MQTT Port: The default MQTT port is
1883
. - MQTT User: Enter the username you created for WiCAN (e.g.,
wican_user
). - MQTT Password: Enter the password for the WiCAN user.
- MQTT Client ID: You can leave this as the default or set a custom ID.
- MQTT Server: This is usually your Home Assistant’s IP address. If Home Assistant is running on
- Click Save to apply the settings. WiCAN should now connect to your WiFi network and the MQTT broker.
WiCAN device connected to OBD2 port
Image: WiCAN ESP32 OBD2 reader connected to a vehicle’s OBD2 port, demonstrating the hardware setup for retrieving car data.
4. Install Node-RED Add-on in Home Assistant
Node-RED will process the MQTT messages from WiCAN and make the data usable in Home Assistant.
- Navigate to Supervisor in your Home Assistant sidebar.
- Go to the Add-on Store tab.
- Search for “Node-RED” and click on it.
- Click the Install button.
- Once installed, go to the Info tab and click Start to start the Node-RED add-on.
- Click “Open Web UI” to access the Node-RED interface in a new tab.
5. Import and Configure the WiCAN Example Flow in Node-RED
An example Node-RED flow simplifies the initial setup by providing pre-configured nodes to handle WiCAN data.
- Download the
wican_example_flow.json
file from the WiCAN GitHub repository or from the developer’s provided link. Ensure you replacedevice_id
in the flow with your actual WiCAN device ID. You can usually find the device ID in the WiCAN web configuration interface or in the MQTT topics WiCAN publishes. - In the Node-RED interface, click the menu button (three horizontal lines) in the top right corner.
- Select Import -> Clipboard.
- Paste the contents of the
wican_example_flow.json
file into the import dialog and click Import. - You should now see the example flow in your Node-RED workspace.
- Double-click the MQTT in node (usually labeled “subsction Node” or similar in the example flow).
- Click the pencil icon next to the “Server” field to edit the MQTT broker configuration.
- In the “Connection” tab, set the following:
- Server: Your Home Assistant’s IP address or
homeassistant.local
. - Port:
1883
. - Security: Set to “TLS configuration” if you are using a secure MQTT connection, otherwise leave it as “None”.
- User: Enter the username you created for WiCAN (e.g.,
wican_user
). - Password: Enter the password for the WiCAN user.
- Server: Your Home Assistant’s IP address or
- Click Update and then Done in the MQTT in node settings.
- Click the Deploy button in the top right corner of Node-RED to apply your changes.
6. Configure MQTT Sensors in Home Assistant configuration.yaml
To display the data from your ESP32 OBD2 reader in Home Assistant, you need to define MQTT sensors in your configuration.yaml
file.
- In Home Assistant, navigate to Settings and then File editor (or use your preferred method to edit configuration files).
- Open the
configuration.yaml
file. - Add the following lines to define MQTT sensors. Adjust the
state_topic
to match the MQTT topics your WiCAN device is publishing (refer to WiCAN documentation for topic details). The example below shows sensors for “Ambient Temperature” and “Fuel Level”:
mqtt:
sensor:
- name: "Ambient Temperature"
state_topic: "CAR1/Amb_Temp" # Adjust to your WiCAN topic
unit_of_measurement: "°C"
value_template: "{{ value_json.amb_temp }}"
- name: "Fuel Level"
state_topic: "CAR1/Fuel_Level" # Adjust to your WiCAN topic
unit_of_measurement: "%"
value_template: "{{ value_json.fuel_level }}"
state_topic
: This is the MQTT topic that WiCAN publishes data to. Replace"CAR1/Amb_Temp"
and"CAR1/Fuel_Level"
with the actual topics from your WiCAN device.unit_of_measurement
: Specify the unit for the sensor value.value_template
: This template extracts the sensor value from the JSON payload of the MQTT message. Adjustvalue_json.amb_temp
andvalue_json.fuel_level
to match the keys in your WiCAN’s MQTT payload.
- Click Save to save the
configuration.yaml
file.
7. Restart Home Assistant and Add Entities to Your Dashboard
Finally, restart Home Assistant to apply the configuration changes and add your new sensors to your dashboard.
- In Home Assistant, go to Developer Tools in the sidebar.
- Go to the YAML tab.
- Click the “Check Configuration” button to ensure your
configuration.yaml
is valid. If there are errors, correct them before proceeding. - Go to the “Restart” tab and click the “Restart Home Assistant” button.
- After Home Assistant restarts, go to your desired dashboard or create a new one.
- Click “Add Card” and choose an “Entities” card or any other card type you prefer to display sensor data.
- Add the MQTT sensors you defined (e.g., “sensor.ambient_temperature”, “sensor.fuel_level”) to the card.
- Click Save.
You should now see the data from your ESP32 OBD2 reader displayed on your Home Assistant dashboard!
Start Monitoring Your Car Data
Congratulations! You have successfully integrated your ESP32 OBD2 reader (WiCAN) with Home Assistant. You can now monitor your car’s data in real-time, create custom dashboards to visualize the information, and build powerful automations based on your vehicle’s status.
Experiment with different sensors, explore more advanced Node-RED flows, and unlock the full potential of combining your car’s data with your smart home. This integration opens up a world of possibilities for vehicle monitoring, diagnostics, and smart automations.