Confirmation beep on keypress

With “on-click” it’s quite easy to have e.g. three automations for a short, a long, and a very ling click. The downside is, anything is only triggered on release and you have to guess the time. In Arduino I have a routine that gives a sort confirmation beep when the press is detected and another when the time for long press is reached. So far I found no way to achieve that in EH. Is there one? Sample of how far I got so far:

binary_sensor:
  - platform: gpio
    name: ${devicename}taste
    id: ${devicename}taste
    pin:
      number: GPIO1
      mode: INPUT_PULLUP
      inverted: true
    on_click:
    - min_length: 2ms
      max_length: 1000ms
      then:
        - output.turn_off: ${devicename}beep
        - output.turn_on: ${devicename}tone
        - lambda: |-
            if (id(vAnz) == 1) {
              if (id(vMenu) == 0) {
                id(vAnz) = 2; // enter edit
              } else {
                id(vAnz) = 0; // exit menu
              }
            } else if (id(vAnz) == 2) {
              id(vAnz) = 1; // confirm edit
            }
        - delay: 80ms
        - output.turn_off: ${devicename}tone
    - min_length: 1000ms
      max_length: 4000ms
      then:
        - output.turn_on: ${devicename}tone
        - sensor.rotary_encoder.set_value:
            id: drehgeber
            value: !lambda 'return id(Tmax) * 2;'
        - lambda: |-
            id(vAnz) = 1;
            id(vMenu) = 0;
        - delay: 100ms
        - output.turn_off: ${devicename}tone
        - delay: 100ms
        - output.turn_on: ${devicename}tone
        - delay: 100ms
        - output.turn_off: ${devicename}tone
    - min_length: 4000ms
      max_length: 9900ms
      then:
        - output.turn_on: ${devicename}tone
#         - mhz19.calibrate_zero: sensorid
        - delay: 100ms
        - output.turn_off: ${devicename}tone
        - delay: 100ms
        - output.turn_on: ${devicename}tone
        - delay: 100ms
        - output.turn_off: ${devicename}tone
        - delay: 100ms
        - output.turn_on: ${devicename}tone
        - delay: 600ms
        - output.turn_off: ${devicename}tone
``´

You can keep your existing on_click configurations and just add on_multi_click to play the beeps. Or you can configure everything under on_multi_click.

Docs here show how to do this, noting:

While on_click only triggers on the falling edge of the signal, and on_double_click only on the second leading edge, an automation for on_multi_click can trigger at any time. For example, an ON for at least timing without an OFF does not await a falling edge.

Thank you. Due to other issues it may take me some time to try that out. Will report back

Thank you. Works just as desired.

binary_sensor:
  - platform: gpio
    name: ${devicename}-taste
    id: ${devicename}_taste
    pin:
      number: $tstpin
      mode:
        input: true
        pullup: true
      inverted: true
    on_multi_click:
    - timing:
        - ON for at least 2ms
      then:
        - output.esp8266_pwm.set_frequency:
            id: ${deviceid}tone
            frequency: $high Hz
        - output.turn_on: ${deviceid}tone
        - delay: 50ms
        - output.turn_off: ${deviceid}tone
    - timing:
        - ON for at most 3s
      then:
        - display.page.show_next: anzeige
        - component.update: anzeige
    - timing:
        - ON for at least 3s
      then:
        - output.esp8266_pwm.set_frequency:
            id: ${deviceid}tone
            frequency: $low Hz
        - output.turn_on: ${deviceid}tone
        - delay: 500ms
        - output.esp8266_pwm.set_frequency:
            id: ${deviceid}tone
            frequency: $high Hz
        - output.turn_on: ${deviceid}tone
        - delay: 100ms
        - output.turn_off: ${deviceid}tone
    - timing:
        - OFF for at least 20s
      then:
        - display.page.show: page0
        - component.update: anzeige
1 Like