How control esphome relay to HA sensors

I don’t understand how to get the information from HA to control the esphome relay. Could I get some help on how to use the two different patforms

esphome:
  name: esp-boiler

esp8266:
  board: nodemcuv2


# Enable logging
logger:

# Enable Home Assistant API
api:
  encryption:
    key: "7oGzmWzQVXQ8JNNmmgwO1fuT0RLFQL4F/nn0iSr9L6A="

ota:
  password: "f4bbe2147ae742b8a98107898bad8ff9"

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Esp-Boiler Fallback Hotspot"
    password: "hctNWB6MLhiA"

captive_portal:

binary_sensor:
  - platform: homeassistant
    name: "boiler high"
    entity_id: input_boolean.varaajan_lamporaja_high
    on_press:
      then:
        output:
          - platform: gpio
            pin:
              number: D3
              mode: output
            id: esp_boiler_Relay3
        interval:
          - interval: 25s
            then:
              - output.turn_on: esp_boiler_Relay3
              - delay: 2s
              - output.turn_off: esp_boiler_Relay3

When you add the esphome device to ha then ha creates a device and entities. You then interact with those entities just like any other.

Could you describe a little more what you want your code to do?
Do you want to turn on the relay for 2 seconds every 25s if your HA control is turned on?
I think some of your config may be misplaced.
You might want something more like this (untested).

binary_sensor:
#Import HA sensor.
  - platform: homeassistant
    name: "boiler high"
    entity_id: input_boolean.varaajan_lamporaja_high
    id: varaajan_lamporaja_high_ha

#Relay (Could also use a gpio switch) 
output:
  - platform: gpio
    pin:
      number: D3
      mode: output
    id: esp_boiler_Relay3
          
interval:
#Run relay for 2 seconds every 25s if your HA control is turned on.
  - interval: 25s
    then:
      - if:
          condition:
            binary_sensor.is_on: varaajan_lamporaja_high_ha
          then:
            - output.turn_on: esp_boiler_Relay3
            - delay: 2s
            - output.turn_off: esp_boiler_Relay3