ESP physical push buttons

I would like to share my last project.
I made 4 physical buttons with ESPHome, one for everyone in the house. I have built this into various things


These have different functions, 1x click, 2x click, …
They also have the ability to hold and dim.
The LED in the button comes on when it gets dark outside and also gives feedback about how many times the button was pressed.
This is the code for ESPHome:

esphome:
  name: knop_giel
  platform: ESP8266
  board: nodemcuv2

wifi:
  ssid: "xxxxxxxxxxxx"
  password: "xxxxxxxxxxxxx"

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Knop Giel Fallback Hotspot"
    password: "xxxxxxxxxxx"

captive_portal:

# Enable logging
logger:

# Enable Home Assistant API
api:
  password: "xxxxxxxxxxxxx"

ota:
  password: "xxxxxxxxxxxxxx"

output:
  - platform: esp8266_pwm
    pin: D0
    id: redgpio

light:
  - platform: monochromatic
    name: "Led knop Giel"
    id: licht
    output: redgpio
    effects:
      - strobe:
      - flicker:

binary_sensor:
  - platform: gpio
    pin:
      number: D5
    id: "knop_giel"
    on_multi_click:
    - timing:
      - ON for at most 1s
      - OFF for at most 1s
      - ON for at most 1s
      - OFF for at most 1s
      - ON for at most 1s
      - OFF for at most 1s
      - ON for at most 1s
      - OFF for at most 1s
      - ON for at most 1s
      - OFF for at least 0.5s
      then:
        - binary_sensor.template.publish:
            id: giel_5_klik
            state: ON
        - if:
            condition:
              light.is_on: licht
            then:
              - delay: 1s
              - light.turn_on:
                  id: licht
                  effect: strobe
              - delay: 5s
              - light.turn_off:
                  id: licht
              - light.turn_on:
                  id: licht
            else:
              - delay: 1s
              - light.turn_on:
                  id: licht
                  effect: strobe
              - delay: 5s
              - light.turn_off:
                  id: licht
        - delay: 2s
        - binary_sensor.template.publish:
            id: giel_5_klik
            state: OFF
    - timing:
      - ON for at most 1s
      - OFF for at most 1s
      - ON for at most 1s
      - OFF for at most 1s
      - ON for at most 1s
      - OFF for at most 1s
      - ON for at most 1s
      - OFF for at least 0.5s
      then:
        - binary_sensor.template.publish:
            id: giel_4_klik
            state: ON
        - if:
            condition:
              light.is_on: licht
            then:
              - delay: 1s
              - light.turn_on:
                  id: licht
                  effect: strobe
              - delay: 4s
              - light.turn_off:
                  id: licht
              - light.turn_on:
                  id: licht
            else:
              - delay: 1s
              - light.turn_on:
                  id: licht
                  effect: strobe
              - delay: 4s
              - light.turn_off:
                  id: licht
        - delay: 2s
        - binary_sensor.template.publish:
            id: giel_4_klik
            state: OFF
    - timing:
        - ON for at most 1s
        - OFF for at most 1s
        - ON for at most 1s
        - OFF for at most 1s
        - ON for at most 1s
        - OFF for at least 0.5s
      then:
          - binary_sensor.template.publish:
              id: giel_3_klik
              state: ON
          - if:
              condition:
                light.is_on: licht
              then:
                - delay: 1s
                - light.turn_on:
                    id: licht
                    effect: strobe
                - delay: 3s
                - light.turn_off:
                    id: licht
                - light.turn_on:
                    id: licht
              else:
                - delay: 1s
                - light.turn_on:
                    id: licht
                    effect: strobe
                - delay: 3s
                - light.turn_off:
                    id: licht
          - delay: 2s
          - binary_sensor.template.publish:
              id: giel_3_klik
              state: OFF
    - timing:
        - ON for at most 1s
        - OFF for at most 1s
        - ON for at most 1s
        - OFF for at least 0.5s
      then:
          - binary_sensor.template.publish:
              id: giel_2_klik
              state: ON
          - if:
              condition:
                light.is_on: licht
              then:
                - delay: 1s
                - light.turn_on:
                    id: licht
                    effect: strobe
                - delay: 2s
                - light.turn_off:
                    id: licht
                - light.turn_on:
                    id: licht
              else:
                - delay: 1s
                - light.turn_on:
                    id: licht
                    effect: strobe
                - delay: 2s
                - light.turn_off:
                    id: licht
          - delay: 2s
          - binary_sensor.template.publish:
              id: giel_2_klik
              state: OFF
    - timing:
        - ON for at most 1s
        - OFF for at least 0.5s
      then:
          - binary_sensor.template.publish:
              id: giel_klik
              state: ON
          - if:
              condition:
                light.is_on: licht
              then:
                - delay: 1s
                - light.turn_on:
                    id: licht
                    effect: strobe
                - delay: 1s
                - light.turn_off:
                    id: licht
                - light.turn_on:
                    id: licht
              else:
                - delay: 1s
                - light.turn_on:
                    id: licht
                    effect: strobe
                - delay: 1s
                - light.turn_off:
                    id: licht
          - delay: 2s
          - binary_sensor.template.publish:
              id: giel_klik
              state: OFF
    - timing:
      - ON for at least 1.2s
      then:
        - binary_sensor.template.publish:
            id: giel_long_klik
            state: ON
        - if:
              condition:
                light.is_on: licht
              then:
                - light.turn_on:
                    id: licht
                    effect: flicker
                - delay: 1s
                - light.turn_off:
                    id: licht
                - light.turn_on:
                    id: licht
              else:
                - light.turn_on:
                    id: licht
                    effect: flicker
                - delay: 1s
                - light.turn_off:
                    id: licht
    on_release:
          - binary_sensor.template.publish:
              id: giel_long_klik
              state: OFF
  
  - platform: template
    id: giel_klik
    name: "Knop Giel klik"
  
  - platform: template
    id: giel_long_klik
    name: "Knop Giel lange klik"
  
  - platform: template
    id: giel_2_klik
    name: "Knop Giel 2 klik"
    
  - platform: template
    id: giel_3_klik
    name: "Knop Giel 3 klik"
  
  - platform: template
    id: giel_4_klik
    name: "Knop Giel 4 klik"
  
  - platform: template
    id: giel_5_klik
    name: "Knop Giel 5 klik"

The automations for the multi_click can be found here: https://github.com/gieljnssns/My-Hassio-config/tree/master/config/automation/esp_buttons

All the code for dimming is based on this topic and can be found here as 3 packages.

6 Likes

He man,

Looks cool!
Are you using the 3v buttons?
And how did you wire? Are you using battery?

Yes I’m using the 3V buttons.
I use this as a power source.
If someone knows a program or site where I can draw an electrical diagram…

I just finished the button for my oldest daughter

Ok good to now.
I hoped on battery but gonna order some buttons :slight_smile:
maybe you can draw it with this: https://www.circuito.io/ (havent tested it myself)


Just left the resistor with the cross out. (don’t find a way in circuito.io to leave it away)

1 Like