ESPHome - multi switch loop

I am trying to use one switch to have two uses - as single on-off and a on-off-on-off.
The on-off works fine, but the on-off-on-off is in a loop and it keeps on switching - endlessly.
Here is the YAML code:
switch:

  • platform: gpio
    id: espresso
    pin:
    number: 5 #GPIO5 aka. D1
    inverted: false
    name: “Brew Espresso”
    icon: “mdi:coffee”
    restore_mode: RESTORE_DEFAULT_OFF
    on_turn_on:

    • switch.turn_on: espresso
    • delay: 500ms
    • switch.turn_off: espresso
  • platform: gpio
    id: espressoX2
    pin:
    number: 5 #GPIO5 aka. D1
    inverted: False
    name: “Brew Double Espresso”
    icon: “mdi:coffee”
    restore_mode: RESTORE_DEFAULT_OFF
    on_turn_on:

    • switch.turn_on: espressoX2
    • delay: 300ms
    • switch.turn_off: espressoX2
    • delay: 300ms
    • switch.turn_on: espressoX2
    • delay: 300ms
    • switch.turn_off: espressoX2

The resulting output looks like this:
[16:21:52][C][mdns:109]: Hostname: coffee-machine
[16:21:52][C][ota:093]: Over-The-Air Updates:
[16:21:52][C][ota:094]: Address: 192.168.1.xxx
[16:21:52][C][ota:097]: Using Password.
[16:21:52][C][api:138]: API Server:
[16:21:52][C][api:139]: Address: 192.168.1.yyy
[16:21:52][C][api:141]: Using noise encryption: YES
[16:21:54][D][api:102]: Accepted 192.168.1.xxx
[16:21:55][D][api.connection:961]: Home Assistant 2023.4.6 (192.168.1.xxx): Connected successfully
[16:22:45][D][switch:012]: ‘Brew Espresso’ Turning ON.
[16:22:45][D][switch:055]: ‘Brew Espresso’: Sending state ON
[16:22:45][D][switch:012]: ‘Brew Espresso’ Turning ON.
[16:22:46][D][switch:016]: ‘Brew Espresso’ Turning OFF.
[16:22:46][D][switch:055]: ‘Brew Espresso’: Sending state OFF

