No description
  • Python 90.9%
  • Smarty 5.9%
  • Shell 2.5%
  • Dockerfile 0.7%
Find a file
cynt4k b8e5ad7f8b
Some checks failed
Test / Test build amd64 (push) Has been cancelled
Test / Test build aarch64 (push) Has been cancelled
Publish / Derive registry (release) Successful in 1s
Publish / Build and push aarch64 (release) Successful in 4m1s
Publish / Build and push amd64 (release) Successful in 34s
Publish / Publish multi-arch manifest (release) Successful in 2s
feat: add rgb support
Signed-off-by: cynt4k <tobi@truecore.tech>
2026-06-06 19:57:07 +02:00
.forgejo/workflows feat: add can interface and bitrate support 2026-06-04 01:51:13 +02:00
src feat: add rgb support 2026-06-06 19:57:07 +02:00
.gitignore update readme / example esphome node config 2023-03-06 12:22:51 +01:00
build.yaml feat: add can interface and bitrate support 2026-06-04 01:51:13 +02:00
CHANGELOG.md bump version to 0.2.8 2025-07-06 23:13:20 +02:00
config.yaml feat: add rgb support 2026-06-06 19:57:07 +02:00
Dockerfile feat: add can interface and bitrate support 2026-06-04 01:51:13 +02:00
LICENSE-APACHE Add licence files 2023-02-12 21:50:45 +01:00
LICENSE-MIT Add licence files 2023-02-12 21:50:45 +01:00
pyproject.toml add pyasyncore to deps 2025-05-07 12:26:13 +02:00
README.md add CAN OTA section to README 2025-02-23 18:32:13 +01:00
repository.yaml remove '(test)' from addon repository name 2025-01-01 18:11:03 +01:00
run.sh feat: add txlen support 2026-06-04 03:30:23 +02:00

Can2MQTT Bridge

ESP32 comes with integrated CAN Bus controller. ESPHome provides low-level support for it (sending / receiving messages from the bus), but it is not able (yet) to automatically expose entities to HomeAssistant over CAN.

This project tries to fill the gap and provides tools for easy exposing ESPHome entities to Home Assistant over CAN Bus:

  • It provides can2mqtt bridge exposing ESPHome CANopen entities onto MQTT topics. It follows MQTT Discovery protocol, so entities appear automatically in HomeAssistant.
  • The esphome-canopen project converts ESPHome device into CANopen node, exporting selected entities over CAN by mapping them to CANopen object dictionary. It also allows to define TPDOs for sending entity state on change. Currently following entity types are supported: sensor, binary_sensor, switch and cover. Entity metadata is also published in Object Dictionary enabling autodiscovery.

How to start

Hardware requirements

  • Linux box with CAN Bus controller supported by python-can library
  • ESP32 board(s) flashed with ESPHome firmware and configured esphome-canopen external component.

There is also esphome-canbus-usb-serial project turning ESP32 S3/C3 device into USB-CAN interface, with dedicated python-can driver (it is also possible to install esphome-canbus-usb-serial component on one of existing ESP32 CANOpen nodes).

Another way of connecting CANBUS to HA is esphome-canbus-udp-multicast. It implements udp_multicast virtual CANBUS interface and allow to bridge existing CANBUS network to PC via UDP multicasts. It also makes possible to create 'virtual' CAN network with nodes communicating only via UDP packets. It is especially convenient for developing / testing / debugging (a lot of can2mqtt / esphome-canopen features were developed this way)

Software requirements

  • MQTT Broker installed and configured in Home Assistant (with auto-discovery), take a look on documentation for details

Installation as HomeAssistant add-on

Open your Home Assistant instance and show the add add-on repository dialog with a specific repository URL pre-filled.

Manual installation

  $ python3 -m venv venv
  $ venv/bin/pip install git+https://github.com/mrk-its/can2mqtt
  $ venv/bin/can2mqtt --help

  usage: can2mqtt [-h] [-s MQTT_SERVER] [-i INTERFACE] [-c CHANNEL] [-b BITRATE] [-l LOG_LEVEL] [-t MQTT_TOPIC_PREFIX]

  CAN to MQTT converter

  options:
    -h, --help            show this help message and exit
    -s MQTT_SERVER, --mqtt-server MQTT_SERVER
    -i INTERFACE, --interface INTERFACE
    -c CHANNEL, --channel CHANNEL
    -b BITRATE, --bitrate BITRATE
    -l LOG_LEVEL, --log-level LOG_LEVEL
    -t MQTT_TOPIC_PREFIX, --mqtt-topic-prefix MQTT_TOPIC_PREFIX

and run it with proper MQTT server / CAN interface configuration. MQTT server can be provided as -s argument or included in python-can configuration file, like:

  $ cat ~/can.conf
  [default]
  interface = seeedstudio
  channel = /dev/ttyUSB1
  bitrate = 500000

  mqtt_server = 192.168.1.200

  $ venv/bin/can2mqtt -l DEBUG

If CAN Bus communication is working properly you should see on stdout received CAN frames and data published to MQTT topics. In HomeAssistant you should see new entities like switch.can_001_02

Firmware updates via CAN (CAN OTA)

can2mqtt and esphome-canopen together support firmware upgrades via CANBUS:

  • make sure there is canopen ota platform present in esphome's yaml file:

    ota:
      - platform: canopen
    
  • compile your node's firmware with

    esphome compile node.yaml
    

    resulting firmware.bin typically is located in:

    .esphome/build/node-xyz/.pioenvs/node-xyz/firmware.bin
    
  • copy resulting firmware.bin to proper firmware directory monitored by can2mqtt.

    • if can2mqtt is installed as an addon of HA supervised, then can2mqtt is ran with --firmware=/config parameter, mapped to /addon_configs/{SLUG}_can2mqtt/ shared directory. SLUG is 8-hexdigit value that can be found on addon's page. It is recommended to create subdirectory for each node and put firmware.bin file there, and copy file to path like: /addon_configs/{SLUG}_can2mqtt/node-xyz/firmware.bin
    • if can2mqtt is installed standalone, then --firmware option can be used to provide firmware directory (it defaults to './firmware`)
  • after copying firmware file following message should appear in can2mqtt logs:

    2025-02-23 17:04:47 can2mqtt.entities  INFO new_firmware: /config/node-xyz/firmware.bin, node_id: ..., ver: 2025.2.0.20250223.001140
    

    and new update should be visible in HA

  • update may be installed via standard HA update interface, the update progress / final status should be visible in can2mqtt logs. When update is finished node will be restarted and should be re-registered in can2mqtt.

Support