From feaa161653a1828ab8fe935041c8d1ad10dbbf0b Mon Sep 17 00:00:00 2001 From: Roman Priesol Date: Fri, 4 Dec 2026 11:53:27 +0100 Subject: [PATCH] can-node-1/2: canopen_entities from mrk-its/esphome-canopen@canopen_entities --- mcu-can-node-1.yaml | 82 ++++++++++++++++----------------------------- mcu-can-node-2.yaml | 7 ++-- 2 files changed, 33 insertions(+), 56 deletions(-) diff --git a/mcu-can-node-1.yaml b/mcu-can-node-1.yaml index 227b754..bd1dc5e 100644 --- a/mcu-can-node-1.yaml +++ b/mcu-can-node-1.yaml @@ -24,9 +24,8 @@ esp32: type: esp-idf external_components: - - source: github://mrk-its/esphome-canopen@dev - refresh: 1h - - source: github://mrk-its/esphome-canbus-udp-multicast@dev + - source: github://mrk-its/esphome-canopen@canopen_entities + components: [canopen_entities] refresh: 1h packages: @@ -44,52 +43,22 @@ canopen: id: can_open canbus_id: can_bus node_id: 1 - entities: - - index: 1 - id: light1_state - rpdo: - - node_id: 2 - tpdo: 0 - offset: 0 - cmd: 0 - - index: 2 - id: light1_brightness - size: 1 - min_value: 0.0 - max_value: 1.0 - rpdo: - - node_id: 2 - tpdo: 0 - offset: 1 - cmd: 0 - - - index: 3 - id: light2_state - rpdo: - - node_id: 2 - tpdo: 0 - offset: 3 - cmd: 0 - - - index: 4 - id: light2_brightness - size: 1 - min_value: 0.0 - max_value: 1.0 - rpdo: - - node_id: 2 - tpdo: 0 - offset: 4 - cmd: 0 +canopen_entities: + remote_nodes: + node2: mcu-can-node-2.yaml binary_sensor: - - platform: template + - platform: canopen_entities id: light1_state name: Light 1 State - - platform: template + node: node2 + entity: light1 + - platform: canopen_entities id: light2_state name: Light 2 State + node: node2 + entity: light2 - platform: template id: light1_state_cmd @@ -105,26 +74,33 @@ binary_sensor: pullup: true on_press: then: - - lambda: |- - bool state = id(light1_state).state || id(light2_state).state; - - // send command to entity #1 (light) on node #2 - id(can_open).send_entity_cmd(2, 1, !state); - - // send command to entity #2 (light2) on node #2 - id(can_open).send_entity_cmd(2, 2, !state); + # 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: template + - platform: canopen_entities id: light1_brightness name: Light 1 Brightness - - platform: template + 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 - internal: true pin: 2 diff --git a/mcu-can-node-2.yaml b/mcu-can-node-2.yaml index ebcfab1..89ccccc 100644 --- a/mcu-can-node-2.yaml +++ b/mcu-can-node-2.yaml @@ -28,9 +28,8 @@ esp32: type: esp-idf external_components: - - source: github://mrk-its/esphome-canopen@dev - refresh: 1h - - source: github://mrk-its/esphome-canbus-udp-multicast@dev + - source: github://mrk-its/esphome-canopen@canopen_entities + components: [canopen_entities] refresh: 1h packages: @@ -48,6 +47,8 @@ canopen: id: can_open canbus_id: can_bus node_id: 2 + +canopen_entities: entities: - index: 1 id: light1