mrk-its / esphome-canopen

Apache License 2.0
24 stars 5 forks source link

ESPHome CANopen external component

This project provides ESPHome external_component named canopen for easy conversion of ESPHome entities into CANopen nodes. It allows to map selected entities to CANopen object dictionary. It also allows to define TPDOs for sending entity state on change. Currently following entity types are supported: sensor, number, binary_sensor, switch, cover and light. Entity metadata is also published in Object Dictionary enabling autodiscovery.

The can2mqtt project provides can2mqtt bridge exposing ESPHome CANopen entities onto MQTT topics. It follows MQTT Discovery protocol, so entities appear automatically in HomeAssistant.

How to start

Hardware requirements

Configure ESPHome with canopen external_component

Example configuration for esp32dev board:

  esphome:
    name: can-node-1

  external_components:
    - source: github://mrk-its/esphome-canopen

  # Enable logging
  logger:

  # Enable Home Assistant API
  api:
    password: ""
    reboot_timeout: 0s

  ota:
    password: ""

  esp32:
    board: esp32dev
    framework:
      type: arduino

  wifi:
    <<: !include {file: wifi.yaml}

  canbus:
    - platform: esp32_can
      id: can_bus
      rx_pin: GPIO22
      tx_pin: GPIO23
      can_id: 0
      bit_rate: 125kbps

  canopen:
    id: can_gate
    canbus_id: can_bus
    node_id: 1
    entities:
      - id: boot
        index: 1
        tpdo: 0
      - id: blue_led
        index: 2
        tpdo: 0
      - id: uptime_sensor
        index: 3
        tpdo: 0
      - id: cover1
        index: 4
        tpdo: 1
      - id: cover2
        index: 5
        tpdo: 1

  sensor:
    - platform: uptime
      id: uptime_sensor
      name: "Uptime 1"
      update_interval: 5sec
      internal: true

  binary_sensor:
    - platform: gpio
      name: "Boot 1"
      id: boot
      internal: true
      pin:
        number: 0
        inverted: true

  switch:
    - platform: gpio
      name: "Led 1"
      id: blue_led
      internal: true
      pin: 2

  cover:
    - platform: time_based
      name: "Cover 1"
      id: cover1
      internal: true
      device_class: shutter
      has_built_in_endstop: true
      open_action:
        - logger.log: open_action
      open_duration: 10s
      close_action:
        - logger.log: close_action
      close_duration: 10s
      stop_action:
        - logger.log: stop_action

Support

Community