ESP Devive sensor connected to host server via USB (no wifi)

Can a ESP Devive working as a sensor that’s connected to host (pi) via USB be registered to hass instead of from wifi?

I have a project that wemos d1 mini have to read a0 analog input non-stop which prevents it to connect wifi. I can see it’s returned sensor states via logs from usb connection to host. Which means it should be easily to show the values as a sensor in ESPHome but what is the way? Because it’s only possible to register esphome device from ip address.

Hey, it’s easy. Here how it’s done;
You disable logger and add uart configuration to your esp device;

logger:
  baud_rate: 0
uart:
  id: uart_bus
  tx_pin: GPIO1
  rx_pin: GPIO3
  baud_rate: 115200

Then send the value you wish to serial, here it’s the “state” of a sensor;

          std::string data_to_send = std::to_string(state) + "\r\n";
          Serial.print(data_to_send.c_str());

Then all there is left is to create a sensor that reads serial port, you add this to your configuration.yaml;

sensor:
  - platform: serial
    serial_port: /dev/ttyUSB0
    baudrate: 115200
    name: "your_sensor"

Never heard of that before.