How to add a filter to text_sensor?

This is my (non-working) yaml:

text_sensor:

- platform: custom 
#/homeassistant/esphome/uart_read_line_sensor.h
  lambda: |-
    auto my_custom_sensor = new UartReadLineSensor(id(myUART23));
    App.register_component(my_custom_sensor);
    return {my_custom_sensor};
  text_sensors:
    -  id: "odb_tx"
       name: "OBD TX"
  filters:###############Red squiggly line here?
    - prepend: "TX="

- platform: custom
#/homeassistant/esphome/uart_read_line_sensor.h
  lambda: |-
    auto my_custom_sensor = new UartReadLineSensor(id(myUART18));
    App.register_component(my_custom_sensor);
    return {my_custom_sensor};
  text_sensors:  
    -  id: "obd_rx"
       name: "OBD RX"

This: Text Sensor Component doesn’t do it for me!
Regards, M.

What about indented like this:

  text_sensors:
    -  id: "odb_tx"
       name: "OBD TX"
       filters:
         - prepend: "TX="

Arrggh… I hate this yaml indenting - with a passion!
I had spent ages trying various combinations (honest).
Is there a (linux) IDE that can check this for me? A sort-of LINT for yaml?

Many thanks Tom.
PS - the Documentation I linked in post one has the “filters” at the platform level.

There’s the ESPHome add-on editor. It’s pretty good at pointing out errors.

Do you mean this one?

I don’t think so. Pretty sure they are always at the sensor level (same level as id:). Those examples are for template text sensors.

Just my point. Tabs to one level in one context, and at another in another context.
But thanks for pointing out that distinction for me.

Regards, M.

Yeah I recall being caught out a few times early on until I realised sensors can be nested in a bit sometimes (when the component supports multiple), and then you need to start from that level.

For some reason this note is above the filter section:

https://esphome.io/components/sensor/#sensor-filters
Screenshot 2024-02-04 at 18-07-44 Sensor Component

1 Like