Using CAN-Bus, Websocket, GPIO

The main question is: is there a way to use it without modifying the host system?

Meanwhile I flashed the device with different firmware (GS_USB), as described here: https://ucandevices.github.io/uccb.html#!#gs
(scroll down, under TOOLS, click GS_USB…)

After flashing, the serial port disappeared under windows (So I can’t flash it back… at least don’t know how…), but 2 new USB devices showed up, so the flashing seems successful.
After flashing it, I tryed in home assistant:
dmesg commad gives this:

...
[ 1742.559680] can: controller area network core
[ 1742.560388] NET: Registered protocol family 29
[ 1742.569021] can: raw protocol
[ 2193.179636] slcan: serial line CAN interface driver
[ 2193.179646] slcan: 10 dynamic interface channels.
[ 2567.733394] usb 1-1.3: USB disconnect, device number 5
[ 2581.594507] usb 1-1.3: new full-speed USB device number 7 using xhci_hcd
[ 2581.731697] usb 1-1.3: New USB device found, idVendor=1d50, idProduct=606f, bcdDevice= 0.00
[ 2581.731708] usb 1-1.3: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[ 2581.731716] usb 1-1.3: Product: UCCB USB to CAN adapter
[ 2581.731724] usb 1-1.3: Manufacturer: ucandevices.github.io
[ 2581.731731] usb 1-1.3: SerialNumber: 00260028564B431320373030
[ 2581.737712] gs_usb 1-1.3:1.0: Configuring for 1 interfaces
...

and
ip addr gives:

...
can0: <NOARP40000> mtu 16 qdisc noop state DOWN qlen 10
link/[280]

well, that’s where I’m now… I really don’t know where to start and what to do…
Also I’m not a really Linux guru…

i dont modify the host system… you can do it thouugh directly in HassOS, but its not needed
I just launch my python script as a custom component, so upon boot HA,it loads the modules in kernel and then i do a candump to a template sensor

see here, do this as test, place below in your sensor.yaml file , its all hardcoded, so chang the names afterwards :

  - platform: dobiss
  - platform: template
    sensors:
      dobiss:
        friendly_name: "dobiss state sensor"
        value_template: "dobiss"

shows up as picture below , for me those are all can messages

then in your custom_component folder, create a folder “dobiss”
2 files need to be there…

  1. manifest.json
{
  "domain": "dobiss",
  "name": "Dobiss integration",
  "documentation": "https://github.com/pergolafabio",
  "issue_tracker": "https://github.com/pergolafabio",
  "config_flow": false,
  "version": "0.0.1",
  "codeowners": [
    "@pergolafabio"
  ],
  "requirements": ["python-can"]
}

2 sensor.py

  • uncomment line 36 if you want , then you see data in your home assistant log file
  • line 49 , i install there canutils, download the canutils and make sure its in your folder, its needed, canutils is not part of the container, also dont change to “apk add canutils” it wont download it, you need to place it there manually
  • line 57 , make sure you create long lived token, i do a rest call to update the template sensor with curl

you probably need to change data offcourse, i do some substrings, its for my personal use… but the logger should give you already something normally?

import logging
import voluptuous as vol
import can
import subprocess
import os
import threading
import asyncio
import requests
import json

from homeassistant.components.sensor import (SensorEntity)

_LOGGER = logging.getLogger(__name__)


def setup_platform(hass, config, add_entities, discovery_info=None):
    _LOGGER.debug("Setting up Dobiss sensor.")


def set_attribute(sensor_name, attribute, value):
    response = requests.get(url_states + sensor_name, headers=headers)
    msg = json.loads(response.text)
    msg['attributes'][attribute] = value
    payload = json.dumps({'state':  msg['state'], 'attributes': msg['attributes']})
    requests.post(url_states + sensor_name, headers=headers, data=payload)
    
def background():
    bus = can.interface.Bus(bustype='socketcan', channel='can0', bitrate=125000)
    while True:
        message = bus.recv()
        #data = "[{}]".format(message.dlc)
        data = ""
        for i in range(0,message.dlc):
            data += " {:02X}".format(message.data[i])
        data = str(data.strip())
        #_LOGGER.warning(data)
        if not message.data.hex()[2:4] == "99":  ## 57 programma
            if not message.data.hex()[2:4] == "58":
                if not message.data.hex()[2:4] == "5b":
                    try:
                        set_attribute(sensor_name, message.data.hex()[2:6], str(message.data.hex()[6:8]))
                    except:
                        pass                

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")

url_states = "http://localhost:8123/api/states/"
sensor_name = "sensor.dobiss" 
headers = {
    'Authorization': 'YOURTOKENHERE',
    'content-type': 'application/json',
} 
t = threading.Thread(name='background', target=background)
t.start()

