Skip to content

Work in Progress. Control and read state of Tesvor X500 vacuum robot via esphome

Notifications You must be signed in to change notification settings

johkn/tesvor-x500-esphome-vacuum

Repository files navigation

To control and read the state of the Tesvor X500 vacuum robot via ESPHome, you can create an ESPHome configuration file (x500.yaml) that defines the commands and status queries. Additionally, you can extend Home Assistant's configuration.yaml to recognize the X500 as a vacuum robot. Here's how you can do it:

ESP Board.

1. ESPHome Configuration (x500.yaml)

This file will define the ESPHome configuration for the ESP12S module inside the Tesvor X500 vacuum robot. Here's an example configuration:

esphome:
  name: x500
  friendly_name: vacuum XY

esp8266:
  board: esp12e

logger:
  baud_rate: 0

ota:
  platform: esphome
  password: !secret ota_password

api:
  encryption:
    key: !secret api_password

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password

globals:
  - id: batdataglob
    type: short
    restore_value: true

uart:
  id: uart_bus
  tx_pin: 1
  rx_pin: 3
  baud_rate: 115200
  debug:
    direction: BOTH
    dummy_receiver: true
    after:
      delimiter: "\r\n"
    sequence:
      - lambda: |-
          UARTDebug::log_hex(direction, bytes, ' ');

          if (bytes.size() == 31) {
            switch (bytes[6]) {
              case 0x09:
                id(rawstate).publish_state("error");
                id(vacstate).publish_state("error");
                break;
              case 0x08:
                id(rawstate).publish_state("docked");
                id(vacstate).publish_state("docked");
                break;
              case 0x06:
                id(rawstate).publish_state("charging");
                id(vacstate).publish_state("docked");
                break;
              case 0x05:
                id(rawstate).publish_state("hibernated");
                id(vacstate).publish_state("idle");
                break;
              case 0x04:
                id(rawstate).publish_state("idle");
                id(vacstate).publish_state("idle");
                break;
              case 0x03:
                id(rawstate).publish_state("returning");
                id(vacstate).publish_state("returning");
                break;
              case 0x02:
                id(rawstate).publish_state("cleaning");
                id(vacstate).publish_state("cleaning");
                break;
            }

            if ((bytes[6] == 0x06) || (bytes[6] == 0x05) || (bytes[6] == 0x04) || (bytes[6] == 0x02)) {
              id(batdataglob) = bytes[29];
            }

            if (bytes[6] != 0x09) {
              id(errorstate).publish_state("no error");
            }
          }

          if (bytes[6] == 0x09) {
            switch (bytes[28]) {
              case 0x02:
                id(errorstate).publish_state("rolling brush blocked");
                break;
              case 0x04:
                id(errorstate).publish_state("wheels blocked");
                break;
              case 0x07:
                id(errorstate).publish_state("side brush blocked");
                break;
              case 0x09:
                id(errorstate).publish_state("front guard jammed");
                break;
            }
          }

text_sensor:
  - platform: template
    id: rawstate
    name: state
  - platform: template
    id: vacstate
    name: vacuum state    
  - platform: template
    id: errorstate
    name: error state

sensor:
  - platform: template
    name: battery
    id: batdata
    accuracy_decimals: 0
    lambda: return id(batdataglob);

button:
  - platform: template
    name: "Smart Cleaning"
    on_press:
      then:
        - uart.write: [0xAA, 0x03, 0x02, 0x22, 0x02, 0x26]
  - platform: template
    name: "Spot Cleaning"
    on_press:
      then:
        - uart.write: [0xAA, 0x03, 0x02, 0x22, 0x01, 0x25]
  - platform: template
    name: "Edge Cleaning"
    on_press:
      then:
        - uart.write: [0xAA, 0x03, 0x02, 0x22, 0x00, 0x24]
  - platform: template
    name: "Stop"
    on_press:
      then:
        - uart.write: [0xAA, 0x03, 0x02, 0x26, 0x00, 0x28]
  - platform: template
    name: "Go Charge"
    on_press:
      then:
        - uart.write: [0xAA, 0x03, 0x02, 0x22, 0x03, 0x27]
  - platform: template
    name: "Move Front"
    on_press:
      then:
        - uart.write: [0xAA, 0x03, 0x02, 0x21, 0x00, 0x23, 0xAA, 0x03, 0x02, 0x21, 0x04, 0x27]
  - platform: template
    name: "Move Back"
    on_press:
      then:
        - uart.write: [0xAA, 0x03, 0x02, 0x21, 0x03, 0x26, 0xAA, 0x03, 0x02, 0x21, 0x04, 0x27]
  - platform: template
    name: "Move Left"
    on_press:
      then:
        - uart.write: [0xAA, 0x03, 0x02, 0x21, 0x01, 0x24, 0xAA, 0x03, 0x02, 0x21, 0x04, 0x27]
  - platform: template
    name: "Move Right"
    on_press:
      then:
        - uart.write: [0xAA, 0x03, 0x02, 0x21, 0x02, 0x25, 0xAA, 0x03, 0x02, 0x21, 0x04, 0x27]

2. Home Assistant Configuration (configuration.yaml)

To allow Home Assistant to recognize and control the Tesvor X500 vacuum, you can extend the configuration.yaml file as follows:

vacuum:
  - platform: template
    vacuums:
      living_room_vacuum:
        value_template: "{{ states('sensor.x500_vacuum_state') }}"
        friendly_name: vacuum XY
        start:
          action: button.press
          target:
            entity_id: button.x500_smart_cleaning
        stop:
          action: button.press
          target:
            entity_id: button.x500_stop
        clean_spot:
          action: button.press
          target:
            entity_id: button.x500_spot_cleaning
        return_to_base:
          action: button.press
          target:
            entity_id: button.x500_go_charge

To-Do List

  1. Map: Integrate a mapping feature to display the cleaned area in the Home Assistant frontend.

Additional Resources

Feel free to ask for further assistance on specific parts of the configuration or integration!

About

Work in Progress. Control and read state of Tesvor X500 vacuum robot via esphome

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published