ESPHome 'Home Assistant Text Sensor' help

I have a Home Assistant Text Sensor that is (for testing) getting the state of a Shelly and it is working as expected.

text_sensor:
  - platform: homeassistant
    name: "Test Text Sensor From Home Assistant"
    entity_id: switch.shelly1pm_e868e7860768
    id: test_state2

[14:29:29][C][homeassistant.text_sensor:023]: Homeassistant Text Sensor 'Test Text Sensor From Home Assistant'
[14:29:29][C][homeassistant.text_sensor:024]:   Entity ID: 'switch.shelly1pm_e868e7860768'
[14:29:36][D][homeassistant.text_sensor:017]: 'switch.shelly1pm_e868e7860768': Got state 'on'
[14:29:36][D][text_sensor:064]: 'Test Text Sensor From Home Assistant': Sending state 'on'
[14:29:38][D][homeassistant.text_sensor:017]: 'switch.shelly1pm_e868e7860768': Got state 'off'
[14:29:38][D][text_sensor:064]: 'Test Text Sensor From Home Assistant': Sending state 'off'

I want to use this state to turn on an LED and the docs say I can use all of the options from ‘Text Sensor’ in a ‘Home Assistant Text Sensor’. So a `text_sensor.state Condition’ should do what I want but I am getting an error that can’t work out.

Cannot have two actions in one item. Key 'if' overrides 'condition'!

What I have tried is straight from the Text Sensor docs.

switch:
  - platform: gpio
    name: "4B1 LED1"
    pin: GPIO4
    id: led1_4b1

text_sensor:
  - platform: homeassistant
    name: "Test Text Sensor From Home Assistant"
    entity_id: switch.shelly1pm_e868e7860768
    id: test_state2
    
    on_value:
      then:
        - if:
            condition:
              text_sensor.state:
                id: test_state2
                state: 'On'
            then:
              - switch.turn_on: led1_4b1
            else:
              - switch.turn_off: led1_4b1

Anyone have any idea what I’m doing wrong ??

Get rid of the first then.

Thanks for that, removing the first ‘then’ and fixing the indentation got rid of the error, it now works. I was sure I had tried all the combinations possible.

text_sensor:
  - platform: homeassistant
    name: "Test Text Sensor From Home Assistant"
    entity_id: switch.shelly1pm_e868e7860768
    id: test_state2

    on_value:
      - if:
          condition:
            text_sensor.state:
              id: test_state2
              state: 'On'
          then:
            - switch.turn_on: led1_4b1
          else:
            - switch.turn_off: led1_4b1

After a bit more playing and getting ideas from the forum I have the same thing working with a lambda.

  - platform: homeassistant
    name: "Text Sensor - Disable Garage Front Person"
    entity_id: automation.notification_garage_front
    id: disable_gf
    
    on_value:
      - if:
          condition:
            lambda: 'return x == "off";'
          then:
            - delay: 1000ms
            - output.turn_on: led2_4b1
          else:
            - delay: 1000ms
            - output.turn_off: led2_4b1

Finished project is here: https://community.home-assistant.io/t/wifi-switch-with-feedback/698966