diff --git a/esp-home-rewrite.yaml b/esp-home-rewrite.yaml index 2e1474a..ddeafb5 100644 --- a/esp-home-rewrite.yaml +++ b/esp-home-rewrite.yaml @@ -131,6 +131,20 @@ uart: # Uncomment to log raw Arduino traffic: # debug: # direction: BOTH + on_data: + - lambda: |- + for (uint8_t b : x) { + if (b == '\n') { + std::string &buf = id(uart_rx_buf); + if (!buf.empty() && buf.back() == '\r') buf.pop_back(); + if (!buf.empty() && buf != "OK" && buf != "PONG") { + id(arduino_last_message).publish_state(buf); + } + buf.clear(); + } else if (id(uart_rx_buf).size() < 128) { + id(uart_rx_buf) += static_cast(b); + } + } # --------------------------------------------------------------------------- # Connectivity diagnostics @@ -259,6 +273,11 @@ text_sensor: name: SSID entity_category: diagnostic + - platform: template + id: arduino_last_message + name: Arduino Last Message + entity_category: diagnostic + # --------------------------------------------------------------------------- # Gauge target numbers # --------------------------------------------------------------------------- @@ -702,11 +721,26 @@ button: id: arduino_uart data: "HOMEALL\n" +# --------------------------------------------------------------------------- +# Periodic auto-rezero +# --------------------------------------------------------------------------- + +interval: + - interval: ${rezero_interval} + then: + - uart.write: + id: arduino_uart + data: "HOMEALL\n" + # --------------------------------------------------------------------------- # Gauge light state cache # --------------------------------------------------------------------------- globals: + - id: uart_rx_buf + type: std::string + restore_value: no + initial_value: '""' - id: vfd_text_value type: std::string restore_value: no @@ -736,35 +770,35 @@ globals: restore_value: no initial_value: ${gauge3_min} - id: gauge0_speed_value - type: float + type: int restore_value: no initial_value: ${gauge0_default_speed} - id: gauge0_accel_value - type: float + type: int restore_value: no initial_value: ${gauge0_default_accel} - id: gauge1_speed_value - type: float + type: int restore_value: no initial_value: ${gauge1_default_speed} - id: gauge1_accel_value - type: float + type: int restore_value: no initial_value: ${gauge1_default_accel} - id: gauge2_speed_value - type: float + type: int restore_value: no initial_value: ${gauge2_default_speed} - id: gauge2_accel_value - type: float + type: int restore_value: no initial_value: ${gauge2_default_accel} - id: gauge3_speed_value - type: float + type: int restore_value: no initial_value: ${gauge3_default_speed} - id: gauge3_accel_value - type: float + type: int restore_value: no initial_value: ${gauge3_default_accel} - id: gauge0_bl_r