esphome / feature-requests

ESPHome Feature Request Tracker
https://esphome.io/
417 stars 26 forks source link

esp32 can dbc based sensor config #1607

Open lein1013 opened 2 years ago

lein1013 commented 2 years ago

Describe the problem you have/What new integration you would like

With the canbus component can messages can be read. In the doc there is no information, how to handles several signals within a message. Usually the messages and signals (incl types and scaling) are defined in a dbc file Using https://pypi.org/project/cantools/ these files could be opened and used to get the message id and the correct scaling for code generation.

proposal for yaml for e.g Tesla dbc

# Example configuration entry
canbus:
  - platform: esp32_can
    tx_pin: GPIO1
    rx_pin: GPIO3
    bit_rate: 500kbps 
    - name: tesla_speed
      friendly_name: "Tesla Vehicle Speed"
      can_message: DI_torque2  # BO_ 280 DI_torque2: 6 DI
      can_signal: DI_vehicleSpeed   #  SG_ DI_vehicleSpeed : 16|12@1+ (0.05,-25) [-25|179.75] "MPH" NEO
      # maybe add here a lambda to change to kph

    - name: tesla_temp_insd
      friendly_name: "Tesla Air Temperature Insid"
      can_message: BODY_R1
      can_signal: AirTemp_Insd  # SG_ AirTemp_Insd : 47|8@0+ (0.25,0) [0|63.5] "C"  NEO
      measurement_unit: "°C" # change unit

for different vehicles dbcs are already available - see https://github.com/commaai/opendbc

The idea is to provide the dbc and use directly the signal name in the esphome yaml config (no problems with ids and scaling)

For code generation https://github.com/howerj/dbcc could be considered.

Please describe your use case for this integration and alternatives you've tried:

The usecase would be to have a esphome directly connected via the vehicle OBD interface. As soon the vehicle connects to the wifi at home the vehicle states and precense are published to the homeassistant.

Another use case is when Home Assistant is used in a camper/ mobile home (battery state, water level, vehicle speed, position,...).

Additional context

related projects online:

clowrey commented 1 week ago

This would be really awesome if someone wanted to take it on!