Assistance needed with ESPHome Automation (cant get my head around it)

Hi All,

Hoping someone can help, as i cannot seeme to get my head around this.

I have followed DrZzs video and setup an esphome garage door Sonoff SV (replacing my old MQTT version, as it had issues). With my MQTT version, i had it connected to a reed switch to sense and display the door status, notifications to tell me when the door was activated (and the activation status), and an LED (positioned inside the house) which flashed continuously when the door was left open.

Basically, I have the new esphome version setup to display correct status using the reed switch, the controller (button) works as required, the LED will flash for 500ms when i activate it manually, BUT i cannot get my head around what i need to do to activate the flashing LED automatically when the door is up…

Do i need to give GPIO14 “Garage Door Test” an ID and then call the ID in an condition on the binary_sensor? or some other way? Is the Template in the right position? i need help…

I have added my yaml below.

As for the notifications on phone, i will work on this once i get the LED working…

Thanks in advance

binary_sensor:
  - platform: gpio
    pin:
      number: GPIO14
      mode: INPUT_PULLUP
      inverted: True
    name: "Garage Door Test"
    device_class: garage_door

switch:
  - platform: gpio
    pin: GPIO12
    id: relay_test
  - platform: template
    icon: "mdi:garage"
    name: "Garage Test"
    turn_on_action:
    - switch.turn_on: relay_test
    - delay: 500ms
    - switch.turn_off: relay_test
  - platform: gpio
    pin: GPIO1
    id: pin_test

  - platform: template
    name: "LED Test"
    optimistic: yes
    id: temp_test
    turn_on_action:
    - while:
        condition:
          lambda: 'return true;'
        then:
        - switch.turn_on: pin_test
        - delay: 500ms 
        - switch.turn_off: pin_test
        - delay: 500ms
    turn_off_action:
    - switch.turn_off: pin_test

I’m not familiar with the DrZzs solution, I guess you are using HA automations there to trigger the relay from HAs? “Grage Test” Please give better names to your things.

Looks like your templated switch “Garage Test” will flash the LED, you can turn on this switch from Ha or from EspHome itself, you can have the automation (sensor made → flash light) in HA or EspHome, if you’d like to do it in ESPHome you have to add to binary_sensor a on_press (or on_relased) that will turn on your switch, e.g.

binary_sensor:
  - platform: gpio
    ...
    on_press:
      - switch.turn_on: switch_garage_test_id # -- add an id to the switch so you can reference here

Now if you only want the LED to flash depending on the GPIO14 reed switch state, I would move the whole while ... inside the binary sensor’s on press and on release automations.

2 Likes

Thank you for the help… you got me looking in the right direction with the id: and the on_push and on_release.

for anyone interested, here is the (partially cleaned) code…

binary_sensor:
  - platform: gpio
    pin:
      number: GPIO14
      mode: INPUT_PULLUP
      inverted: True
    id: garage_door_state_test
    name: "Garage Door State (test)"
    device_class: garage_door
    on_press:
      - then:
        - switch.turn_on: led_flasher_test
    on_release:
      - then:
        - switch.turn_off: led_flasher_test
        - switch.turn_off: sonoff_sv_tx_gpio_test

switch:
  - platform: gpio
    pin: GPIO12
    id: sonoff_sv_relay_gpio_test
  - platform: template
    id: garage_switch_test
    icon: "mdi:garage"
    name: "Garage Switch Test"
    turn_on_action:
    - switch.turn_on: sonoff_sv_relay_gpio_test
    - delay: 500ms
    - switch.turn_off: sonoff_sv_relay_gpio_test

  - platform: gpio
    pin: GPIO1
    id: sonoff_sv_tx_gpio_test
  - platform: template
    name: "LED Flasher Test"
    optimistic: yes
    id: led_flasher_test
    turn_on_action:
    - while:
        condition:
          lambda: 'return true;'
        then:
        - switch.turn_on: sonoff_sv_tx_gpio_test
        - delay: 500ms 
        - switch.turn_off: sonoff_sv_tx_gpio_test
        - delay: 500ms

thanks again @glmnet

1 Like