Esphome gives false toggle commands (solved)

Hello Everybody,
I’m building a remote control for my HA system. I want to be able to switch on lights tv etc etc from my lazy chair. I made a little box with a esp32 wroom board, 8 push buttons, a display for temperature an one for time. The buttons have a pulldown resistor of 1.5k to ground and are powered with 3.3 volt. When I turn on power It starts giving random toggle commands on all switches… So I started disconnecting button’s etc. I even powerd the esp32 solo (nothing attached, just 5v usb cable). It keeps giving those commands so I guess I made some error in the programming of esphome.
I use a HP620 tinypc with HassOs 2023.11.03

esphome:
  name: afstandbediening-2
  friendly_name: Afstandbediening_2

esp32:
  board: esp32dev
  framework:
    type: arduino

# Enable logging
logger:

# Enable Home Assistant API
api:
  encryption:
    key: "++OgItpWQSQCCLu0pXkAaT4PT8EG9q2X6eiMYcdl5fc="

ota:
  password: "cdae413a49a107aa7b9cec63cd1cc18c"

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

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Afstandbediening-2"
    password: "wztrf9cFUNH7"

captive_portal:

sensor:
  - platform: homeassistant
    id: kamer_temperatuur
    entity_id: sensor.kamertemperatuur
    internal: true

time:
- platform: homeassistant
  id: my_time2   


display:
  - platform: tm1637
    id: tm1637_01
    clk_pin: GPIO13
    dio_pin: GPIO14
    inverted: true
    length: 4
    update_interval: 10s
    lambda: |-
        it.printf(2,"%.0f",id(kamer_temperatuur).state, "c");
  - platform: tm1637
    id: tm1637_02
    clk_pin: GPIO14
    dio_pin: GPIO13
    inverted: true
    length: 4
    update_interval: 500ms
    lambda: |-
        static int i = 0;
        i++;
        if ((i % 2) == 0)
          it.strftime("%H.%M", id(my_time2).now());
        else
          it.strftime("%H%M", id(my_time2).now());

binary_sensor:  
  - platform: gpio
    pin: GPIO27
    name: "Verlichting eettafel Toggle Button"
    on_press:
      then:
        - homeassistant.service:
            service: switch.toggle
            data:
              entity_id: switch.eettafellamp_eettafel

  - platform: gpio
    pin: GPIO25
    name: "Verlichting kamer Toggle Button"
    on_press:
      then:
        - homeassistant.service:
            service: switch.toggle
            data:
              entity_id: switch.huiskamer

  - platform: gpio
    pin: GPIO23
    name: "Verlichting LED Toggle Button"
    on_press:
      then:
        - homeassistant.service:
            service: switch.toggle
            data:
              entity_id: light.woonkamer_ws2812b_woonkamer_ws2812
  
  - platform: gpio
    pin: GPIO32
    name: "Fonteinen Toggle Button"
    on_press:
      then:
        - homeassistant.service:
            service: switch.toggle
            data:
              entity_id: switch.kikkers

  - platform: gpio
    pin: GPIO35
    name: "Ventilatoren Toggle Button"
    on_press:
      then:
        - homeassistant.service:
            service: switch.toggle
            data:
              entity_id: switch.ventilatoren_verwarming
===============================================================

part of the log:

