Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- substitutions:
- name: living-room-aircon
- friendly_name: Living Room Aircon
- esphome:
- name: ${name}
- friendly_name: ${friendly_name}
- esp32:
- board: esp32dev
- framework:
- type: esp-idf
- # debug:
- # update_interval: 10s
- # Enable logging
- logger:
- # Enable Home Assistant API
- api:
- # Allow Over-The-Air updates
- ota:
- - platform: esphome
- uart:
- id: my_uart
- baud_rate: 9600
- stop_bits: 2
- parity: NONE
- tx_pin:
- number: RX
- rx_pin:
- number: TX
- debug:
- direction: BOTH
- dummy_receiver: true
- sequence:
- - lambda: UARTDebug::log_string(direction, bytes);
- web_server:
- port: 80
- wifi:
- ssid: !secret wifi_ssid
- password: !secret wifi_password
- select:
- - id: change_baud_rate
- name: "Baud Rate"
- platform: template
- options:
- - "2400"
- - "9600"
- - "38400"
- - "57600"
- - "115200"
- - "256000"
- - "512000"
- - "921600"
- initial_option: "9600"
- optimistic: true
- restore_value: true
- entity_category: config
- icon: mdi:swap-horizontal
- set_action:
- - lambda: |-
- id(my_uart).flush();
- uint32_t new_baud_rate = stoi(x);
- ESP_LOGD("change_baud_rate", "Changing baud rate from %i to %i", id(my_uart).get_baud_rate(), new_baud_rate);
- if (id(my_uart).get_baud_rate() != new_baud_rate) {
- id(my_uart).set_baud_rate(new_baud_rate);
- id(my_uart).load_settings();
- }
- - id: change_stop_bits
- name: "Stop Bits"
- platform: template
- options:
- - "1"
- - "2"
- initial_option: "2"
- optimistic: true
- restore_value: true
- entity_category: config
- icon: mdi:swap-horizontal
- set_action:
- - lambda: |-
- uint8_t new_stop_bits = stoi(x);
- ESP_LOGD("change_stop_bits", "Changing stop bits from %i to %i", id(my_uart).get_stop_bits(), new_stop_bits);
- if (id(my_uart).get_stop_bits() != new_stop_bits) {
- id(my_uart).set_stop_bits(new_stop_bits);
- id(my_uart).load_settings();
- }
- - id: change_parity
- name: "Parity"
- platform: template
- options:
- - "NONE"
- - "ODD"
- - "EVEN"
- initial_option: "NONE"
- optimistic: true
- restore_value: true
- entity_category: config
- icon: mdi:swap-horizontal
- set_action:
- - lambda: |-
- UARTParityOptions new_parity;
- if (x == "NONE") {
- new_parity = UART_PARITY_NONE;
- } else if (x == "ODD") {
- new_parity = UART_PARITY_ODD;
- } else if (x == "EVEN") {
- new_parity = UART_PARITY_EVEN;
- } else {
- new_parity = UART_PARITY_NONE;
- }
- ESP_LOGD("change_parity", "Changing parity from %i to %i", id(my_uart).get_parity(), new_parity);
- if (id(my_uart).get_parity() != new_parity) {
- id(my_uart).set_parity(new_parity);
- id(my_uart).load_settings();
- }
- - id: change_tx_pin
- name: "TX Pin"
- platform: template
- options:
- - "GPIO1"
- - "GPIO3"
- initial_option: "GPIO1"
- optimistic: true
- restore_value: true
- entity_category: config
- icon: mdi:pin
- set_action:
- - lambda: |-
- // Expecting the option format "GPIO<number>"
- std::string pin_str(x.c_str());
- if (pin_str.find("GPIO") == 0) {
- int new_tx_pin = stoi(pin_str.substr(4));
- ESP_LOGD("change_tx_pin", "Changing TX pin to GPIO%i", new_tx_pin);
- id(my_uart).set_tx_pin(new InternalGPIOPin(new_tx_pin));
- id(my_uart).load_settings();
- }
- - id: change_rx_pin
- name: "RX Pin"
- platform: template
- options:
- - "GPIO1"
- - "GPIO3"
- initial_option: "GPIO3"
- optimistic: true
- restore_value: true
- entity_category: config
- icon: mdi:pin
- set_action:
- - lambda: |-
- // Expecting the option format "GPIO<number>"
- std::string pin_str(x.c_str());
- if (pin_str.find("GPIO") == 0) {
- int new_rx_pin = stoi(pin_str.substr(4));
- ESP_LOGD("change_rx_pin", "Changing RX pin to GPIO%i", new_rx_pin);
- id(my_uart).set_rx_pin(new InternalGPIOPin(new_rx_pin));
- id(my_uart).load_settings();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement