Local button with LEDC did not trigger

Hey,

i am new in HA and YAML, i tried a lot now and didn’t find my misstake.

current test setup:

  • 1x PIR sensor (PIN 33, 27k Pull-Down)
  • 1x LEDC driver (PIN 25)
  • 1x touch button (PIN 34, 27k Pull-Down)

What is working:

  • I see PIR in HA
  • I can switch and dim LED via HA.

What is not working:

  • on_click to activate the light with PIR

My final goal:
If PIR (on time 15 sec) is detect movement switch on the LED for 2 min with 50% brightness.
If PIR has detecting in between the LED is on, restart the 2 min timer.
IF a touch botton is used don’t use the PIR :wink: (second step)

esphome:
  name: s73-aut
  friendly_name: s73_aut
  
esp32:
  board: az-delivery-devkit-v4
  framework:
    type: arduino

logger:
  level: VERY_VERBOSE

api:
  encryption:
    key: "!"

ota:
  - platform: esphome
    password: "!"

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

  ap:
    ssid: "S73-AUT"
    password: "!"

captive_portal:

# --- GLOBALS VARIABLE --- maybe i need this way
globals:
  - id: actual_effect
    type: int
    restore_value: yes
    initial_value: '0'

# --- I2C CONFIG working ---
i2c:
  sda: 21
  scl: 22
  scan: true
  id: bus_a

# --- Analog IC working ---
ads1115:
  - address: 0x4A
    i2c_id: bus_a
# --- END Analog IC ---
# --- END I2C CONFIG ---


# --- SENSORS ---
#     --- WIFI SIGNAL --- working 
sensor:
  - platform: wifi_signal # Reports the WiFi signal strength/RSSI in dB
    name: "WiFi Signal dB"
    id: wifi_signal_db
    update_interval: 60s
    entity_category: "diagnostic"
  - platform: copy # Reports the WiFi signal strength in %
    source_id: wifi_signal_db
    name: "WiFi Signal Percent"
    filters:
      - lambda: return min(max(2 * (x + 100.0), 0.0), 100.0);
    unit_of_measurement: "Signal %"
    entity_category: "diagnostic"
#     --- END WIFI SIGNAL ---

#     --- DISPLAY uptime working ---
  - platform: uptime
    name: Uptime
    id: up_time
#     --- END DISPLAY uptime

# --- RESTART Button --- working
button:
  - platform: restart
    name: "werkstatt3 Restart"
# --- END RESTART Button ---

# --- BINARY SENSOR PIR ---
binary_sensor:
  - platform: gpio
    pin: 
      number: 33
      mode:
        input: true
        pulldown: true
    name: "PIR Sensor outside"
    device_class: motion
    on_click:
      then: 
        - light.turn_on: light_left
        - output.set_level:
            id: light_left_PWM
            level: "50%"
    filters: 
      - delayed_off: 
          seconds: 15       

# --- END BINARY SENSOR PIR ---

# --- OUTPUT LEDC --- working
output:
  - platform: ledc
    pin: 25
    id: light_left_PWM
    frequency: 1000Hz
# --- END OUTPUT LEDC

# --- LIGHT CONFIG --- working
light:
  - platform: monochromatic
    name: "Light left"
    output: light_left_PWM
    id: light_left
    restore_mode: ALWAYS_OFF
# --- END LIGHT CONFIG ---

Your PIR probably doesn’t give a short <350ms click and I’s getting ignored.
Try with on_press: instead.

Do you see the pir getting activated in the logs?

Yes I can see the pir detection on the log.

Thank you, I will try on_press.

on_press is working, so the light goes on.
Thank you all for the support.

Big thanks to T3m3z @github esphome for the delay function template.

# --- BINARY SENSOR PIR ---
binary_sensor:
  - platform: gpio
    pin:
      number: 33
      mode:
        input: true
        pulldown: true
    id: PIR_OUTSIDE
    name: "PIR Sensor outside"
    device_class: motion
  - platform: template
    name: "PIR Sensor outside delayed"
    lambda: |-
      return id(PIR_OUTSIDE).state;
    filters:
      - delayed_off: 
          seconds: 20 # Sensor goes to OFF state when this time has passed after last true ON
    on_press:
      then:
        - light.turn_on:
            id: light_left
            brightness: 50%
    on_release:
      then:
        - light.turn_off: light_left