A vehicle CAN (Controller Area Network) bus has a wealth of information and data which can be used for HA integrations and automations.
The CAN bus is a complicated system, made up of different bus type - each related to specific roles in the vehicle and have been developed over time by manufacturers and have diverged into different standards. - there is not a `single` CAN bus.
An ODB II port is generally available on most new vehicles (post 1996) and exposes a limited set of CAN bus data. The ODB II port is not a direct connection to the various CAN bus, but serves as a generic port which sends requests to an internal ODB II gateway device (usually the BSI/BCM), which publishes the requested CAN bus data back to the ODB II connected device.
More info here:
https://www.csselectronics.com/pages/obd2-explained-simple-intro
https://www.wevolver.com/article/understanding-can-bus-a-comprehensive-guide
https://medium.com/@fmntf/connecting-to-the-infotainment-can-network-34a79b6de0d8
https://www.obdtester.com/elm-usb-commands
https://www.autopi.io/blog/how-to-read-can-bus-data/
https://sourceforge.net/p/rusefi/tickets/_discuss/thread/65c5390c/5610/attachment/iso_15765-4.pdf
https://www.csselectronics.com/pages/obd2-pid-table-on-board-diagnostics-j1979
https://www.csselectronics.com/pages/j1939-pgn-conversion-tool
https://dauntlessdevices.com/support/dauntlessobd-developer-api-info/dauntlessobd-supported-elm327-style-at-commands/
https://github.com/iDoka/awesome-canbus
https://www.snapon.com/EN/US/Diagnostics/News-Center/CAN-Bus
https://www.youtube.com/watch?app=desktop&v=k8bJegVxo_c
Low-Speed CAN, also known as fault-tolerant or ISO 11898-3, typically at 50Kbps, but operates at speeds up to 125 kbps. It is designed for less critical systems like body control modules, door locks, window controls, etc., where data transmission speed isn't vital. Its key feature is the ability to continue functioning even when one wire in the bus fails. (Source)
https://www.iso.org/standard/36055.html
Used for Media / Entertainment / Steering wheel controls. Opening a Connects2 steering wheel adapter reveals a TJA1055 IC. This CAN bus is present on the Stereo Headunit rear connector and used to provide road speed telemetry, engine status, steering wheel control integration etc.
This low-speed Fault Tolerant CANbus operates on different electrical voltages than the main ODBII port and high speed CANbus. Whilst a high-speed CANbus transceiver can work with the low-speed, it is not advised and could cause unsable CANbus issue with errors and intermittent connectivity. - i can validate from my own experience.
High-Speed CAN, or ISO 11898-2, typically at 500Kbps, but can reach speeds up to 1 Mbps. This type of network is suitable for more time-sensitive applications such as engine management systems and electronic braking systems due to its faster data transfer rates compared to low-speed counterparts. However, it lacks fault tolerance capabilities found in low-speed networks. (Source)
https://www.sae.org/standards/content/j2284/3_201611/
The K-Line is a very low-speed single-wire serial communication system used on many motor vehicles and commercial vehicles. It is commonly used for the diagnostic connections between the Electronic Control Modules (ECMs) on the vehicle and the diagnostic equipment (scan tools and data loggers). The K-Line is a network based upon the ISO9141 specifications, also known as the 9141 California Air Resources Board (CARB) Standard.
The K-Line is very different to a CAN Bus network and from most communication networks in general. A CAN Bus network, for example, does not have either a central or a primary ECM: all the ECMs are equal as they are all able to transmit messages along the network as well as receive messages.
https://www.picoauto.com/library/automotive-guided-tests/k-line#:~:text=The%20K%2DLine%20is%20a,scan%20tools%20and%20data%20loggers).If you want to directly access the vehicle specific CAN bus data, then wiring diagrams will help.
For example, this is the functional diagram of the Peugeot Boxer Audio system, and shows the B-CAN low speed can bus interconnects various systems including the Stereo and Instrument Cluster.
This CAN bus provides data about vehicle motion & comfort systems and can be a useful source of information in HA.
Digging deeper into the wiring diagrams, it can be seen that the main Body System Integration ECU (BSI1), connects through the Body Fuse box (BF00), through a connector (B002) to the Stereo headunit (8410).
The Wires shown in bold are the B-CAN bus lines and can be physically identified as blue and white twisted pairs.
This wiring diagram represents the Diagnostics port socket.
At the top of the Wiring diagram is the socket (C001).
The connected systems can be verified and seen exposed as pins on the ODB connector pinout below.
This can vary with make/model of vehicle, please check your own wiring specs and pinouts.
There are several routes with options... below i have detailed two...
Using WiCAN hardware modele for Vehicle ODB Port diag data, using pre-configured `vehicle profiles` allows some common vehicle data to be pulled into Home Assistant.
This also has the benefit on being easy to reconfigure for streaming canbus data to the `SavvyCan` app for initial diagnotics and decoding
Using a more complicated ESP32 hardware, and a TJA1050 can bus transceiver chip, can be used configured through the ESPhome environment and used to `monitor` the can bus for known message IDs and read can bus data into HA. ** NOTE: this method introduced some CANbus instabilty and caused various sporadic messages to occur (airBag,Parking, intermittent indicators) - i would advise to go the TJA1055 route for full compatibility.
Using a FT-CAN TJA1055 CANbus transceiver connected to an ESP32.
Whilst i started with the TJA1050 high-speed CANbus transciever and it worked at low speeds, it was not very stable and caused a range of CANbus signal errors due to the TJA1050 not able to work in Fault Tolerant mode or at the correct voltages. IT should be noted that the low-speed CANbus does not require the 120Ohms termination resistors either.. contrary to a lot of generic CAN bus documentation. I ended up pulling out the BCM, Parking ECU and Dash instrument panel, opening up and checking for termination resistors and board faults using an oscilliscope to check for voltage fluctuations and signal interference.. until i realised the FT-CANbus is significantly different.
I am now using the TJA1055, wired up to the ESP32 wih no errors.. and full compatiblity with all the other low-speed CANbus ECUs.
MeatPi make a handy CANbus device and have been actively working on the development and integration into Home Assistant.
https://www.meatpi.com/
Documentation is constantly being added to and enhanced here:
https://meatpihq.github.io/wican-fw/
The device is available from a number of outlets online, i purchased mine from:
https://www.mouser.co.uk/c/?q=wican
Wire up the WICAN USB module to the ODBport.
VIN > ODBII pin 16 (12v)
GND > ODBII PIN 4 or 5 (Gnd)
CH (B-CAN A) > ODBII Pin 6 (on a Peugeot Boxer 2016)
CL (B-CAN B) > ODBII Pin 14 (on a Peugeot Boxer 2016)
Note: ODBII CAN pins may be different per manufacturer, please checked and validate before connecting.
With the Vehicle Ingition Key ON, you should see the Green Power LED on.
Connect over Wifi to the WICAN default wifi AP and access it via
http://192.168.80.1
Set up your Wifi Connection settings.
AP Config
Mode : AP+Station
Station Config:
your HA connected Wifi SSID
your HA connected Wifi SSID password
Reboot the module and connect to your HA connected WiFi network.
If your using DHCP, you will need to discover the IP address of the device, this should be displayed on the DHCP page of your router, it wil be shown as an `espressif ` (ESP) device.
you should be able to login to the new DHCP allocated IP address from now.
you may want to either set a DHCP reservation, or give the device a static IP.
First ! : Update to the latest firmware release from Github:
https://github.com/meatpiHQ/wican-fw/releases
Note: at present the HA integration is only available as unreleased test code available via the Discord channel
note: MQTT must be disabled to install this update)
Setup the WiCAN CANbus options as shown and reboot.
Notable : `50Kbps` for the B-CAN on the rear of the Stereo/ODB ports 1&9.
When CANbus data is detected by WiCAN the Orange Data LED will flash on Tx/Rx.
Check for Data.
using the WiCAN `Monitor` page, and the Ignition ON, click the `Start` monitor button and ensure you are seeing a stream of CAN busdata.
Remember to Reboot after this monitor is stopped to ensure the WiCAN is working correctly.
Setup the Vehicle Profiles to import known working ODBII PID data queries..
note : the Latest software has a refresh button to directly download the latest github `vehicle_profiles.json` file.
enable the require Vehicle/Model.
Note : the `Home Assistant Discovery` is not needed with the new WiCAN HA integration below
Reboot after changing settings.
The Peugeot Boxer 2016 MkIII model uses a ODB Port with ISO-15765, 29bit High Speed CAN bus at 500Kbps requiring the a specific Initialization/ header string. These are preconfigured in the `vehicle_profiles.json` file under `AAA: Generic 29bit`
available here:
https://drive.google.com/file/d/1dit24VDGmydgPnsXjzHReCxpWEIPEKhq/view?usp=drive_link
ATSP7, ATSHDB33F1,ATST96
AT SP h / hh - Set Protocol (See supported protocol list; supports 1 or 2 character protocol IDs; auto mode will only try OBD protocols)
Protocol 7 is `ISO-15765 CAN 29-bit @ 500 kbps` (OBD-II on most Honda, Volvo, GM Global-B, some FCA, etc)
AT SH hhh / hhhhhh / hhhhhhhhb - Set Header (Sets CAN-11 or CAN-29 transmit ID)
AT ST hh - Set Timeout (Note that this is the maximum timeout when using Adaptive Timing modes)
Add the HA Integration via HACS
Note: at present the HA integration is only available as Alpha test code available on Github.
Add this Integration as a `Custom Repository`
Add the HACS device integration into HA
Devices / Add / Search for `WiCAN`
when prompted, add the IP address of your WiCAN device.
Note: This Integration works over exposed HTTP data and does not require MQTT.
A number of default `Device` based entities are added, along with all from the selected `Vehicle` profile and Custom PIDs.
Validate data....
Advanced Data : Finding PID information to monitor.
Use the android app `Car Scanner` connected to a seperate ODBII plug, to selectively scan elements and log the full Tx/Rx data flow.
from there, extract the required PID request value and create `Custom PID` on the WiCAN webpage.
it should appear in the HA Integration under the WiCAN device.
validate the PID Values and ammend the `Expression` on the WiCAN device to result in the correct valid required data.
or...
On the Peugeot Boxer ODB port, there are 2 additional CAN bus pins exposed.
Pins 1 & 9.
These are connected to the low-speed CAN bus data, for Instrument Cluster/Doors/Windows/Entertainment Headunit etc...
It operates on a 50Kbps datarate.
The canbus data streams, may look un intelligible... but with a bit of analysis, they reveal some usefull insights and lead to the required information.
The WiCAN device can be configured to export the CAN bus data as a live stream using a few protocols. Using the `SavvyCan` mode and using the SavvyCan app :
https://github.com/collin80/SavvyCAN
The CAN bus messages are recorded and presented with a variety of tools to allow the analyis.
A simple method, is to do a repeated action whislt recording the data.. then look through the data for the repeated messages - which standout over the backghround noise.
https://www.csselectronics.com/pages/can-bus-sniffer-reverse-engineering#savvycan
Some Examples below:
#HeadLights_Status
#0x06214000
#2nd Byte, Bit Mask : 01101000 (0x68)
- can_id: 0x2214000
use_extended_id: true
then:
- lambda: |-
if (x.size() > 0) {
// Check if bit 12 is high
if ((x[1] & 0x68) == 0x68) {
id(Headlights_Status).publish_state(true);
} else {
id(Headlights_Status).publish_state(false);
}
}
#HazardLights_Status
#0x06214000
#3rd Byte, Bit Mask : 01100000 (0x60)
- can_id: 0x2214000
use_extended_id: true
then:
- lambda: |-
if (x.size() > 0) {
// Check if bits 22 and 23 are high
if ((x[2] & 0x60) == 0x60) {
id(HazardLights_Status).publish_state(true);
} else {
id(HazardLights_Status).publish_state(false);
}
}
An Alternative option, rather than using the WiCAN, is to use an ESP32 device, with the ESPhome development environment.
There is specific CAN Bus functionality.
https://esphome.io/components/canbus/index.html
Using an ESP32-WROOM and a `TJA1050 CAN Controller Interface Module` (note the Termination Resistor will need to be unsoldered from the board)
The CAN bus transciever, wired up to the same low speed (50Kbp) B-CAN bus, can view the same canbus frame messages and exposed to Home Assistant as sensors.
* NOTE: this method introduced some CANbus instabilty and caused various sporadic messages to occur (airBag,Parking, intermittent indicators) - i would advise to go the TJA1055 route for full compatibility.
[18:00:20][D][canbus:069]: received can message (#5) extended can_id=0xa014003 size=4
[18:00:20][D][canbus:069]: received can message (#6) extended can_id=0x6214000 size=8
[18:00:20][D][canbus:069]: received can message (#7) extended can_id=0x6314000 size=8
[18:00:20][D][canbus:069]: received can message (#8) extended can_id=0x2214000 size=6
[18:00:20][D][canbus:069]: received can message (#9) extended can_id=0x6254000 size=8
Latest ESP CANbus Code udpates available on Github
https://github.com/stav242/esphome-canbus-peugeot-boxer
AI is great at looking at load of data and finding answers in seemingly random information.
so... i captured some canbus frames using SavvyCan whilst the engine was running, and pasted a good portion of it into the Google Gemini AI chat bot.
Then asked it a question, with context and a specific output...
using the initial data i provided, identify the engine rpm can frame ID, bytes and expression which would equart to around 800 rpm. provide the results in a esphome canbus format with the on_frame section. and provide the template sensor that would be passed to home assistant
i have literally copied and pasted this into ESPhome ... and it works.
this took a few attempts to prompt the correct response... but hopefully will be a helping step to find the notoriously hard canbus frame data.
I have replace the manufacturer Stereo headunit as it had very limited functionality, with a new Android unit (Atoto S8 Standard) capable of connecting to Home Assistant, as well as Wireless Android Auto/Carplay and google maps/spotify etc...
but... the feature to `set the clock` was on the stereo menu functions and has since been missing, which has meant that if the vehicle battery was disconnected, the vehicle `clock` would reset and be out of sync. Daylight savings time changes also cause the clock to be 1 hour out at different times of the year.
Luckily... i still have the old Stereo, with the WiCAN to sniff the canbus traffic.
It has taken some time, with the aid of ChatGPT to hone the esphome yaml code... but i have finally got a script (a button in HA) which triggers a time sync, from the HA time, sending the `set time` function to the vehicle clock...
TAJ1055 FT-CANbus transceiver fior low-speed CANbus.
Work in Progress....