Using CAN-Bus, Websocket, GPIO

Hello
I am a beginner in Home Assistant. For my home automation I want to use a multi-master CAN Bus with 30 CAN-nodes. Sending messages from HA is probably not the problem. But I am not sure how to listen to the bus and recognize every message on the bus without a possibility of interrupts.
My hardware components are:
Raspberry Pi 3
CAN Bus:
Tiny-CAN II-XL (http://www.mhs-elektronik.de/index.php?module=artikel&action=artikel&id=3) with a API for C# and Python. (preferred)
Or:
PiCAN2 (http://skpang.co.uk/catalog/pican2-canbus-board-for-raspberry-pi-23-p-1475.html) with the SocketCAN driver.

So here are my questions:

  1. Is it possible to send, receive and handle CAN messages with one of these two CAN adapters and a bus speed of 125 kbit/s in HA?
  2. How can I recognize a short (<1/125000 s) HIGH-signal on a GPIO and process the message with the python API?
    Or:
  3. How can I recognize an incoming message on a websocket and process it?
    I hope someone can give me an advice.

Thank you for your answer.

Did you make any progress with this? I also have a CAN-bus based domotica system and would love to get it talking to HA.

U can use this module
https://ucandevices.github.io/uccb.html#!#python

1 Like

Hello!

I would like to communicate with my Stiebel Eltron heatpump (WPL 18 cool). It’s using can bus for internal communication between stiebel components.
I plan to use a Basic(UCCB) can adapter. The integration doesn’t exist, but there are some python examples around to start with. I plan to capture and analize the can communication, and then create my own component for it.
The question is that this can adapter has two firmware options on this page:
https://www.tindie.com/products/lll7/can-usb-converter-uccb/
SocketCan GS_USB (Linux only)
and
Virtual COM Port (SLCAN)
I suppose I’ll have to buy it with Linux compatible firmware, but please someone confirm…

If it can be easily re-flashed, then I could do the development and debug on my PC, then change the firmware, and use it in Home Assistant…
Anyone has experience using this device?

regards, f

I was planning to buy this one : https://canable.io/

But no idea yet how to get the candump to HA … Need todo some reading first

Yeah, that seems good (especially the pro version, which is optically isolated). Unfortunately the shipping cost from USA to Hungary is 130 $… .So I ordered the one I mentioned before, from Tindie. It is not optically isolated, but I hope there won’t be any problem with it… It’s shipped from Poland, much cheaper.
There are a lot of interesting DIY stuff on Tindie by the way…

Will report how i’ts working, when arrives…

ok, keep us posted
how are you going to export those information to HA? whats your plan?

PS: you can also buy them from aliexpress , like 20€ include shipping

For CAN bus I recommend to use ESPHome: CAN bus — ESPHome

I am using the canable, i submitted a PR to HassOs, so the drivers can be loaded in kernel now,… If you use HassOs…

It’s a “cleaner” solution then esphome and mcp2515

@pergola.fabio thanks for the hint, I will have a look. Could you please share the link to the PR?

It’s already available since hass 6.0

Hi All!

Today I played a bit with the Basic(UCCB) can adapter.

I could get readings from the Stiebel WPL18 Cool heat pump, under windows, using a UCCBViewer 2.6.
There I had to set the speed to (20000 b/s) to get any values:

t50079600fe01000000
t3017c0017501320000
t301731000bc3050000

So the device seems OK - although I can’t decode the readings - yet.

I use home assistant on raspberry PI4. If I attach it to the PI, the device appears as a serial port.

And now I’m a bit lost about how shall I continue…
How to configure Home Assistant to utilize this, as a can bus adapter - if it’s possible at all?

Didn’t found any can bus related documentations about it - except the ESPhome - CAN sollution - which is quite well documented.

So the questions are:
1.) Is there a way to use natively the device as a “CAN gateway” - like the zigbee dongles or similar?
2) It would be nice, to have a method, to configure the heatpump’s registers, inputs, outputs to MQTT entities, that would be easily useable.
3.) Or do I have to write the whole communication from scratch? Tailoring together the information pieces found on the internet?

Regards, F

hi, if using HassOS, the drivers should be loaded, you can do a candump?
in my case , i use slcand driver, i need to modprobe it first in a python script

check in putty if drivers are loaded?

Home Assistant OS 6.5
installed can utils: (sudo apt-get gives: -bash: sudo: command not found)

apk add can-utils

the command:

candump any

gives nothing…

is the driver loaded? check with modprobe

try “lsmod” ?

i use slcan

image

no, they aren’t there in the list… Trying to restart the system, maybe that helps.
Meanwhile there was some kind of trouble in the heat pump communication, because it stopped making hot water. The pumps worked, but the water was cold… I restared, then everything seems working normal… maybe I made some unwanted communiction while testing…

So maybe I know wht’s the problem… I can access the container with SSH, not the host system. That’s why the sudo not working. And I have to install the can-utils package every time I reboot.

maybe I’ll try to flash another firmware to it. Maybe that will help…

Yes , indeed. , I add the requirements in my python script upon start HA… And I do a modprobe to load the kernel drivers in same script

well, I was trying some, and now shows the devices if i type ‘lsmod’
I tryed this step-by-step guide: http://pascal-walter.blogspot.com/2015/08/installing-lawicel-canusb-on-linux.html

I stuck at step 4
slcand -c -o -f -s0 -S115200 /dev/ttyACM1 slcan0
response:
ioctl TIOCSETD: Operation not permitted
Any ideas?

i dont think you can do it from the SSH terminal, its indeed not permitted
i do it from the host itself , from a script upon start

below are the prcesses i do in order

subprocess.call(['modprobe', 'can'])
subprocess.call(['modprobe', 'can_raw'])
subprocess.call(['modprobe', 'slcan'])

os.system("apk add /config/python_scripts/canutils.apk")
os.system("slcand -o -c -s4 /dev/ttyACM0 can0")
os.system("ifconfig can0 txqueuelen 1000")
os.system("ifconfig can0 up")

i manally downloaded the canutils.apk and placed in a folder, because if you do apk add canutls from host, it cant find the packaje, while it works from ssh addon
the ssh addon download other versions then host, seems canutils is not listed in the community alpine, thats why i point it manally

but do you use slcand?