Recently I was working on project for easy-exposing ESPHome entities to HomeAssistant over CANBus.
The project is splitted onto two parts: esphome-canopen external_component for converting ESPHome entities into CAN nodes and can2mqtt bridge exposing these CAN nodes to HomeAssistant through MQTT server. It follows MQTT discovery protocol, so ESPHome CAN entities appear automatically in HomeAssistant.
I started with my custom CAN protocol, but recenty I moved to CANopen standard. It should enable interesting features in near future, like mapping any existing CANopen devices into HomeAssistant entities.
esphome-canopen should work with any CAN Bus controller supported by ESPHome, like built-in ESP32 controller or external MCP2515 (on ESP32 or 8266 boards)
Example esphome config converting ESP32 gpio switch entity into CANopen device looks like:
Your message is just in time
I am developing my home automation system with a can bus in the house and your libraries are very interesting.
I followed the same path as you by developing my own protocol but I want to switch to a standard protocol.
On my side, the hardware part is working, I will be able to test the comm with the opencan protocol.
Do you try your lib with the can nodered ?
We stay in touch
On my side, the hardware part is working, I will be able to test the comm with the opencan protocol.
Great, let me know if you need any help!
Do you try your lib with the can nodered ?
No, Iām not using nodered - but my can2mqtt follows HomeAsssitant MQTT discovery protocol and these entities are discovered automatically by HA (and I hope they will by simply available in nodered if you have it integrated with HA). Let me know how it looks like on nodered.
great work, i use esphome-canopen together with can2mqtt and it works very well, but is it possible to use more then one sensor?
There is a htu21d connected to my ESP32 (temperature, humidity), if assign both entities to opencan then get an error at can2mqtt.
Yes. Single TPDO has 8 bytes and there is 4 TPDOs. Single sensor is 4-byte float, so it occupies the half of tpdo. Try different assignment of your sensors to TPDOs (i.e. put 2 sensors in separate tpdo)
I should prepare better documentation of it in README, will do.
For now:
binary sensor occupies 1 bytes of tpdo
sensor occupies 4 bytes of tpdo
cover occupies 2 bytes of tpdo (1 byte for position and 1 byte for state)
switch occupies 1 byte of tpdo
Regarding sensors: sometimes sensor should fit in single byte (for example underlying hardware returns single byte). Iām planning to implement optional mapping of float values to shorter integer types, to fit more of them in 4 TPDOs.
I am not familiar with canbus, that explains my mistake, thanks.
Is there a way to evaluate the birth message from homeassistant in can2mqtt and restart the app or create the entities again because they are no longer available after restarting homeassistant-server.
Very interesting project!. I have developped two custom board with esp32 and can bus inteface for home automation.
The first board is used as actuator and contains 4 relay ( 2 for roller shutter + 2 for light control), 2 MOSFET PWM output and 4 input optoisolated for alarms.
The second board contain an esp32 , can bus, 3.5 touch LCD, air quality sensor, temperature ant humidity sensor, motion detector sensor, pir and touch buttons.
Iām going to select the correct library/enviroment for developping the firmware and starting the test/debug the boards.
Iām looking with interest to your project but Iām not familiar with ESPHome and custom external component.
Let me know if you are intersted to collaborate I can share the project with you.
Let me know if you are intersted to collaborate I can share the project with you.
Sure! It looks esphome-canopen should be perfect for your project. I recommend joining our discord server: Discord, Iāll try to help with configuration
My house has a lift/elevator which uses CANopen as itās main bus. As Iām sure you can imagine, it would be awesome to be able to get some if the lift info in/out of HA and interfacing with the bus seems like the way forward. Iād like to be able to get the current floor, door status etc, and ideally call the lift to certain floors. I believe the lift may also send data relating to energy monitoring too.
Iāve got as far as the standard - CiA 417 which is the āApplication Profile for Lift Control Systemsā and I assume my lift uses this - though I will get more information from the manufacturer before I start further investigations (clearly there is a potential risk to people and property here I need to manage before fiddling with sending data on the bus).
Iām working on the basis that initially I can just read raw CAN packets via an ESP and CAN interface, and reverse engineer some of the data Iām looking for - e.g. check what packet is sent when I press a call button.
While things like the landing call buttons are documented in the standard, Iām guessing I may need to āfakeā the node that corresponds to the actual addressing of the call button nodes in my lift configuration.
On that basis, I think Iāll just have the ESP send/receive the full raw packets to MQTT and into Node-RED initially for experimentation. However in time I may be able to use your CANopen library to grab specific packets (e.g. current floor number) as a sensor for easy integration into HA.
You clearly have a more detailed understanding of CANopen then me - does this sound like the right approach?
Obviously I doubt many people here have lifts in their houses, but in time perhaps I can report back with some of the config Iām using in case it does happen to be useful for others. In theory there is a standard so that could be useful.
And if anyone else searching for ESP/ESPHome/HA/CANopen comes across this post and has a lift - get in touch and we can share notes!
What is the best way to gather data and control a CANopen piece of hardware through Home Assistant.
I am not sure if I am understanding the purpose of this project completely.
I am interested in data aquisition from a compressor that uses CANopen for its connection between the screen controller and the internal electronics. From what I have managed to workout is that it is possible to add another device on that CAN network and gather data as well as send commands.
How does CANopen and standard CAN Bus in ESPhome differ. I would like to ideally expose the CANopen device to MQTT so that it could integrate with HA and other systems through an MQTT broker.
What is the best way to gather data and control a CANopen piece of hardware through Home Assistant.
I am not sure if I am understanding the purpose of this project completely.
ESPHome-canopen works together with can2mqtt - first one allows to convert easily ESPHome-based devices into CANOpen nodes, second one knows how to map this kind of CANOpen devices to mqtt topics and exposes them this way to HA. But can2mqtt recognizes only these ESPHome-based devices, there is no support for external devices.
Such support can be added to can2mqtt of course, but it would require some effort and currently is not planned.
Could you please explain the interaction between the devices?
For example, I have 3 esp32 boards connected by can-bus.
The first board has sensors connected to it.
The second board has relays connected to it.
The third board has buttons and LEDs connected (or a touchscreen LCD, doesnāt matter).
This third board is the control board and displays the status of the first two boards (or rather, what is connected to them).
So basically I need a single space where I can āseeā sensors, LEDs, relays, etc. connected to them on any device, just as they would be seen as entities in HomeAssistant, but in this case without being connected to it.
Or am I misunderstanding the point of canopen and this is not the right component for me?
You can setup this with esphome-canopen.
Sensors on first board can be mapped to canopen node, their state will be broadcasted on CANBUS on change using āTPDOā canopen messages.
The same for relays - their state will be broadcasted on CANBUS on each change.
The third (controller) board can listen these broadcasts and update its local status of sensors / relays. It can also control remote entities (in your case relays on second board) by sending special TPDO message with the desired command.
You can optionally setup can2mqtt addon in your HA (you need to have some CAN interface supported by python-can) - and you will also see all these sensors / relays in HA (via CANBUS)
Take a look on can2mqtt code - for now it recognizes only esphome-canopen nodes, but after small changes you should be able to add support for other ones too.
I was even planning to add support for āmappingā some external CANOpen nodes, but I donāt have / use any, thatās why I stopped thinking about it.
If you want to work on that then ping me on Discord, maybe Iāll be able to help some way.
Thank you for this. Fortunately, the director of our company has fast tracked the replacement of the older compressor that was the CANopen device I was looking at connecting. So not an issue for now.