Advertisement
Guest User

Untitled

a guest
Mar 8th, 2025
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
YAML 4.77 KB | None | 0 0
  1. substitutions:
  2.   name: living-room-aircon
  3.   friendly_name: Living Room Aircon
  4.  
  5. esphome:
  6.   name: ${name}
  7.   friendly_name: ${friendly_name}
  8.  
  9. esp32:
  10.   board: esp32dev
  11.   framework:
  12.     type: esp-idf
  13.  
  14. # debug:
  15. #  update_interval: 10s
  16.  
  17. # Enable logging
  18. logger:
  19. # Enable Home Assistant API
  20. api:
  21. # Allow Over-The-Air updates
  22. ota:
  23. - platform: esphome
  24.  
  25. uart:  
  26.   id: my_uart
  27.   baud_rate: 9600
  28.   stop_bits: 2
  29.   parity: NONE
  30.   tx_pin:
  31.     number: RX
  32.   rx_pin:
  33.     number: TX    
  34.   debug:
  35.     direction: BOTH
  36.     dummy_receiver: true
  37.     sequence:
  38.       - lambda: UARTDebug::log_string(direction, bytes);
  39.  
  40. web_server:
  41.   port: 80
  42.  
  43. wifi:
  44.   ssid: !secret wifi_ssid
  45.   password: !secret wifi_password
  46.  
  47. select:
  48.   - id: change_baud_rate
  49.     name: "Baud Rate"
  50.     platform: template
  51.     options:
  52.       - "2400"
  53.       - "9600"
  54.       - "38400"
  55.       - "57600"
  56.       - "115200"
  57.       - "256000"
  58.       - "512000"
  59.       - "921600"
  60.     initial_option: "9600"
  61.     optimistic: true
  62.     restore_value: true
  63.     entity_category: config
  64.     icon: mdi:swap-horizontal
  65.     set_action:
  66.       - lambda: |-
  67.           id(my_uart).flush();
  68.           uint32_t new_baud_rate = stoi(x);
  69.           ESP_LOGD("change_baud_rate", "Changing baud rate from %i to %i", id(my_uart).get_baud_rate(), new_baud_rate);
  70.           if (id(my_uart).get_baud_rate() != new_baud_rate) {
  71.             id(my_uart).set_baud_rate(new_baud_rate);
  72.             id(my_uart).load_settings();
  73.           }
  74.  
  75.   - id: change_stop_bits
  76.     name: "Stop Bits"
  77.     platform: template
  78.     options:
  79.       - "1"
  80.       - "2"
  81.     initial_option: "2"
  82.     optimistic: true
  83.     restore_value: true
  84.     entity_category: config
  85.     icon: mdi:swap-horizontal
  86.     set_action:
  87.       - lambda: |-
  88.           uint8_t new_stop_bits = stoi(x);
  89.           ESP_LOGD("change_stop_bits", "Changing stop bits from %i to %i", id(my_uart).get_stop_bits(), new_stop_bits);
  90.           if (id(my_uart).get_stop_bits() != new_stop_bits) {
  91.             id(my_uart).set_stop_bits(new_stop_bits);
  92.             id(my_uart).load_settings();
  93.           }
  94.  
  95.   - id: change_parity
  96.     name: "Parity"
  97.     platform: template
  98.     options:
  99.       - "NONE"
  100.       - "ODD"
  101.       - "EVEN"
  102.     initial_option: "NONE"
  103.     optimistic: true
  104.     restore_value: true
  105.     entity_category: config
  106.     icon: mdi:swap-horizontal
  107.     set_action:
  108.       - lambda: |-
  109.           UARTParityOptions new_parity;
  110.           if (x == "NONE") {
  111.             new_parity = UART_PARITY_NONE;
  112.           } else if (x == "ODD") {
  113.             new_parity = UART_PARITY_ODD;
  114.           } else if (x == "EVEN") {
  115.             new_parity = UART_PARITY_EVEN;
  116.           } else {
  117.             new_parity = UART_PARITY_NONE;
  118.           }
  119.           ESP_LOGD("change_parity", "Changing parity from %i to %i", id(my_uart).get_parity(), new_parity);
  120.           if (id(my_uart).get_parity() != new_parity) {
  121.             id(my_uart).set_parity(new_parity);
  122.             id(my_uart).load_settings();
  123.           }  
  124.  
  125.   - id: change_tx_pin
  126.     name: "TX Pin"
  127.     platform: template
  128.     options:
  129.       - "GPIO1"
  130.       - "GPIO3"
  131.     initial_option: "GPIO1"
  132.     optimistic: true
  133.     restore_value: true
  134.     entity_category: config
  135.     icon: mdi:pin
  136.     set_action:
  137.       - lambda: |-
  138.           // Expecting the option format "GPIO<number>"
  139.           std::string pin_str(x.c_str());
  140.           if (pin_str.find("GPIO") == 0) {
  141.             int new_tx_pin = stoi(pin_str.substr(4));
  142.             ESP_LOGD("change_tx_pin", "Changing TX pin to GPIO%i", new_tx_pin);
  143.             id(my_uart).set_tx_pin(new InternalGPIOPin(new_tx_pin));
  144.             id(my_uart).load_settings();
  145.           }
  146.  
  147.   - id: change_rx_pin
  148.     name: "RX Pin"
  149.     platform: template
  150.     options:
  151.       - "GPIO1"
  152.       - "GPIO3"
  153.     initial_option: "GPIO3"
  154.     optimistic: true
  155.     restore_value: true
  156.     entity_category: config
  157.     icon: mdi:pin
  158.     set_action:
  159.       - lambda: |-
  160.           // Expecting the option format "GPIO<number>"
  161.           std::string pin_str(x.c_str());
  162.           if (pin_str.find("GPIO") == 0) {
  163.             int new_rx_pin = stoi(pin_str.substr(4));
  164.             ESP_LOGD("change_rx_pin", "Changing RX pin to GPIO%i", new_rx_pin);
  165.             id(my_uart).set_rx_pin(new InternalGPIOPin(new_rx_pin));
  166.             id(my_uart).load_settings();
  167.           }          
  168.  
  169.  
  170.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement