mrk-its / can2mqtt

Apache License 2.0
44 stars 5 forks source link

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:

How to start

Hardware requirements

Software requirements

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

Support