Files
esphome-configs/mcu-can-node-1.yaml
T
2026-12-05 13:59:12 +01:00

114 lines
2.6 KiB
YAML

---
# Hardware: ESP32 DevKit
# Pinout:
# GPIO0 -> Boot (binary_sensor gpio) (inverted)
# GPIO2 -> LED (switch gpio)
# GPIO22 -> can_bus (canbus esp32_can rx_pin)
# GPIO23 -> can_bus (canbus esp32_can tx_pin)
substitutions:
device: can-node-1
name: CAN Node 1
area: DEV
comment: CANopen
esphome:
name: mcu-${device}
friendly_name: ${name}
area: ${area}
comment: ${comment}
esp32:
variant: esp32
toolchain: esp-idf
framework:
type: esp-idf
external_components:
- source: github://mrk-its/esphome-canopen@canopen_entities
components: [canopen_entities]
refresh: 1h
packages:
common: !include common/common.yaml
logger:
logs:
# canbus logs every frame at DEBUG, which slows the loop during SDO block transfers
canbus: INFO
canbus:
- platform: esp32_can
id: can_bus
rx_pin: 22
tx_pin: 23
can_id: 1
bit_rate: 500kbps
# IDF default is 5 frames; an SDO block (16 segments in ~8 ms) overflowed it (EMCY 0x8110, partial block acks)
rx_queue_len: 32
canopen:
id: can_open
canbus_id: can_bus
node_id: 1
canopen_entities:
remote_nodes:
node2: mcu-can-node-2.yaml
binary_sensor:
- platform: canopen_entities
id: light1_state
name: Light 1 State
node: node2
entity: light1
- platform: canopen_entities
id: light2_state
name: Light 2 State
node: node2
entity: light2
- platform: template
id: light1_state_cmd
- platform: gpio
name: Boot
id: boot_button
pin:
number: 0
inverted: true
mode:
input: true
pullup: true
on_press:
then:
# both lights on node 2 off if either is on, otherwise both on
- if:
condition:
lambda: return id(light1_state).state || id(light2_state).state;
then:
- canopen_entities.light.turn_off: {node: node2, entity: light1}
- canopen_entities.light.turn_off: {node: node2, entity: light2}
else:
- canopen_entities.light.turn_on: {node: node2, entity: light1}
- canopen_entities.light.turn_on: {node: node2, entity: light2}
sensor:
- platform: canopen_entities
id: light1_brightness
name: Light 1 Brightness
node: node2
entity: light1
state: brightness
- platform: canopen_entities
id: light2_brightness
name: Light 2 Brightness
node: node2
entity: light2
state: brightness
switch:
- platform: gpio
name: LED
id: blue_led
pin: 2