Advertisement
tahc81

Untitled

Jan 10th, 2024
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
YAML 4.56 KB | None | 0 0
  1. esphome:
  2.   name: esp32-eltek-can
  3.  
  4. esp32:
  5.   board: wemos_d1_mini32
  6.   framework:
  7.     type: arduino
  8.  
  9. wifi:
  10.   networks:
  11.   - ssid: !secret wifi_ssid
  12.     password: !secret wifi_password
  13.  
  14. api:
  15. ota:
  16. logger:
  17.  
  18. globals:
  19.   - id: temp_inlet
  20.     type: int
  21.     restore_value: no
  22.     initial_value: '0'
  23.   - id: temp_outlet
  24.     type: int
  25.     restore_value: no
  26.     initial_value: '0'
  27.   - id: voltage_input
  28.     type: int
  29.     restore_value: no
  30.     initial_value: '0'
  31.   - id: voltage_output
  32.     type: float
  33.     restore_value: no
  34.     initial_value: '0'
  35.   - id: current_output
  36.     type: float
  37.     restore_value: no
  38.     initial_value: '0'
  39.   - id: serial_number
  40.     type: uint8_t[6]
  41.   - id: current_limiting
  42.     type: bool
  43.     initial_value: 'false'
  44.  
  45. web_server:
  46.   port: 80
  47.  
  48. canbus:
  49.   - platform: esp32_can
  50.     rx_pin: GPIO18
  51.     tx_pin: GPIO19
  52.     can_id: 1
  53.     id: eltek
  54.     use_extended_id: true
  55.     bit_rate: 125kbps
  56.     on_frame:
  57.     - can_id:     0  # listen to all messages
  58.       can_id_mask: 0
  59.       use_extended_id: true
  60.       then:
  61.         - lambda: |-
  62.             char buf[29];
  63.             // DGN
  64.             // Source Address (SA)
  65.             // Priority
  66.             // Data (8 bytes)
  67.             int dgn = (can_id >>8) & 0x1ffff;
  68.             int pri = (can_id >> 26) & 0b111;
  69.             int sa  = can_id & 0xff;
  70.             snprintf((char*)&buf, sizeof(buf), "%05X,%02X,%1X,%02X%02X%02X%02X%02X%02X%02X%02X", dgn, sa, pri, x[0], x[1], x[2], x[3], x[4], x[5], x[6], x[7]);
  71.             id(rvc_rx).publish_state((const char*)&buf);
  72.             ESP_LOGI("can", "%s", (const char*)&buf);
  73.  
  74. sensor:
  75.   - platform: template
  76.     id: eltek_temp_inlet
  77.     name: "Eltek inlet temperature"
  78.     device_class: temperature
  79.     unit_of_measurement: "°C"
  80.     accuracy_decimals: 0
  81.     update_interval: 1s
  82.     lambda: |-
  83.       return (id(temp_inlet));
  84.   - platform: template
  85.     id: eltek_temp_outlet
  86.     name: "Eltek outlet temperature"
  87.     device_class: temperature
  88.     unit_of_measurement: "°C"
  89.     accuracy_decimals: 0
  90.     update_interval: 1s
  91.     lambda: |-
  92.       return (id(temp_outlet));
  93.   - platform: template
  94.     id: eltek_voltage_input
  95.     name: "Eltek voltage input"
  96.     device_class: voltage
  97.     unit_of_measurement: "V"
  98.     accuracy_decimals: 0
  99.     update_interval: 1s
  100.     lambda: |-
  101.       return (id(voltage_input));
  102.   - platform: template
  103.     id: eltek_voltage_output
  104.     name: "Eltek voltage output"
  105.     device_class: voltage
  106.     unit_of_measurement: "V"
  107.     accuracy_decimals: 2
  108.     update_interval: 1s
  109.     lambda: |-
  110.       return (id(voltage_output));
  111.   - platform: template
  112.     id: eltek_cell_voltage
  113.     name: "Eltek cell voltage (13S Li-ion)"
  114.     device_class: voltage
  115.     unit_of_measurement: "V"
  116.     accuracy_decimals: 2
  117.     update_interval: 1s
  118.     lambda: |-
  119.       return (id(voltage_output) / 13);
  120.   - platform: template
  121.     id: eltek_current_output
  122.     name: "Eltek current output"
  123.     device_class: current
  124.     unit_of_measurement: "A"
  125.     accuracy_decimals: 2
  126.     update_interval: 1s
  127.     lambda: |-
  128.       return (id(current_output));
  129.   - platform: template
  130.     id: eltek_power_output
  131.     name: "Eltek power output"
  132.     device_class: power
  133.     unit_of_measurement: "W"
  134.     accuracy_decimals: 2
  135.     update_interval: 1s
  136.     lambda: |-
  137.       return (id(current_output) * id(voltage_output));
  138.  
  139. number:
  140.   - platform: template
  141.     id: eltek_voltage
  142.     name: "Eltek FP2 voltage"
  143.     device_class: voltage
  144.     unit_of_measurement: "V"
  145.     update_interval: 5s
  146.     restore_value: true
  147.     min_value: 44.50
  148.     max_value: 57.60
  149.     step: 0.1
  150.     optimistic: true
  151.     mode: box
  152.          
  153.   - platform: template
  154.     id: eltek_current
  155.     name: "Eltek FP2 current"
  156.     device_class: current
  157.     unit_of_measurement: "A"
  158.     update_interval: 5s
  159.     restore_value: true
  160.     min_value: 0.10
  161.     max_value: 41.70
  162.     step: 0.1
  163.     optimistic: true
  164.     mode: box
  165.  
  166. switch:
  167.   - platform: restart
  168.     name: "ESPhome Eltek FP2 restart"
  169.  
  170. binary_sensor:
  171.   - platform: template
  172.     name: "Current limiting active"
  173.     lambda: |-
  174.       if (id(current_limiting)) {
  175.         return true;
  176.       } else {
  177.         return false;
  178.       }
  179.  
  180. text_sensor:
  181.   - platform: wifi_info
  182.     ip_address:
  183.       name: ESP IP Address
  184.     ssid:
  185.       name: ESP Connected SSID
  186.  
  187.   - platform: template
  188.     name: "Flatpack2 temperatures"
  189.     lambda: |-
  190.       char buf[200];
  191.       sprintf(buf, "%.0f°C / %.0f°C", id(eltek_temp_inlet).state, id(eltek_temp_outlet).state);
  192.       return (std::string) buf;
  193.     update_interval: 1s
  194.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement