Serial sensor value transfer

Hello.
I have a distance sensor in my parking lot that measures the distance and sends it further using LoRa. The receiver is connected to a Wemos D1 Mini, which I connected to my Raspberry Pi using a USB cable. I would like to use the “Serial Sensor” to display the distance.

The “Serial Sensor” sensor also shows me the distance, but the “Distance” sensor does not. It always says unknown.

The Configuration.yaml looks like this:

sensor:
  - platform: serial
    serial_port: /dev/ttyUSB0
    baudrate: 9600


  - platform: template
    sensors:
      entfernung:
        friendly_name: "Entfernung"
        value_template: "{{ states.sensor.serial_port.state }}"
        device_class: distance

In Developer Tools → States, what is the state of sensor.serial_port ?


Try this instead:

  - platform: template
    sensors:
      entfernung:
        friendly_name: "Entfernung"
        value_template: "{{ states('sensor.serial_port')|int(0) }}"
        device_class: distance
        unit_of_measurement: m # or km, cm, mm, mi, yd, or in

Also see the warning box here: https://www.home-assistant.io/docs/configuration/templating/#states