INFO ESPHome 2023.11.4
INFO Reading configuration /config/esphome/afstandbediening-2.yaml…
INFO Detected timezone ‘Europe/Amsterdam’
INFO Starting log output from afstandbediening-2.local using esphome API
INFO Successfully connected to afstandbediening-2 in 0.124s
INFO Successful handshake with afstandbediening-2 in 0.161s
[10:11:21][I][app:102]: ESPHome version 2023.11.3 compiled on Nov 23 2023, 17:20:34
[10:11:21][C][wifi:559]: WiFi:
[10:11:21][C][wifi:391]: Local MAC: 24:62:AB:DC:A8:94
[10:11:21][C][wifi:396]: SSID: ‘Muziek’[redacted]
[10:11:21][C][wifi:397]: IP Address: 192.168.2.241
[10:11:21][C][wifi:399]: BSSID: 00:90:4C:1F:F0:1A[redacted]
[10:11:21][C][wifi:400]: Hostname: ‘afstandbediening-2’
[10:11:21][C][wifi:402]: Signal strength: -35 dB ▂▄▆█
[10:11:21][C][wifi:406]: Channel: 1
[10:11:21][C][wifi:407]: Subnet: 255.255.255.0
[10:11:21][C][wifi:408]: Gateway: 192.168.2.254
[10:11:21][C][wifi:409]: DNS1: 192.168.2.10
[10:11:21][C][wifi:410]: DNS2: 0.0.0.0
[10:11:21][D][homeassistant.sensor:024]: ‘sensor.kamertemperatuur’: Got state 16.94
[10:11:21][D][sensor:094]: ‘kamer_temperatuur’: Sending state 16.94000 with 1 decimals of accuracy
[10:11:21][C][logger:416]: Logger:
[10:11:21][C][logger:417]: Level: DEBUG
[10:11:21][C][logger:418]: Log Baud Rate: 115200
[10:11:21][C][logger:420]: Hardware UART: UART0
[10:11:22][C][gpio.binary_sensor:015]: GPIO Binary Sensor ‘Verlichting eettafel Toggle Button’
[10:11:22][C][gpio.binary_sensor:016]: Pin: GPIO27
[10:11:22][C][gpio.binary_sensor:015]: GPIO Binary Sensor ‘Verlichting kamer Toggle Button’
[10:11:22][C][gpio.binary_sensor:016]: Pin: GPIO25
[10:11:22][C][gpio.binary_sensor:015]: GPIO Binary Sensor ‘Verlichting LED Toggle Button’
[10:11:22][C][gpio.binary_sensor:016]: Pin: GPIO23
[10:11:22][D][binary_sensor:036]: ‘Verlichting eettafel Toggle Button’: Sending state ON
[10:11:22][D][binary_sensor:036]: ‘Fonteinen Toggle Button’: Sending state ON
[10:11:22][C][gpio.binary_sensor:015]: GPIO Binary Sensor ‘Fonteinen Toggle Button’
[10:11:22][C][gpio.binary_sensor:016]: Pin: GPIO32
[10:11:22][D][binary_sensor:036]: ‘Verlichting eettafel Toggle Button’: Sending state OFF
[10:11:22][D][binary_sensor:036]: ‘Ventilatoren Toggle Button’: Sending state ON
[10:11:22][C][gpio.binary_sensor:015]: GPIO Binary Sensor ‘Ventilatoren Toggle Button’
[10:11:22][C][gpio.binary_sensor:016]: Pin: GPIO35
[10:11:22][D][binary_sensor:036]: ‘Fonteinen Toggle Button’: Sending state OFF
[10:11:22][C][homeassistant.time:010]: Home Assistant Time:
[10:11:22][C][homeassistant.time:011]: Timezone: ‘CET-1CEST,M3.5.0,M10.5.0/3’
[10:11:22][D][binary_sensor:036]: ‘Ventilatoren Toggle Button’: Sending state OFF
[10:11:22][C][display.tm1637:138]: TM1637:
[10:11:22][C][display.tm1637:139]: Intensity: 7
[10:11:22][C][display.tm1637:140]: Inverted: 1
[10:11:22][C][display.tm1637:141]: Length: 4
[10:11:22][C][display.tm1637:142]: CLK Pin: GPIO13
[10:11:22][C][display.tm1637:143]: DIO Pin: GPIO14
[10:11:22][C][display.tm1637:144]: Update Interval: 10.0s
[10:11:22][C][display.tm1637:138]: TM1637:
[10:11:22][C][display.tm1637:139]: Intensity: 7
[10:11:22][C][display.tm1637:140]: Inverted: 1
[10:11:22][C][display.tm1637:141]: Length: 4
[10:11:22][C][display.tm1637:142]: CLK Pin: GPIO14
[10:11:22][C][display.tm1637:143]: DIO Pin: GPIO13
[10:11:22][C][display.tm1637:144]: Update Interval: 0.5s
[10:11:22][D][binary_sensor:036]: ‘Ventilatoren Toggle Button’: Sending state ON
[10:11:22][D][binary_sensor:036]: ‘Ventilatoren Toggle Button’: Sending state OFF
[10:11:22][C][captive_portal:088]: Captive Portal:
[10:11:22][D][binary_sensor:036]: ‘Verlichting eettafel Toggle Button’: Sending state ON
[10:11:22][C][mdns:115]: mDNS:
[10:11:22][C][mdns:116]: Hostname: afstandbediening-2
[10:11:22][D][binary_sensor:036]: ‘Verlichting eettafel Toggle Button’: Sending state OFF
[10:11:22][D][binary_sensor:036]: ‘Fonteinen Toggle Button’: Sending state ON
[10:11:22][C][ota:097]: Over-The-Air Updates:
[10:11:22][C][ota:098]: Address: afstandbediening-2.local:3232
[10:11:22][C][ota:101]: Using Password.
[10:11:22][W][ota:107]: Last Boot was an unhandled reset, will proceed to safe mode in 8 restarts
[10:11:22][D][binary_sensor:036]: ‘Fonteinen Toggle Button’: Sending state OFF
[10:11:22][C][api:139]: API Server:
[10:11:22][C][api:140]: Address: afstandbediening-2.local:6053
[10:11:22][C][api:142]: Using noise encryption: YES
[10:11:22][D][binary_sensor:036]: ‘Verlichting eettafel Toggle Button’: Sending state ON
[10:11:22][D][binary_sensor:036]: ‘Fonteinen Toggle Button’: Sending state ON
[10:11:22][C][homeassistant.sensor:030]: Homeassistant Sensor ‘kamer_temperatuur’
[10:11:22][C][homeassistant.sensor:030]: State Class: ‘’
[10:11:22][C][homeassistant.sensor:030]: Unit of Measurement: ‘’
[10:11:22][C][homeassistant.sensor:030]: Accuracy Decimals: 1
[10:11:22][C][homeassistant.sensor:031]: Entity ID: ‘sensor.kamertemperatuur’
[10:11:22][D][binary_sensor:036]: ‘Verlichting eettafel Toggle Button’: Sending state OFF
[10:11:22][D][binary_sensor:036]: ‘Ventilatoren Toggle Button’: Sending state ON
[10:11:22][D][binary_sensor:036]: ‘Verlichting eettafel Toggle Button’: Sending state ON
[10:11:22][D][binary_sensor:036]: ‘Fonteinen Toggle Button’: Sending state OFF
[10:11:22][D][binary_sensor:036]: ‘Verlichting eettafel Toggle Button’: Sending state OFF
[10:11:22][D][binary_sensor:036]: ‘Ventilatoren Toggle Button’: Sending state OFF
[10:11:22][D][homeassistant.sensor:024]: ‘sensor.kamertemperatuur’: Got state 17.00
[10:11:22][D][sensor:094]: ‘kamer_temperatuur’: Sending state 17.00000 with 1 decimals of accuracy
[10:11:23][D][binary_sensor:036]: ‘Verlichting eettafel Toggle Button’: Sending state ON
[10:11:23][D][binary_sensor:036]: ‘Fonteinen Toggle Button’: Sending state ON
[10:11:23][D][binary_sensor:036]: ‘Ventilatoren Toggle Button’: Sending state ON
[10:11:23][D][binary_sensor:036]: ‘Verlichting eettafel Toggle Button’: Sending state OFF
[10:11:23][D][binary_sensor:036]: ‘Fonteinen Toggle Button’: Sending state OFF
[10:11:23][D][binary_sensor:036]: ‘Ventilatoren Toggle Button’: Sending state OFF
[10:11:23][D][binary_sensor:036]: ‘Verlichting eettafel Toggle Button’: Sending state ON
[10:11:23][D][binary_sensor:036]: ‘Fonteinen Toggle Button’: Sending state ON
[10:11:23][D][binary_sensor:036]: ‘Verlichting eettafel Toggle Button’: Sending state OFF
[10:11:23][D][binary_sensor:036]: ‘Fonteinen Toggle Button’: Sending state OFF
[10:11:23][D][binary_sensor:036]: ‘Verlichting eettafel Toggle Button’: Sending state ON
[10:11:23][D][binary_sensor:036]: ‘Verlichting eettafel Toggle Button’: Sending state OFF
[10:11:23][D][binary_sensor:036]: ‘Verlichting eettafel Toggle Button’: Sending state ON
[10:11:23][D][binary_sensor:036]: ‘Ventilatoren Toggle Button’: Sending state ON
[10:11:23][D][binary_sensor:036]: ‘Fonteinen Toggle Button’: Sending state ON
[10:11:23][D][binary_sensor:036]: ‘Ventilatoren Toggle Button’: Sending state OFF
[10:11:23][D][binary_sensor:036]: ‘Verlichting eettafel Toggle Button’: Sending state OFF
[10:11:23][D][binary_sensor:036]: ‘Fonteinen Toggle Button’: Sending state OFF
[10:11:23][D][binary_sensor:036]: ‘Ventilatoren Toggle Button’: Sending state ON
[10:11:23][D][binary_sensor:036]: ‘Ventilatoren Toggle Button’: Sending state OFF
[10:11:23][D][binary_sensor:036]: ‘Verlichting eettafel Toggle Button’: Sending state ON
[10:11:23][D][binary_sensor:036]: ‘Fonteinen Toggle Button’: Sending state ON
[10:11:23][D][binary_sensor:036]: ‘Verlichting eettafel Toggle Button’: Sending state OFF
[10:11:23][D][binary_sensor:036]: ‘Fonteinen Toggle Button’: Sending state OFF
[10:11:24][D][binary_sensor:036]: ‘Verlichting eettafel Toggle Button’: Sending state ON
[10:11:24][D][binary_sensor:036]: ‘Fonteinen Toggle Button’: Sending state ON
[10:11:24][D][binary_sensor:036]: ‘Ventilatoren Toggle Button’: Sending state ON
[10:11:24][D][binary_sensor:036]: ‘Verlichting eettafel Toggle Button’: Sending state OFF
[10:11:24][D][binary_sensor:036]: ‘Fonteinen Toggle Button’: Sending state OFF
[10:11:24][D][binary_sensor:036]: ‘Ventilatoren Toggle Button’: Sending state OFF
[10:11:24][D][binary_sensor:036]: ‘Verlichting eettafel Toggle Button’: Sending state ON

and on and on…

Anybody a guess what’s going wrong?

Many boards have pins that go high or low during boot up.
You need to find a pinout diagram for your board with boot up pins listed too.

Try to use filter in binary_sensor:

    filters:
      - delayed_on: 50ms

to prevent flickering.

Another ideas: use bigger resistence like 4-7 kOm.
I prefer to use pullup and connect switches to group.
So far no issues with.

Thanks for the reactions! Problem is solved. WallyR gave the Hint! I only checked what pins I could use (ESP32 Pinout Reference: Which GPIO pins should you use? | Random Nerd Tutorials) and didn´t check what kind of pins it are. They are 'touch" pins. When I ran the esp32 without anything connected those pins are “floating” and I guess that gave a lot of false flipping. In the box 1 ground cable to halve of the buttons wasn’t soldered correctly which caused those pins to float. Everything works now correctly!