Using homeassistant switch in my ESP32 through ESPhome

Hi everyone,

i am trying to use my switch in homeassistant, which was created by ‘helpers’ in settings. It made basic switch with ’ entity id: input_boolean.info_na_esp '. I

have my ESP32 with LCD. Lcd is running great.

Everythng I want is, when I ‘switch ON’ my input_boolean.info_na_esp ’ switch, i want certain info about data I want and when I ‘switch OFF’ my input_boolean.info_na_esp ’ switch, i want different data to be shown.

Here is my ESP32 code:

platform: homeassistant
    id: teplotaKotel
    entity_id: sensor.tepelny_senzor_kotel_multisensor_temperature_0
    internal: true

binary_sensor:
  - platform: homeassistant
    id: ESP32switch
    name: "Just Temperature"
    entity_id: input_boolean.info_na_esp
    
# Example configuration entry
i2c:
  sda: GPIO21
  scl: GPIO22

display:
  - platform: lcd_pcf8574
    dimensions: 16x2
    address: 0x27
    update_interval: 3s
    lambda: |-
      static int i = 0;
      i++;
      if (id(ESP32switch).state) {
        it.printf(1,0,"Teplota Kotle:");
        it.printf(1,1,"%.2f", id(teplotaKotel).state);
      }else{
        it.printf(1,0,"KotelT: %.2f", id(teplotaKotel).state);
        
      } 

It’s is showing just 2-line text and if i turn off or turn on my HA switch, nothing happen.

I would like to know, how to make my switch in HA work with my ESPhome.

Thank you for your help.

Has this code been copied across incorrectly? Looks like you are missing some and the indentation looks off. It’s hard to help debug without the details being right.

It would also be helpful to post some ESPHome logs from when you toggle your switch.