Esp32 doesn't toggle entitie

Hello,

i’m new to this all and have no experience programming but i try to get my first project to work.

I’m trying to build a display with an esp that has 3 icons, on pressing on one icon it should e.g toggle a light.

I got the display working, it shows my three icon and the first icon coordinates a programmed in. But when i tocuh the icon i get in the loggs it toggles the script but the lights don’t go on.

My Code:

esphome:
  name: esp32_tft_touch
  friendly_name: Arbeitszimmer Touchdisplay
  platformio_options:
    build_flags: "-DBOARD_HAS_PSRAM"

esp32:
  board: esp32dev
  framework:
    type: arduino

logger:

api:
  encryption:
    key: ""

ota:
  - platform: esphome
    password: ""

wifi:
  ssid: ""
  password: ""

spi:
  clk_pin: GPIO18
  mosi_pin: GPIO23
  miso_pin: GPIO19

display:
  - platform: ili9xxx
    model: ILI9341
    cs_pin: GPIO17
    dc_pin: GPIO4
    reset_pin: GPIO16
    rotation: 90
    invert_colors: false
    color_palette: 8bit
    update_interval: never
    id: tft_display
    data_rate: 20000000
    lambda: |-
      it.image(35, 30, id(icon_lamp));     // Links
      it.image(125, 30, id(icon_alarm));   // Mitte
      it.image(215, 30, id(icon_gaming));  // Rechts

touchscreen:
  - platform: xpt2046
    id: my_touchscreen
    cs_pin: GPIO13
    interrupt_pin: GPIO34
    update_interval: 50ms
    threshold: 400
    calibration:
      x_min: 200
      x_max: 3900
      y_min: 200
      y_max: 3900
    on_touch:
      then:
        - lambda: |-
            id(tft_display).update();
            int x = touch.x;
            int y = touch.y;

            ESP_LOGD("touch", "Touch coordinates: (%d, %d)", x, y);
            if (x > 196 && x < 286 && y > 170 && y < 217) {
            ESP_LOGD("touch", "Toggle Lamp Triggered");
            id(toggle_lamp).execute();
            } else {
            ESP_LOGD("touch", "Touch outside range: %d, %d", x, y);
            }


image:
  - file: "images/icon_lamp.bmp"
    id: icon_lamp
    type: RGB
  - file: "images/icon_alarm.bmp"
    id: icon_alarm
    type: RGB
  - file: "images/icon_gaming.bmp"
    id: icon_gaming
    type: RGB

script:
  - id: toggle_lamp
    then:
      - homeassistant.service:
          service: homeassistant.toggle
          data:
            entity_id: switch.licht_esszimmer

  - id: toggle_alarm
    then:
      - homeassistant.service:
          service: automation.toggle
          data:
            entity_id: automation.alarm_arbeitszimmer

  - id: toggle_gaming
    then:
      - homeassistant.service:
          service: homeassistant.toggle
          data:
            entity_id: switch.gaming

Logs after pressing the icon:

[10:47:55][D][xpt2046:055]: Touchscreen Update [2661, 3275], z = 1373
[10:47:55][D][touch:068]: Touch coordinates: (212, 199)
[10:47:55][D][touch:070]: Toggle Lamp Triggered
[10:47:55][W][component:239]: Component touchscreen took a long time for an operation (144 ms).
[10:47:55][W][component:240]: Components should block for at most 30 ms.
[10:47:55][D][xpt2046:055]: Touchscreen Update [2655, 3263], z = 1575
[10:47:56][D][touch:068]: Touch coordinates: (212, 198)
[10:47:56][D][touch:070]: Toggle Lamp Triggered
[10:47:56][W][component:239]: Component touchscreen took a long time for an operation (145 ms).
[10:47:56][W][component:240]: Components should block for at most 30 ms.
[10:47:57][D][xpt2046:055]: Touchscreen Update [2796, 3362], z = 958
[10:47:58][D][touch:068]: Touch coordinates: (224, 205)
[10:47:58][D][touch:070]: Toggle Lamp Triggered
[10:47:58][W][component:239]: Component touchscreen took a long time for an operation (145 ms).
[10:47:58][W][component:240]: Components should block for at most 30 ms.

Every help is needed :smiley:

Your log posted above doesn’t give any line for script execution.
You could add some print also inside your script for debugging.

Homeassistant.service has been replaced with .action on actual esphome documentation.

Replaced .service with .action but still nothing happens (same logs)

Add
- logger.log: Script is running
inside your script

Have you turned this option (top one) on in the esphome integration for the device ?

i get many errors when adding this line

script:
  - id: toggle_lamp
    then:
      - logger.log: Script is running
      - homeassistant.service:
          service: homeassistant.toggle
          data:
            entity_id: switch.licht_esszimmer

I feel so dumb right now, this was the error

I forget to do it all the time…