Conditionally executing http_request based on a lambda response

When I turn on a light, I’m trying to directly poll the state of another light, and send it a turn_on command if it’s currently turned off.

http_request:
  useragent: esphome/device
  timeout: 10s
  id: http_request_data

sensor:
  - platform: template
    id: remote_state

...

light:
  - platform: binary
    name: "Foyer Light"
    output: relay1
    id: light1
    on_turn_on:
      - http_request.get:
          url: http://192.168.0.21/light/foyer_light
          on_response:
            then:
              - lambda: |-
                  json::parse_json(id(http_request).get_string(), [](JsonObject root) {
                      id(remote_state).publish_state(root["state"]);
                  });
      - if:
          condition:
            text_sensor.state:
              id: remote_state
              state: 'OFF'
          then:
            - http_request.post: "http://192.168.0.21/light/foyer_light/turn_on"

This throws an error Unable to find condition with the name 'text_sensor.state'. I think I might be missing something terribly obvious with my indenting - is there a cleaner way to do this?

I think it’s probably because your sensor is defined as a sensor and not a text sensor (or another suitable type such as a binary sensor)

So you need to make the sensor and the condition the same type.

In ESPHome, sensors are numeric. Binary sensors are Boolean. Text sensors are… Text.