forked from lucize/esphome-jk-bms-can
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test-esp32-receiver-can.yaml
125 lines (115 loc) · 3.71 KB
/
test-esp32-receiver-can.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# Will receive CAN packets for SMA CAN protocol testing
esphome:
name: test-esp32-receiver-can.yaml
esp32:
board: esp32doit-devkit-v1
framework:
type: arduino
# type: esp-idf
# version: latest
# Enable logging
logger:
# Enable Home Assistant API
api:
ota:
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
canbus:
- platform: esp32_can
tx_pin: GPIO5
rx_pin: GPIO4
can_id: 4
bit_rate: 500kbps
on_frame:
- can_id: 0x351
then:
- lambda: |-
int val0 = int(x[0]);
int val1 = int(x[1]);
int val2 = int(x[2]);
int val3 = int(x[3]);
int val4 = int(x[4]);
int val5 = int(x[5]);
int val6 = int(x[6]);
int val7 = int(x[7]);
ESP_LOGI("main", "received can id: 0x351 hex: %x %x %x %x %x %x %x %x", val0, val1, val2, val3, val4, val5, val6, val7);
- can_id: 0x355
then:
- lambda: |-
int val0 = int(x[0]);
int val1 = int(x[1]);
int val2 = int(x[2]);
int val3 = int(x[3]);
int val4 = int(x[4]);
int val5 = int(x[5]);
ESP_LOGI("main", "received can id: 0x355 hex: %x %x %x %x %x %x", val0, val1, val2, val3, val4, val5);
- can_id: 0x356
then:
- lambda: |-
int val0 = int(x[0]);
int val1 = int(x[1]);
int val2 = int(x[2]);
int val3 = int(x[3]);
int val4 = int(x[4]);
int val5 = int(x[5]);
ESP_LOGI("main", "received can id: 0x356 hex: %x %x %x %x %x %x", val0, val1, val2, val3, val4, val5);
- can_id: 0x35A
then:
- lambda: |-
int val0 = int(x[0]);
int val1 = int(x[1]);
int val2 = int(x[2]);
int val3 = int(x[3]);
int val4 = int(x[4]);
int val5 = int(x[5]);
int val6 = int(x[6]);
int val7 = int(x[7]);
ESP_LOGI("main", "received can id: 0x35A hex: %x %x %x %x %x %x %x %x", val0, val1, val2, val3, val4, val5, val6, val7);
- can_id: 0x35E
then:
- lambda: |-
std::string b(x.begin(), x.end());
ESP_LOGI("main", "received can id: 0x35E ascii: %s", &b[0] );
- can_id: 0x00F
then:
- lambda: |-
int val0 = int(x[0]);
int val1 = int(x[1]);
int val2 = int(x[2]);
int val3 = int(x[3]);
int val4 = int(x[4]);
int val5 = int(x[5]);
int val6 = int(x[6]);
int val7 = int(x[7]);
ESP_LOGI("main", "received can id: 0x00F hex: %x %x %x %x %x %x %x %x", val0, val1, val2, val3, val4, val5, val6, val7);
sensor:
# Uptime sensor
- platform: uptime
name: ${name} Uptime Sensor
id: uptime_sensor
update_interval: 60s
on_raw_value:
then:
- text_sensor.template.publish:
id: uptime_human
state: !lambda |-
int seconds = round(id(uptime_sensor).raw_state);
int days = seconds / (24 * 3600);
seconds = seconds % (24 * 3600);
int hours = seconds / 3600;
seconds = seconds % 3600;
int minutes = seconds / 60;
seconds = seconds % 60;
return (
(days ? to_string(days) + "d " : "") +
(hours ? to_string(hours) + "h " : "") +
(minutes ? to_string(minutes) + "m " : "") +
(to_string(seconds) + "s")
).c_str();
text_sensor:
# Uptime Sensor
- platform: template
name: ${name} Uptime Human Readable
id: uptime_human
icon: mdi:clock-start