Control extarnal Relay within ESPHome

How can I control a relay connected to HA from ESPHome? There are two nodes. One of them is ESP8266 and includes main software and the other one is a relay working with ESP01 which is intagreted to HA. In all the examples I have looked at, it is assumed that the relay is directly connected to the gpio of main ESP8266. Whereas, what I want to do is to control a separate relay integrated into HA from other ESPHome.

Here is my definition of climate control. Also i have an entity which is named switch.kombi_relay. I want to control this relay within climate control. What can i define in ESPHome and write correct sentences to switch.turn_on: and switch.turn_off: action?

climate:
  - platform: thermostat
    id: kombi
    name:  Thermostat
    sensor: oda_sicakligi_esp8266
    heat_deadband: 0.2
    heat_overrun: 0.2
    min_heating_off_time: 5s #300s
    min_heating_run_time: 5s #300s
    min_idle_time: 5s #30s
    heat_action:
      - switch.turn_on: xxxxx
      - lambda: |-
          id(Nextion_LCD).send_command_printf("vis flame,1");
    idle_action:
      - switch.turn_off: xxxxx
      - lambda: |-
          id(Nextion_LCD).send_command_printf("vis flame,0");
    on_state:
      - lambda: 'id(Nextion_LCD).set_component_text_printf("page0.target", "%.1f", id(kombi).target_temperature);'
    visual:
      min_temperature: 10
      max_temperature: 30
      temperature_step: 0.1

Best regard…

Assuming you are using the API rather than MQTT for the controlling device.

Thanks for your reply. I have reviewed this page before, but where do I specify the entity_id: switch.kombi_relay information? Can you give a small example based on the information I gave in my first message?

Best regards…

    heat_action:
      - homeassistant.service:
          service: homeassistant.turn_on
          data:
            entity_id: switch.kombi_relay
      - lambda: |-
          id(Nextion_LCD).send_command_printf("vis flame,1");
    idle_action:
      - homeassistant.service:
          service: homeassistant.turn_off
          data:
            entity_id: switch.kombi_relay
      - lambda: |-
          id(Nextion_LCD).send_command_printf("vis flame,0");

You know it is really bad form to keep asking the same question in multiple threads. This is your 3rd. You have already been given the same answer. Please stop.

@nickrout

This question I asked is not the same as other questions. I got stuck on the same project but on a different issue. This topic was about controlling another device, others were about setting the thermostat target temperature. And why did this bother you so much? You can ignore my messages if you don’t want to help.

@zoogara thank you for your help. The final version of the codes like this, maybe it will help others. Thank you again…

climate:
  - platform: thermostat
    id: kombi
    name:  Thermostat
    sensor: oda_sicakligi_esp8266
    heat_deadband: 0.3
    heat_overrun: 0.3
    min_heating_off_time: 5s #300s
    min_heating_run_time: 5s #300s
    min_idle_time: 5s #30s
    heat_action:
      - homeassistant.service:
          service: switch.turn_on
          data_template:
            entity_id: switch.kombi_relay
      - lambda: |-
          id(Nextion_LCD).send_command_printf("vis flame,1");
    idle_action:
      - homeassistant.service:
          service: switch.turn_off
          data_template:
            entity_id: switch.kombi_relay
      - lambda: |-
          id(Nextion_LCD).send_command_printf("vis flame,0");
    on_state:
      - lambda: 'id(Nextion_LCD).set_component_text_printf("page0.target", "%.1f", id(kombi).target_temperature);'
    visual:
      min_temperature: 10
      max_temperature: 30
      temperature_step: 0.1