[16:23:00][D][switch:012]: ‘Brew Double Espresso’ Turning ON.
[16:23:00][D][switch:055]: ‘Brew Double Espresso’: Sending state ON
[16:23:00][D][switch:012]: ‘Brew Double Espresso’ Turning ON.
[16:23:01][D][switch:016]: ‘Brew Double Espresso’ Turning OFF.
[16:23:01][D][switch:055]: ‘Brew Double Espresso’: Sending state OFF
[16:23:01][D][switch:012]: ‘Brew Double Espresso’ Turning ON.
[16:23:01][D][switch:055]: ‘Brew Double Espresso’: Sending state ON
[16:23:01][D][switch:012]: ‘Brew Double Espresso’ Turning ON.
[16:23:01][D][switch:016]: ‘Brew Double Espresso’ Turning OFF.
[16:23:01][D][switch:055]: ‘Brew Double Espresso’: Sending state OFF
[16:23:01][D][switch:016]: ‘Brew Double Espresso’ Turning OFF.
[16:23:01][D][switch:012]: ‘Brew Double Espresso’ Turning ON.
[16:23:01][D][switch:055]: ‘Brew Double Espresso’: Sending state ON
[16:23:01][D][switch:012]: ‘Brew Double Espresso’ Turning ON.
[16:23:02][D][switch:016]: ‘Brew Double Espresso’ Turning OFF.
[16:23:02][D][switch:055]: ‘Brew Double Espresso’: Sending state OFF
[16:23:02][D][switch:016]: ‘Brew Double Espresso’ Turning OFF.
[16:23:02][D][switch:012]: ‘Brew Double Espresso’ Turning ON.
[16:23:02][D][switch:055]: ‘Brew Double Espresso’: Sending state ON
[16:23:02][D][switch:012]: ‘Brew Double Espresso’ Turning ON.
[16:23:02][D][switch:016]: ‘Brew Double Espresso’ Turning OFF.
[16:23:02][D][switch:055]: ‘Brew Double Espresso’: Sending state OFF
[16:23:02][D][switch:016]: ‘Brew Double Espresso’ Turning OFF.
[16:23:03][D][switch:012]: ‘Brew Double Espresso’ Turning ON.
[16:23:03][D][switch:055]: ‘Brew Double Espresso’: Sending state ON
[16:23:03][D][switch:012]: ‘Brew Double Espresso’ Turning ON.
[16:23:03][D][switch:016]: ‘Brew Double Espresso’ Turning OFF.
[16:23:03][D][switch:055]: ‘Brew Double Espresso’: Sending state OFF
[16:23:03][D][switch:016]: ‘Brew Double Espresso’ Turning OFF.
[16:23:03][D][switch:012]: ‘Brew Double Espresso’ Turning ON.
[16:23:03][D][switch:055]: ‘Brew Double Espresso’: Sending state ON
[16:23:03][D][switch:012]: ‘Brew Double Espresso’ Turning ON.
[16:23:04][D][switch:016]: ‘Brew Double Espresso’ Turning OFF.
[16:23:04][D][switch:055]: ‘Brew Double Espresso’: Sending state OFF
[16:23:04][D][switch:016]: ‘Brew Double Espresso’ Turning OFF.
[16:23:04][D][switch:012]: ‘Brew Double Espresso’ Turning ON.
[16:23:04][D][switch:055]: ‘Brew Double Espresso’: Sending state ON
[16:23:04][D][switch:012]: ‘Brew Double Espresso’ Turning ON.
[16:23:04][D][switch:016]: ‘Brew Double Espresso’ Turning OFF.
[16:23:04][D][switch:055]: ‘Brew Double Espresso’: Sending state OFF
[16:23:04][D][switch:016]: ‘Brew Double Espresso’ Turning OFF.
[16:23:05][D][switch:012]: ‘Brew Double Espresso’ Turning ON.
[16:23:05][D][switch:055]: ‘Brew Double Espresso’: Sending state ON
[16:23:05][D][switch:012]: ‘Brew Double Espresso’ Turning ON.
[16:23:05][D][switch:016]: ‘Brew Double Espresso’ Turning OFF.
[16:23:05][D][switch:055]: ‘Brew Double Espresso’: Sending state OFF
[16:23:05][D][switch:016]: ‘Brew Double Espresso’ Turning OFF.
[16:23:05][D][switch:012]: ‘Brew Double Espresso’ Turning ON.
[16:23:05][D][switch:055]: ‘Brew Double Espresso’: Sending state ON
[16:23:05][D][switch:012]: ‘Brew Double Espresso’ Turning ON.
[16:23:05][D][switch:016]: ‘Brew Double Espresso’ Turning OFF.
[16:23:05][D][switch:055]: ‘Brew Double Espresso’: Sending state OFF
[16:23:05][D][switch:016]: ‘Brew Double Espresso’ Turning OFF.
[16:23:06][D][switch:012]: ‘Brew Double Espresso’ Turning ON.
[16:23:06][D][switch:055]: ‘Brew Double Espresso’: Sending state ON
[16:23:06][D][switch:012]: ‘Brew Double Espresso’ Turning ON.
[16:23:06][D][switch:016]: ‘Brew Double Espresso’ Turning OFF.
[16:23:06][D][switch:055]: ‘Brew Double Espresso’: Sending state OFF
[16:23:06][D][switch:016]: ‘Brew Double Espresso’ Turning OFF.
[16:23:06][D][switch:012]: ‘Brew Double Espresso’ Turning ON.
[16:23:06][D][switch:055]: ‘Brew Double Espresso’: Sending state ON
[16:23:06][D][switch:012]: ‘Brew Double Espresso’ Turning ON.
[16:23:07][D][switch:016]: ‘Brew Double Espresso’ Turning OFF.
[16:23:07][D][switch:055]: ‘Brew Double Espresso’: Sending state OFF
[16:23:07][D][switch:016]: ‘Brew Double Espresso’ Turning OFF.
[16:23:07][D][switch:012]: ‘Brew Double Espresso’ Turning ON.
[16:23:07][D][switch:055]: ‘Brew Double Espresso’: Sending state ON
[16:23:07][D][switch:012]: ‘Brew Double Espresso’ Turning ON.
[16:23:07][D][switch:016]: ‘Brew Double Espresso’ Turning OFF.
[16:23:07][D][switch:055]: ‘Brew Double Espresso’: Sending state OFF
[16:23:07][D][switch:016]: ‘Brew Double Espresso’ Turning OFF.
[16:23:08][D][switch:012]: ‘Brew Double Espresso’ Turning ON.
[16:23:08][D][switch:055]: ‘Brew Double Espresso’: Sending state ON
[16:23:08][D][switch:012]: ‘Brew Double Espresso’ Turning ON.
[16:23:08][D][switch:016]: ‘Brew Double Espresso’ Turning OFF.
[16:23:08][D][switch:055]: ‘Brew Double Espresso’: Sending state OFF
[16:23:08][D][switch:016]: ‘Brew Double Espresso’ Turning OFF.
[16:23:08][D][switch:012]: ‘Brew Double Espresso’ Turning ON.
[16:23:08][D][switch:055]: ‘Brew Double Espresso’: Sending state ON
[16:23:08][D][switch:012]: ‘Brew Double Espresso’ Turning ON.
[16:23:09][D][switch:016]: ‘Brew Double Espresso’ Turning OFF.
[16:23:09][D][switch:055]: ‘Brew Double Espresso’: Sending state OFF
[16:23:09][D][switch:016]: ‘Brew Double Espresso’ Turning OFF.
[16:23:09][D][switch:012]: ‘Brew Double Espresso’ Turning ON.
[16:23:09][D][switch:055]: ‘Brew Double Espresso’: Sending state ON
[16:23:09][D][switch:012]: ‘Brew Double Espresso’ Turning ON.
[16:23:09][D][switch:016]: ‘Brew Double Espresso’ Turning OFF.
[16:23:09][D][switch:055]: ‘Brew Double Espresso’: Sending state OFF
[16:23:09][D][switch:016]: ‘Brew Double Espresso’ Turning OFF.
[16:23:09][D][switch:012]: ‘Brew Double Espresso’ Turning ON.
[16:23:09][D][switch:055]: ‘Brew Double Espresso’: Sending state ON
[16:23:09][D][switch:012]: ‘Brew Double Espresso’ Turning ON.
[16:23:10][D][switch:016]: ‘Brew Double Espresso’ Turning OFF.
[16:23:10][D][switch:055]: ‘Brew Double Espresso’: Sending state OFF
[16:23:10][D][switch:016]: ‘Brew Double Espresso’ Turning OFF.
[16:23:10][D][switch:012]: ‘Brew Double Espresso’ Turning ON.
[16:23:10][D][switch:055]: ‘Brew Double Espresso’: Sending state ON
[16:23:10][D][switch:012]: ‘Brew Double Espresso’ Turning ON.
[16:23:10][D][switch:016]: ‘Brew Double Espresso’ Turning OFF.
[16:23:10][D][switch:055]: ‘Brew Double Espresso’: Sending state OFF
[16:23:10][D][switch:016]: ‘Brew Double Espresso’ Turning OFF.
[16:23:11][D][switch:012]: ‘Brew Double Espresso’ Turning ON.
[16:23:11][D][switch:055]: ‘Brew Double Espresso’: Sending state ON
[16:23:11][D][switch:012]: ‘Brew Double Espresso’ Turning ON.
[16:23:11][D][switch:016]: ‘Brew Double Espresso’ Turning OFF.
[16:23:11][D][switch:055]: ‘Brew Double Espresso’: Sending state OFF
[16:23:11][D][switch:016]: ‘Brew Double Espresso’ Turning OFF.
[16:23:11][D][switch:012]: ‘Brew Double Espresso’ Turning ON.
[16:23:11][D][switch:055]: ‘Brew Double Espresso’: Sending state ON
[16:23:11][D][switch:012]: ‘Brew Double Espresso’ Turning ON.
[16:23:12][D][switch:016]: ‘Brew Double Espresso’ Turning OFF.
[16:23:12][D][switch:055]: ‘Brew Double Espresso’: Sending state OFF
[16:23:12][D][switch:016]: ‘Brew Double Espresso’ Turning OFF.
[16:23:12][D][switch:012]: ‘Brew Double Espresso’ Turning ON.
[16:23:12][D][switch:055]: ‘Brew Double Espresso’: Sending state ON
[16:23:12][D][switch:012]: ‘Brew Double Espresso’ Turning ON.
[16:23:12][D][switch:016]: ‘Brew Double Espresso’ Turning OFF.
[16:23:12][D][switch:055]: ‘Brew Double Espresso’: Sending state OFF
[16:23:12][D][switch:016]: ‘Brew Double Espresso’ Turning OFF.
[16:23:13][D][switch:012]: ‘Brew Double Espresso’ Turning ON.
[16:23:13][D][switch:055]: ‘Brew Double Espresso’: Sending state ON
[16:23:13][D][switch:012]: ‘Brew Double Espresso’ Turning ON.
[16:23:13][D][switch:016]: ‘Brew Double Espresso’ Turning OFF.
[16:23:13][D][switch:055]: ‘Brew Double Espresso’: Sending state OFF
[16:23:13][D][switch:016]: ‘Brew Double Espresso’ Turning OFF.
[16:23:13][D][switch:012]: ‘Brew Double Espresso’ Turning ON.
[16:23:13][D][switch:055]: ‘Brew Double Espresso’: Sending state ON
[16:23:13][D][switch:012]: ‘Brew Double Espresso’ Turning ON.
[16:23:13][D][switch:016]: ‘Brew Double Espresso’ Turning OFF.
[16:23:13][D][switch:055]: ‘Brew Double Espresso’: Sending state OFF
[16:23:14][D][switch:016]: ‘Brew Double Espresso’ Turning OFF.
[16:23:14][D][switch:012]: ‘Brew Double Espresso’ Turning ON.
[16:23:14][D][switch:055]: ‘Brew Double Espresso’: Sending state ON
[16:23:14][D][switch:012]: ‘Brew Double Espresso’ Turning ON.
[16:23:14][D][switch:016]: ‘Brew Double Espresso’ Turning OFF.
[16:23:14][D][switch:055]: ‘Brew Double Espresso’: Sending state OFF
[16:23:14][D][switch:016]: ‘Brew Double Espresso’ Turning OFF.
[16:23:14][D][switch:012]: ‘Brew Double Espresso’ Turning ON.
[16:23:14][D][switch:055]: ‘Brew Double Espresso’: Sending state ON
[16:23:14][D][switch:012]: ‘Brew Double Espresso’ Turning ON.
[16:23:15][D][switch:016]: ‘Brew Double Espresso’ Turning OFF.
[16:23:15][D][switch:055]: ‘Brew Double Espresso’: Sending state OFF
[16:23:15][D][switch:016]: ‘Brew Double Espresso’ Turning OFF.
Serial port closed!

And it does not get out of the "brew Double Espresso’ state, until I disconnect power.

WHAT am I missing here?

Well you’re definitely missing proper code formatting;)

on_multi_click

Well thank you Mahko for this real helpful input. There is nothing wrong with the formatting, it’s the website that does not cater for copy and paste.Sorry if it hurt your eyes!

Thanks a million, VDRainer. I have certainly overlooked and missed that option. Will test it out right away.

Actually it is helpful, because if you format your code properly as per the forum rules (which I took time to helpfully link you to, and tells you how to do it) then you are more likely to get help, because of the reasons the rule describes.

I initially came to help but was deterred by the code being too hard to read.

So format your code.

mando-way-mandalorian

1 Like