Use data from HA to switch on a led

Hi, I’m newbe in ESPHOME. I try to find in documentation how to use data comming from HA to automatize processes in ESP8266 board, but I don’t get throught :frowning: I’m triying to ope a switch if a value from HA sensore is below a value. Here’s the yaml I have at this point. Thanks in adevance !

sensor:
  - platform: homeassistant
    id: distanciaporta
    entity_id: sensor.sensor_distancia_2
    internal: true
    on_value_range:
      below: 1
      then:
        - switch.turn_off: led_rebedor

switch:
  - platform: gpio
    pin: GPIO3
    name: "led"
    id: led_rebedor
    restore_mode: ALWAYS_ON

Looks about right to me…

Can you see the HA sensor change in the ESPHOME logs? And does the switch work when triggered from HA?

Are you getting some error or particular unexpected behaviour?