Support for CAN Bus (Peak, Ixxat, canable etc)

hey @OpenJeDi , can you gives us a hand here? you bought also a canable.io adapter? :slight_smile:

Yes, please :slight_smile: ! Currently it seems to me as if the necessary tools/drivers for an integration are already there (mostly).

i hope @OpenJeDi respons, i know he bought an adapter too, he made a custom component before
we use somekind of domotica controller for our lighs/plugs, it also uses canbus

i know he was interesred, since his custom was based on TCP api, and he wanted canbus too
Sp i hope he is reading community forums :slight_smile:

Hopefully…
Currently I only own a PCAN USB adapter, which appears as native CAN bus device in Linux. For now this is fine and native CAN support should be the desirable way. But if necessary I could also buy a canable.io module for setting up identical testing conditions.

I still use the MCP2515 adapter, for reading canbus, i have it hooked up to an ESP8266 , so working with ESPHome now… works great, allthoug i prefer to use it with a ready USB hardware adapter like canable :slight_smile:

Okay, I think about the integration as follows (warning: might contain crap :slight_smile: ):

To activate CAN bus support, add the following to the configuration.yaml:

can:
  interface: can0 #(or however it's name is)
  baudrate: 125000 #(or whatever it shall be)

And then:

sensor:
  - platform: can
    unit_of_measurement: °C
    listen_id: 0x201005 # (or any other valid ID)
    value: data0
# or
    value_template: "{{ (value_json.byte0 + value_json.byte1) / 10 }}"

Does that make sense?

Makes sense indeed, … Do you need to load a driver for that adapters? I am using HassOs, no idea if HA will recognize it

Well, at least in my case, the driver is present OOTB. The SocketCAN driver collection is in the Linux kernel since 2.6.25 - so basically it should be plug and play (at least from the hardware driver side).

I already tried to set up the development environment by myself. That worked relatively good. But I get stuck at the point where it gets serious (programming). The python-library is there, the drivers are there, but I have just no idea what to do :see_no_evil:

1 Like

Hey, maybe we should start easy, instead of creating a component or a custom component, why not run a .py script in background, that just reads/writes canbus messages? i am ready doing something similar right now… When i startup HA… i run a script thats stays in background HA… its actually a socket script that reads/writes data from another hardware component, based on information i receive/get, i just send REST calls to HA to turn on a sevice like below curl script

there are plenty of example scrips on internet on python that reads/write canbus messages
what do you think?


example REST command
"curl -k -X POST -H \"Authorization: Bearer XXXXX\" -d '{\"entity_id\": \"script.xxx\"}' http://127.0.0.1:8123/api/services/script/turn_on"

with automation below i start up a script in background HA

- alias: Dobiss Server
  initial_state: 'on'
  trigger:
    - platform: homeassistant
      event: start
  action:
    - service: shell_command.dobiss_server

dobiss_server: nohup python3 /config/python_scripts/dobiss_server.py $1 > /dev/null 2>&1 &

Please don’t get me wrong, I don’t want to degrade your effort in any way. But from my point of view, running a script and providing a REST API is the same as my idea with the file-sensor: a workaround.
The goal should be to integrate that into HA natively. Your approach as well as my idea with the file-sensor do not integrate anything into HA: we take HA as it is and try to fill the gap between HA and our CAN bus hardware by scripts - but in the end the gap persists.

I try to get in touch with developers via Discord or I write them PMs via github. Now that I’ve set up my development environment, I should not stop here…

Greetings

yeah, i totally understand offcourse, its both a workaround

i hope some developer wants to make it?

maybe @danielschramm can give us a hand here? he made the integration possible with EspHome, i bet he is a Python developer :slight_smile:

i also sended @OpenJeDi i message on github, i know he wants canbus too, and he is python developer
he is not active on communitry , so i hope he receives the message now :slight_smile:

I have no Interest in implementing Canbus directly to Homeassistant.
I prefer edge Computing!
For me the controls run as scripts in EspHome autonomously and can optionally be controlled via Homeassistant.
So we can still control the window blinds when the Server is updating, etc.

no problem, thnx for feedback! :slight_smile:

But if someone else is going to start this projects I can give some hints how Python works together with Canbus like a charm.

  1. As mentioned earlier in the thread start setting up SocketCan with an appropriate USB-Can Interface. I tested Peak, Systec, MHS Tinycan and Lawicel (SLCAN) and they all work. Peak is the only one of these which needs no daemon running or where you do not need to compile an own module.
    Peak and Systec and Lawicel also run on windows with python.
  2. Use the DBC Component of https://pypi.org/project/cantools/ - in an DBC file the Can Frames are described and mapped to Data objects. You can download CanDB++ Editor from Vector for free to generate the Definitions.
    DBC Editor
    Going this way will save you very much time on defining your data and make your project really portable to other CAN-Applications.

I which you all the success with your project.

Hi,

Sorry to not reply sooner, I am sweating over a tight deadline for work right now I’m afraid. I hope to get some free time starting next week :slight_smile:

I’m still very interested in this project, but cannot guarantee I can put much time in it right now.

Creating an extension for HA is very well documented. You can also have a look at my repository’s code to see how I did it. It is far from perfect, but it does include adding the integration through the integration page instead of manually configuring it.

I did receive my cannable.io device and some other devices I ordered to tinker with, but I didn’t even unwrap them yet…

aha, you are still alive :slight_smile:
thnx for feedback already!

Hi @OpenJeDi and thank you for your reply!

I definitely agree with you that the development documentation is very good. Nevertheless I just don’t understand what to do now :sweat_smile: . It is just a problem somewhere inside of my head…

I don’t want to stress your tough time even more. I will try to do as many things as possible by myself. But of course it is highly appreciated, if there are people willing to help me to help myself :slight_smile: .

So most testing stuff could probably be done on my side. Programming… maybe :wink: .

1 Like

so i also have a canable.io , going to attach it to my esx server and to my HassOS
Do you have some kind of test script that i can use, to actually see if the hardware is working on HassOS ? for example to read canbus messages
That way i can help too with this project :slight_smile:

i also probably need candlelight firmware? right? => https://canable.io/

https://canable.io/

hmm, i think there is something wrong with my canable, just plugged it in first time use in windows desktop pc, but windows is not recognizing hardware at all in device manager , allthough greed light is on on the canable.io … verry strange

EDIT: nm, seems to be working now with another usb cable , verry strange