offcourse , its based on SLCAN , i had issues with gs_usb , i flashed back
if you use gs_usb, then the commands are different to bring it up

see here : Getting Started - CANable

also on this website, there is an updater , to flash vs gs_usb and slcand

I studied the suggested setup, but no luck. I cannot bring up the interface, even with modifying the code, using alternative init method…
So I decided to flash back the device with the original serial firmware. But no luck. The flash programmer didn’t recognized it under windows l. I see it in device manager, but can’t flash it. Also tried many driver change and reinstall, but no luck.
This device don’t have a boot, or reset pin either.

So the firmware is gs_usb on it now (I think it’s almost identical wit candlelight)

I’ll try to flash it back to original fw from Linux…

And what if you test it just on a Ubuntu system, does it work then?

Ah wait i remember I had flashing issues too, it was a wrong USB cable… Take another one… I had a cable that didn’t send data… You need one that sends power and data… Like a charging cable for an smartphone, that you can also use to transfer data

Well, I’ll give it a try on another linux. Good idea.
It is an usb dongle… no cable. Originaly flashed over usb (it has serial pins, but it should work over USB)
I’ll ask the manufacturer about the flashing… maybe.

I’ll have little time now, but I’ll inform You if there will be any progress.

1 Like

Yes, if you know the commands , you can use them also on HassOS, gs_usb should be easier tough , no cantools needed to bring up the interface, only the iplink… Part of niet-tools if I remember correctly…

But it gave issues for me when I restarted HA, while the OS was already loaded, so reverted back to Slcan

Okay, I could flash back the original FW (using a standard Linux Mint (ubuntu) PC)
Now I could bring up the interface, so seems the HA configs are OK.

But I cannot read any messages on the bus - checked on another PC too, using a monitoring proram - that worked before… So, I don’t know what is the situation now- I hope I didn’t blowed the device or something … Have to check it somehow…

At least the config works, and the device opens properly.

Do a candump? You can do it from the SSL addon, install first the APK for cantools

Okay, finally could do a candump, and see values arriving from my heatpump system… :slight_smile: Cheers
(The bitrate was wrong in the config… I had to use -s1 to configure it to 20k bus speed)

slcand -o -c -s1 /dev/ttyACM1 can0

So next task is to figure out how to interact with the stiebel eltron heatpump using this canbus connnection…

you could use a script, and then update a sensor with rest api on HA, thats how i do it, i have posted my custom component a few posts above , its based on a candump

I could set up the background task with the config that You gave above. I see the readings in the logs (I’ve uncommented the line 36, just to see it)
There were the readings, but I’ve noticed that the log was full with the same number of this message:

Login attempt or request with invalid authentication from localhost (::1). (python-requests/2.26.0)

I assume this is related somehow with the long lived. But I think I’ve set up that token properly … I’ve recreated a new token, but still gives the above warning messages, every time a can bus communication arrives…

Do You have any hint about this?

hi, as a test just remove the rest api where update the sensor, and enable the logger, see if you have the canbus data in your HA log file as warning, to see if the component actually works

like:


        _LOGGER.warning(data)

#remove all below
        if not message.data.hex()[2:4] == "99":  ## 57 programma
            if not message.data.hex()[2:4] == "58":
                if not message.data.hex()[2:4] == "5b":
                    try:
                        set_attribute(sensor_name, message.data.hex()[2:6], str(message.data.hex()[6:8]))
                    except:
                        pass

Okay, now only the data values appear in the log… So I suppose that I’ll have to write my own parser part to process the data, or tailor in an exsisting heatpump handler python script…

Thnaks for Your help so far!

That’s good, must be a small issue then when you want to update the sensor, maybe wrong bearer ? Or http instead of https

hello, can someone tell me what is the best way to read can bus in home assistant, I want to use it for daly BMS and for heat pump, I have home assistant running on odroid N2

Depends, I use a canable USB Stick to read the candump messages

thanks for quick answer.

i buy this one , you think it work or are there better?

https://nl.aliexpress.com/item/4000045445478.html?spm=a2g0o.order_list.order_list_main.50.21ef79d2E7gNjp&gatewayAdapt=glo2nld

I don’t immediately see an integration for can in HA, how did you use it? Python? do you have an example somewhere?

i bought myself this one, flashed it with SLcan

https://vi.aliexpress.com/item/1005004972158302.html?spm=a2g0n.order_detail.order_detail_item.3.1af1f19cCqSJhK&gatewayAdapt=glo2vnm

you can indeed use s python script read or write can messages

or use cantools

You need to make indeed a cstom script, since there are no cantools in HA