-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathDual R4850G on one CAN-BUS-MQTT_example.YAML
779 lines (695 loc) · 27 KB
/
Dual R4850G on one CAN-BUS-MQTT_example.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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
esphome:
name: can-bus01
friendly_name: can-bus01
esp32:
board: esp32dev
framework:
type: arduino
logger:
level: INFO
# This YAML file is optimised to run two R4850G units in parallel on the same CAN BUS. COMMUNICATION VIA MQTT.
# If you dont have or want to use Home assistant or do any automation, just need a simple web surface to
# control your R4875G1, just fill out your wifi credentials, uncomment this webs_server: section and
# comment out the "api:" section and the "mqtt:" section. and compile and upload bin to esp32
# using any PC: https://www.youtube.com/watch?v=BX6tDsux_X4
########
#web_server:
# version: 3
########
# Uncomment api: block if you are using Home Assistant
########
#api:
# encryption:
# key: "Np7EDGpTJZPZphuc+WA2vIt34DHI7hpXM9gPVnHOICg="
########
ota:
- platform: esphome
password: "afafd3c4bba9467b8f842f8d622f1435"
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: "Can-Bus01 Fallback Hotspot"
password: "Qjk3nwK8gpqw"
captive_portal:
# Uncomment this mqtt: block AND the mqtt block at the bottom of this file if you plan to use it. The status and control topics are shown in the Log also.
########
mqtt:
broker: !secret mqtt_host
username: !secret mqtt_username
password: !secret mqtt_password
id: mqtt_client
########
globals:
- id: amp_scaling_factor
type: int
initial_value: "20"
restore_value: true
- id: voltage_scaling_factor
type: int
initial_value: "1024"
restore_value: true
canbus:
- platform: esp32_can
tx_pin: GPIO19
rx_pin: GPIO21
can_id: 0xE5F32E5
bit_rate: 125kbps
use_extended_id: true
on_frame:
- can_id: 0x1081407F
use_extended_id: true
then:
- lambda: |-
if (x.size() >= 8) {
const uint8_t byte_0 = static_cast<uint8_t>(x[0]);
const uint8_t byte_1 = static_cast<uint8_t>(x[1]);
const uint32_t value = (static_cast<uint32_t>(x[4]) << 24) |
(static_cast<uint32_t>(x[5]) << 16) |
(static_cast<uint32_t>(x[6]) << 8) |
static_cast<uint32_t>(x[7]);
switch (byte_0) {
case 0x01:
switch (byte_1) {
case 0x70: id(ac_power_in_sensor1).publish_state(value); break;
case 0x71: id(grid_frequency_sensor1).publish_state(value); break;
case 0x72: id(input_current_sensor1).publish_state(value); break;
case 0x73: id(dc_power_out_sensor1).publish_state(value); break;
case 0x75: id(output_voltage_sensor1).publish_state(value); break;
case 0x76: id(set_max_output_current_sensor1).publish_state(value); break;
case 0x78: id(input_grid_voltage_sensor1).publish_state(value); break;
case 0x7F: id(output_temperature_sensor1).publish_state(value); break;
case 0x81: id(output_current_sensor1).publish_state(value); break;
}
break;
}
}
- can_id: 0x1001117E
use_extended_id: true
then:
- lambda: |-
if (x.size() == 8) {
// Extract the state byte (x[3]) and last four bytes for Wh
const uint8_t state_byte = x[3];
const uint32_t meter_value =
(static_cast<uint32_t>(x[4]) << 24) |
(static_cast<uint32_t>(x[5]) << 16) |
(static_cast<uint32_t>(x[6]) << 8) |
static_cast<uint32_t>(x[7]);
// Publish Power state and alt AMP values
id(alt_amp_sensor1).publish_state(meter_value);
id(power_state_sensor1).publish_state(state_byte == 0);
}
# Handle messages from the second device
- can_id: 0x1082407F
use_extended_id: true
then:
- lambda: |-
if (x.size() >= 8) {
const uint8_t byte_0 = static_cast<uint8_t>(x[0]);
const uint8_t byte_1 = static_cast<uint8_t>(x[1]);
const uint32_t value = (static_cast<uint32_t>(x[4]) << 24) |
(static_cast<uint32_t>(x[5]) << 16) |
(static_cast<uint32_t>(x[6]) << 8) |
static_cast<uint32_t>(x[7]);
switch (byte_0) {
case 0x01:
switch (byte_1) {
case 0x70: id(ac_power_in_sensor_device2).publish_state(value); break;
case 0x71: id(grid_frequency_sensor_device2).publish_state(value); break;
case 0x72: id(input_current_sensor_device2).publish_state(value); break;
case 0x73: id(dc_power_out_sensor_device2).publish_state(value); break;
case 0x75: id(output_voltage_sensor_device2).publish_state(value); break;
case 0x76: id(set_max_output_current_sensor_device2).publish_state(value); break;
case 0x78: id(input_grid_voltage_sensor_device2).publish_state(value); break;
case 0x7F: id(output_temperature_sensor_device2).publish_state(value); break;
case 0x81: id(output_current_sensor_device2).publish_state(value); break;
}
break;
}
}
- can_id: 0x1002117E
use_extended_id: true
then:
- lambda: |-
if (x.size() == 8) {
// Extract the state byte (x[3]) and last four bytes for Wh
const uint8_t state_byte = x[3];
const uint32_t meter_value =
(static_cast<uint32_t>(x[4]) << 24) |
(static_cast<uint32_t>(x[5]) << 16) |
(static_cast<uint32_t>(x[6]) << 8) |
static_cast<uint32_t>(x[7]);
// Publish Power state and alt AMP values
id(alt_amp_sensor2).publish_state(meter_value);
id(power_state_sensor2).publish_state(state_byte == 0);
}
time:
- platform: sntp
id: sntp_time
# Define sensors
# Define binary sensor for "ON/OFF" state
binary_sensor:
- platform: template
id: power_state_sensor1
name: "Charger Power State1"
device_class: power
- platform: template
id: power_state_sensor2
name: "Charger Power State2"
device_class: power
sensor:
- platform: template
name: "Output Current alt1"
id: alt_amp_sensor1
unit_of_measurement: "A"
accuracy_decimals: 1
filters:
- lambda: |-
return x / id(amp_scaling_factor);
icon: "mdi:current-dc"
- platform: template
name: "Output Current alt2"
id: alt_amp_sensor2
unit_of_measurement: "A"
accuracy_decimals: 1
filters:
- lambda: |-
return x / id(amp_scaling_factor);
icon: "mdi:current-dc"
- platform: template
name: "AC Power In1"
id: ac_power_in_sensor1
unit_of_measurement: "W"
accuracy_decimals: 2
filters:
- lambda: |-
return x / id(voltage_scaling_factor);
icon: "mdi:flash"
update_interval: 1s # Updates every second
- platform: template
name: "DC Power Out1"
id: dc_power_out_sensor1
unit_of_measurement: "W"
accuracy_decimals: 2
filters:
- lambda: |-
return x / id(voltage_scaling_factor);
icon: "mdi:flash"
update_interval: 1s # Updates every second
- platform: template
name: "Grid Frequency1"
id: grid_frequency_sensor1
unit_of_measurement: "Hz"
accuracy_decimals: 1
filters:
- lambda: |-
return x / id(voltage_scaling_factor);
icon: "mdi:transmission-tower-import"
- platform: template
name: "Input Current1"
id: input_current_sensor1
unit_of_measurement: "A"
accuracy_decimals: 1
filters:
- lambda: |-
return x / id(voltage_scaling_factor);
icon: "mdi:current-ac"
- platform: template
name: "Output Voltage1"
id: output_voltage_sensor1
unit_of_measurement: "V"
accuracy_decimals: 1
filters:
- lambda: |-
return x / id(voltage_scaling_factor);
icon: "mdi:current-dc"
- platform: template
name: "Input Grid Voltage1"
id: input_grid_voltage_sensor1
unit_of_measurement: "V"
accuracy_decimals: 2
filters:
- lambda: |-
return x / id(voltage_scaling_factor);
icon: "mdi:sine-wave"
- platform: template
name: "Output Temperature1"
id: output_temperature_sensor1
unit_of_measurement: "°C"
accuracy_decimals: 1
filters:
- lambda: |-
return x / id(voltage_scaling_factor);
icon: "mdi:thermometer"
on_value:
then:
- if:
condition:
lambda: 'return id(output_temperature_sensor1).state > 90.0;'
then:
- canbus.send:
use_extended_id: true
can_id: 0x108180FE
data: [1, 50, 0, 1, 0, 0, 0, 0]
- logger.log:
level: INFO
format: "Temperature exceeded 90°C. Sent CAN OFF message."
- platform: template
name: "Output Current1"
id: output_current_sensor1
unit_of_measurement: "A"
accuracy_decimals: 1
filters:
- lambda: |-
return x / id(voltage_scaling_factor);
icon: "mdi:current-dc"
- platform: template
name: "Set Max Output Current1"
id: set_max_output_current_sensor1
unit_of_measurement: "A"
accuracy_decimals: 1
filters:
- lambda: |-
return x / id(amp_scaling_factor);
icon: "mdi:current-ac"
- platform: template
name: "AC Power In2"
id: ac_power_in_sensor_device2
unit_of_measurement: "W"
accuracy_decimals: 2
filters:
- lambda: |-
return x / id(voltage_scaling_factor);
icon: "mdi:flash"
update_interval: 1s # Updates every second
# Combined AC Power sensor
- platform: template
name: "Combined AC Power"
id: combined_ac_power_sensor
unit_of_measurement: "kW"
accuracy_decimals: 2
filters:
- multiply: 0.001
update_interval: 1s # Updates every second
lambda: |-
return id(ac_power_in_sensor1).state + id(ac_power_in_sensor_device2).state;
icon: "mdi:flash"
- platform: template
name: "DC Power Out2"
id: dc_power_out_sensor_device2
unit_of_measurement: "W"
accuracy_decimals: 2
filters:
- lambda: |-
return x / id(voltage_scaling_factor);
icon: "mdi:flash"
update_interval: 1s # Updates every second
# Combined DC Power sensor
- platform: template
name: "Combined DC Power"
id: combined_dc_power_sensor
unit_of_measurement: "kW"
accuracy_decimals: 2
update_interval: 1s # Updates every second
filters:
- multiply: 0.001
lambda: |-
return id(dc_power_out_sensor1).state + id(dc_power_out_sensor_device2).state;
icon: "mdi:flash"
# Combined Daily AC Energy kWh sensor
- platform: total_daily_energy
name: "AC Power In Total (kWh)"
power_id: combined_ac_power_sensor
time_id: sntp_time
unit_of_measurement: "kWh"
accuracy_decimals: 3
icon: "mdi:counter"
# Combined Daily DC Energy kWh sensor
- platform: total_daily_energy
name: "DC Power Out Total (kWh)"
power_id: combined_dc_power_sensor
time_id: sntp_time
unit_of_measurement: "kWh"
accuracy_decimals: 3
icon: "mdi:counter"
- platform: template
name: "Grid Frequency2"
id: grid_frequency_sensor_device2
unit_of_measurement: "Hz"
accuracy_decimals: 1
filters:
- lambda: |-
return x / id(voltage_scaling_factor);
icon: "mdi:transmission-tower-import"
- platform: template
name: "Input Current2"
id: input_current_sensor_device2
unit_of_measurement: "A"
accuracy_decimals: 1
filters:
- lambda: |-
return x / id(voltage_scaling_factor);
icon: "mdi:current-ac"
- platform: template
name: "Output Voltage2"
id: output_voltage_sensor_device2
unit_of_measurement: "V"
accuracy_decimals: 1
filters:
- lambda: |-
return x / id(voltage_scaling_factor);
icon: "mdi:current-dc"
- platform: template
name: "Input Grid Voltage2"
id: input_grid_voltage_sensor_device2
unit_of_measurement: "V"
accuracy_decimals: 2
filters:
- lambda: |-
return x / id(voltage_scaling_factor);
icon: "mdi:sine-wave"
- platform: template
name: "Output Temperature2"
id: output_temperature_sensor_device2
unit_of_measurement: "°C"
accuracy_decimals: 1
filters:
- lambda: |-
return x / id(voltage_scaling_factor);
icon: "mdi:thermometer"
on_value:
then:
- if:
condition:
lambda: 'return id(output_temperature_sensor1).state > 90.0;'
then:
- canbus.send:
use_extended_id: true
can_id: 0x108280FE
data: [1, 50, 0, 1, 0, 0, 0, 0]
- logger.log:
level: INFO
format: "Temperature exceeded 90°C. Sent CAN OFF message."
- platform: template
name: "Output Current2"
id: output_current_sensor_device2
unit_of_measurement: "A"
accuracy_decimals: 1
filters:
- lambda: |-
return x / id(voltage_scaling_factor);
icon: "mdi:current-dc"
- platform: template
name: "Set Max Output Current2"
id: set_max_output_current_sensor_device2
unit_of_measurement: "A"
accuracy_decimals: 1
filters:
- lambda: |-
return x / id(amp_scaling_factor);
icon: "mdi:current-ac"
number:
- platform: template
name: "CAN Voltage Set"
id: can_voltage_input
min_value: 49
max_value: 58
step: 0.1
unit_of_measurement: "V"
optimistic: true
mode: BOX
restore_value: True
on_value:
then:
- lambda: |-
float voltage_value = id(can_voltage_input).state;
int scaled_value = (int)(voltage_value * id(voltage_scaling_factor));
ESP_LOGD("custom", "Received voltage: %.1fV, Scaled value: %d", voltage_value, scaled_value);
uint8_t high_byte = (scaled_value >> 8) & 0xFF;
uint8_t low_byte = scaled_value & 0xFF;
ESP_LOGI("custom", "Encoded CAN message: [0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x%02X, 0x%02X]", high_byte, low_byte);
- canbus.send:
use_extended_id: true
can_id: 0x108080FE
data: !lambda |-
std::vector<uint8_t> can_data(8, 0x00);
can_data[0] = 0x01;
int scaled_value = (int)(id(can_voltage_input).state * id(voltage_scaling_factor));
can_data[6] = (scaled_value >> 8) & 0xFF;
can_data[7] = scaled_value & 0xFF;
return can_data;
# Amp Setting
- platform: template
name: "CAN Amp Set"
id: can_amp_input
min_value: 1
max_value: 75 # Max value for the Amp input
step: 1 # 1 Amp steps
unit_of_measurement: "A"
optimistic: true
mode: BOX
restore_value: True
on_value:
then:
- lambda: |-
float amp_value = id(can_amp_input).state; // Get the current Amp value
int scaled_value = (int)(amp_value * id(amp_scaling_factor)); // Scale the Amp value
ESP_LOGD("custom", "Received Amp: %.1fA, Scaled value: %d", amp_value, scaled_value);
uint8_t high_byte = (scaled_value >> 8) & 0xFF;
uint8_t low_byte = scaled_value & 0xFF;
ESP_LOGI("custom", "Encoded CAN message: [0x01, 0x03, 0x00, 0x00, 0x00, 0x00, 0x%02X, 0x%02X]", high_byte, low_byte); // Log the CAN message data
- canbus.send:
use_extended_id: true
can_id: 0x108080FE
data: !lambda |-
std::vector<uint8_t> can_data(8, 0x00); // Initialize with 8 zeros
can_data[0] = 0x01; // First byte is always 0x01
can_data[1] = 0x03; // Second byte is 0x03
int scaled_value = (int)(id(can_amp_input).state * id(amp_scaling_factor)); // Scale the Amp value
can_data[6] = (scaled_value >> 8) & 0xFF; // Encode the high byte in the 7th byte
can_data[7] = scaled_value & 0xFF; // Encode the low byte in the 8th byte
return can_data;
# Fallback Amp Setting
- platform: template
name: "Fallback Amp Set"
id: fallback_amp_input
min_value: 1
max_value: 75 # Adjust as needed
step: 1 # 1A steps
unit_of_measurement: "A"
optimistic: true
mode: BOX
restore_value: True
on_value:
then:
- lambda: |-
float fallback_amp_value = id(fallback_amp_input).state; // Get the fallback Amp value
int fallback_scaled_value = (int)(fallback_amp_value * id(amp_scaling_factor)); // Scale the Amp value
ESP_LOGD("custom", "Fallback Amp: %.1fA, Scaled value: %d", fallback_amp_value, fallback_scaled_value);
uint8_t high_byte = (fallback_scaled_value >> 8) & 0xFF; // Get high byte
uint8_t low_byte = fallback_scaled_value & 0xFF; // Get low byte
ESP_LOGI("custom", "Encoded CAN message: [0x01, 0x04, 0x00, 0x00, 0x00, 0x00, 0x%02X, 0x%02X]", high_byte, low_byte); // Log the CAN message data
- canbus.send:
use_extended_id: true
can_id: 0x108080FE
data: !lambda |-
std::vector<uint8_t> can_data(8, 0x00); // Initialize with 8 zeros
can_data[0] = 0x01; // First byte is always 0x01
can_data[1] = 0x04; // Second byte is 0x04 for the Fallback Amps setting
int fallback_scaled_value = (int)(id(fallback_amp_input).state * id(amp_scaling_factor)); // Scale the Amp value
can_data[6] = (fallback_scaled_value >> 8) & 0xFF; // Encode the high byte in the 7th byte
can_data[7] = fallback_scaled_value & 0xFF; // Encode the low byte in the 8th byte
return can_data;
# Fallback Voltage Setting
- platform: template
name: "Fallback Voltage Set"
id: fallback_voltage_input
min_value: 49
max_value: 58 # Adjust as needed for your voltage range
step: 0.1 # 0.1V steps
unit_of_measurement: "V"
optimistic: true
mode: BOX
restore_value: True
on_value:
then:
- lambda: |-
float fallback_voltage_value = id(fallback_voltage_input).state; // Get the fallback voltage value
int fallback_scaled_value = (int)(fallback_voltage_value * id(voltage_scaling_factor)); // Scale the voltage value
ESP_LOGD("custom", "Fallback Voltage: %.1fV, Scaled value: %d", fallback_voltage_value, fallback_scaled_value);
uint8_t high_byte = (fallback_scaled_value >> 8) & 0xFF; // Get high byte
uint8_t low_byte = fallback_scaled_value & 0xFF; // Get low byte
ESP_LOGI("custom", "Encoded CAN message: [0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x%02X, 0x%02X]", high_byte, low_byte); // Log the CAN message data
- canbus.send:
use_extended_id: true
can_id: 0x108080FE
data: !lambda |-
std::vector<uint8_t> can_data(8, 0x00); // Initialize with 8 zeros
can_data[0] = 0x01; // First byte is always 0x01
can_data[1] = 0x01; // Second byte is 0x01 for the Fallback Voltage setting
int fallback_scaled_value = (int)(id(fallback_voltage_input).state * id(voltage_scaling_factor)); // Scale the voltage value
can_data[6] = (fallback_scaled_value >> 8) & 0xFF; // Encode the high byte in the 7th byte
can_data[7] = fallback_scaled_value & 0xFF; // Encode the low byte in the 8th byte
return can_data;
interval:
# Interval for sending the first CAN message every 30 seconds
- interval: 2s
then:
- canbus.send:
use_extended_id: true
can_id: 0x108040FE
data: [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]
# Interval for sending voltage CAN message every 30 seconds
- interval: 30s
then:
- canbus.send:
use_extended_id: true
can_id: 0x108080FE
data: !lambda |-
std::vector<uint8_t> can_data(8, 0x00); // Initialize with 8 zeros
can_data[0] = 0x01; // First byte is always 0x01
int scaled_value = (int)(id(can_voltage_input).state * id(voltage_scaling_factor)); // Scale the voltage value
can_data[6] = (scaled_value >> 8) & 0xFF; // Encode the high byte in the 7th byte
can_data[7] = scaled_value & 0xFF; // Encode the low byte in the 8th byte
return can_data;
# Interval for sending Amp setting CAN message every 10 seconds
- interval: 30s
then:
- canbus.send:
use_extended_id: true
can_id: 0x108080FE
data: !lambda |-
std::vector<uint8_t> can_data(8, 0x00); // Initialize with 8 zeros
can_data[0] = 0x01; // First byte is always 0x01
can_data[1] = 0x03; // Second byte is 0x03
int scaled_value = (int)(id(can_amp_input).state * id(amp_scaling_factor)); // Scale the Amp value
can_data[6] = (scaled_value >> 8) & 0xFF; // Encode the high byte in the 7th byte
can_data[7] = scaled_value & 0xFF; // Encode the low byte in the 8th byte
return can_data;
# Define a button component for turning ON
button:
- platform: template
name: "CAN ON Button"
on_press:
then:
- lambda: |-
ESP_LOGI("custom", "CAN ON Button pressed, sending message: [0x01, 0x32, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]");
- canbus.send:
use_extended_id: true
can_id: 0x108080FE
data: [0x01, 0x32, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]
# Define a button component for turning OFF
- platform: template
name: "CAN OFF Button"
on_press:
then:
- lambda: |-
ESP_LOGI("custom", "CAN OFF Button pressed, sending message: [0x01, 0x32, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00]");
- canbus.send:
use_extended_id: true
can_id: 0x108080FE
data: [0x01, 0x32, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00]
# Define a button component for setting the fan to full speed
- platform: template
name: "Fan Full Speed Button"
on_press:
then:
- lambda: |-
ESP_LOGI("custom", "Fan Full Speed Button pressed, sending message: [0x01, 0x34, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00]");
- canbus.send:
use_extended_id: true
can_id: 0x108080FE
data: [0x01, 0x34, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00]
# Define a button component for setting the fan to auto mode
- platform: template
name: "Fan Auto Mode Button"
on_press:
then:
- lambda: |-
ESP_LOGI("custom", "Fan Auto Mode Button pressed, sending message: [0x01, 0x34, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]");
- canbus.send:
use_extended_id: true
can_id: 0x108080FE
data: [0x01, 0x34, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]
###################################################################################################################################
##This Block must be added to enable voltage and currrent SET topics when using the mqtt: component
## Subscribe to MQTT topic to update CAN voltage
text_sensor:
- platform: mqtt_subscribe
name: "CAN Voltage MQTT"
id: mqtt_voltage_input
topic: "home/canbus/voltage_set"
internal: true # This makes the sensor internal
on_value:
then:
- delay: 0.01s # Small delay to ensure the value is properly updated
- lambda: |-
// Convert MQTT message to float
float mqtt_voltage = atof(x.c_str());
// Update the number input with the new value
if (mqtt_voltage >= 49.0 && mqtt_voltage <= 58.0) {
id(can_voltage_input).publish_state(mqtt_voltage);
ESP_LOGI("custom", "MQTT Voltage Set to: %.1fV", mqtt_voltage);
} else {
ESP_LOGW("custom", "Received out-of-range voltage value: %.1fV", mqtt_voltage);
}
# Subscribe to MQTT topic to update CAN amps
- platform: mqtt_subscribe
name: "CAN Amps MQTT"
id: mqtt_amp_input
topic: "home/canbus/amp_set"
internal: true # This makes the sensor internal
on_value:
then:
- delay: 0.01s # Small delay to ensure the value is properly updated
- lambda: |-
// Convert MQTT message to float
float mqtt_amp = atof(x.c_str());
// Update the number input with the new value
if (mqtt_amp >= 1.0 && mqtt_amp <= 75.0) {
id(can_amp_input).publish_state(mqtt_amp);
ESP_LOGI("custom", "MQTT Amp Set to: %.1fA", mqtt_amp);
} else {
ESP_LOGW("custom", "Received out-of-range amp value: %.1fA", mqtt_amp);
}
# Subscribe to MQTT topic to update Fallback Voltage
- platform: mqtt_subscribe
name: "Fallback Voltage MQTT"
id: mqtt_fallback_voltage
topic: "home/canbus/fallback_voltage_set"
internal: true # This makes the sensor internal
on_value:
then:
- delay: 0.01s # Small delay to ensure the value is properly updated
- lambda: |-
// Convert MQTT message to float
float fallback_voltage = atof(x.c_str());
// Update the number input with the new value
if (fallback_voltage >= 49.0 && fallback_voltage <= 58.0) {
id(fallback_voltage_input).publish_state(fallback_voltage);
ESP_LOGI("custom", "Fallback Voltage Set to: %.1fV", fallback_voltage);
} else {
ESP_LOGW("custom", "Received out-of-range fallback voltage value: %.1fV", fallback_voltage);
}
# Subscribe to MQTT topic to update Fallback Amps
- platform: mqtt_subscribe
name: "Fallback Amps MQTT"
id: mqtt_fallback_amp
topic: "home/canbus/fallback_amp_set"
internal: true # This makes the sensor internal
on_value:
then:
- delay: 0.01s # Small delay to ensure the value is properly updated
- lambda: |-
// Convert MQTT message to float
float fallback_amp = atof(x.c_str());
// Update the number input with the new value
if (fallback_amp >= 1.0 && fallback_amp <= 75.0) {
id(fallback_amp_input).publish_state(fallback_amp);
ESP_LOGI("custom", "Fallback Amps Set to: %.1fA", fallback_amp);
} else {
ESP_LOGW("custom", "Received out-of-range fallback amp value: %.1fA", fallback_amp);
}
##############################################################################################################################