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

yeah, i noticed earlier in the first stages by luck, that he was developing this for ESPHome
so tested some stuff for him with the hardware setup

i am quite happy with it, i was always already able to control my lights and other stuff by TCP commands, but the wallswitches are based on canbus, so i can now intercept them and do more then just turn on lights :slight_smile:

next phase is sending canbus messages, allthough i dont need it for now

Did you make any progress with this hardware? Maybe just with python scripts?

Hi!
Sorry for my late response.
What do you mean? Do you mean with my custom hardware or with the PCAN device? Or with Homeassistent in general?
Sadly I have been busy with private stuff lately. So there was nothing possible but a little bit of soldering… :confused:

Yeah, just interested nog you were able to use canable.io with home assistant :wink:

No, not yet. But because of HA does currently not know anything about CAN bus, the only option would be to flash the firmware for a virtual serial port onto the canable. So HA would just interact with this serial interface - from my point of view, this is not a desirable way to go, because most advantages of CAN bus compared to serial would be down the sink…

Ok, I had time to investigate in this a little bit.
I played around with the Linux tools “can-utils”, which worked pretty fine with my PCAN USB adapter.

My fundamental idea about the integration into HA was to have sensor components for different CAN IDs.
Based in this I played around with candump: it is possible to start different candump-processes in parallel, listening to different CAN IDs (with filters).

Describing it in my easy and immature words, each CAN sensor could start its own candump-process (or whatever), listening to its own identifier. The data-field could then be treated similar to a MQTT payload.
So from my point of view, the CAN bus sensor component architecture itself would not violate the current usage style.

I am quite familiar with CAN bus, but not with the HA programming. So if there is anyone who is familiar with creating sensor components, I would be happy to support with CAN bus and testing.

Greetings

ok, sounds great!! but i am not a developer , i know maybe someone, who s also interested in canbus and HA, and who is a developer

If there is no chance to get CAN bus integrated into HA, you could start as many candump-processes as you like to listen to different CAN IDs which write their outputs to individual files. Then you could create file sensor components in HA that observe these files. Of course, this is a quite crappy way to do it. But at least this could work…

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: