Files
esphome/tests/components/mcp2515/common.yaml
T
2026-10-11 09:12:28 -10:00

74 lines
2.1 KiB
YAML

canbus:
- platform: mcp2515
id: mcp2515_can
cs_pin: ${cs_pin}
can_id: 4
bit_rate: 50kbps
on_frame:
- can_id: 500
then:
- lambda: |-
std::string b(x.begin(), x.end());
ESP_LOGD("can_id 500", "%s", b.c_str());
- canbus.send:
canbus_id: mcp2515_can
can_id: 501
data: !lambda |-
return {static_cast<uint8_t>(can_id), x.empty() ? uint8_t(0) : x[0]};
- can_id: 23
then:
- if:
condition:
lambda: "return x[0] == 0x11;"
then:
logger.log: "x[0] == 0x11"
- can_id: 0b00000000000000000000001000000
can_id_mask: 0b11111000000000011111111000000
use_extended_id: true
then:
- lambda: |-
auto pdo_id = can_id >> 14;
switch (pdo_id)
{
case 117:
ESP_LOGD("canbus", "exhaust_fan_duty");
break;
case 118:
ESP_LOGD("canbus", "supply_fan_duty");
break;
case 119:
ESP_LOGD("canbus", "supply_fan_flow");
break;
// to be continued...
}
interval:
- interval: 1s
then:
- lambda: |-
auto status = id(mcp2515_can).get_status();
ESP_LOGD("canbus_status", "bus_off: %d, tx_err: %d, rx_err: %d",
status.bus_off,
status.tx_error_counter,
status.rx_error_counter
);
button:
- platform: template
name: MCP2515 Send
on_press:
# Identical on purpose: both sends share one constant payload
- canbus.send:
canbus_id: mcp2515_can
data: [0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88]
- canbus.send:
canbus_id: mcp2515_can
data: [0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88]
- canbus.send:
canbus_id: mcp2515_can
can_id: 0x123
data: "abc"
- canbus.send:
canbus_id: mcp2515_can
data: !lambda return {0x01, 0x02};