Trying to create an alert that lets me know if my chicken coop did not open or close

Hello everyone…

This morning i was surprised to see that my chicken door wasnt open all the way and was stuck in the middle…so i was wondering how to make an alert notification that watches my “is open” or “is closed” status that i have available and when one or the other changes, wait 20 or 30 seconds and if the other status hasn’t changed after that throw an alert for either did not open or did not close…

I tried a couple versions, but somehow i dont get the logic in to read both status, plug it into a variable, use the on the one that is “on” (for open or closed) dynamically and as soon the “on” changes to off, wait 30 seconds and when the other on reaches "on in that time frame do nothing, but when it does not reach the “on”, throw an alert that uses the variable to tell if it either did not reach open or closed in time.

Here the ESPHOME c


ode that does the opening and closing:

binary_sensor:  
  - platform: gpio
    pin:
      number: GPIO13
      mode:
        input: true
        pullup: true
      inverted: true
    id: lsw1_open
    name: "Chicken Coop open"
    filters:
      - delayed_on: 30ms
      - delayed_off: 30ms       
    on_press:
      then:
        - button.press: button_stop    

  - platform: gpio
    pin:
      number: GPIO14
      mode:
        input: true
        pullup: true
      inverted: true
    id: lsw2_closed
    name: "Chicken Coop closed"
    filters:
      - delayed_on: 30ms
      - delayed_off: 30ms      
    on_press:
      then:
        - button.press: button_stop         

  - platform: gpio
    name: "Toggle Door"
    pin:
      number: GPIO3 
      inverted: True
      mode:
        input: True
        pullup: True
    filters:
      - delayed_on: 30ms
      - delayed_off: 30ms    
    on_press:
      then:
      - if:
          condition:
            binary_sensor.is_off: lsw2_closed 
          then:
            - button.press: button_on_sunset
      - if: 
          condition: 
            binary_sensor.is_off: lsw1_open   
          then:
            - button.press: button_on_sunrise

switch:
    - platform: template 
      id: disable_open_on_sunrise 
      name: "Disable open on sunrise" 
      optimistic: true

button:
  - platform: template
    id: button_on_sunset
    name: Close Door
    on_press:
        if: 
          condition: 
            binary_sensor.is_off: lsw2_closed    
          then:
            - fan.turn_on: 
                id: chickendoormotor
                speed: 20
                direction: REVERSE
            - wait_until:
                condition:
                  binary_sensor.is_on: lsw2_closed
            - fan.turn_off: chickendoormotor

  - platform: template
    id: button_on_sunrise
    name: Open Door
    on_press:
        if: 
          condition: 
            binary_sensor.is_off: lsw1_open   
          then:
            - fan.turn_on: 
                id: chickendoormotor
                speed: 30
                direction: FORWARD
            - wait_until:
                condition:
                  binary_sensor.is_on: lsw1_open
            - fan.turn_off: chickendoormotor
                
  - platform: template
    id: button_stop
    name: Stop Door
    on_press:
        - fan.turn_off: chickendoormotor

If I’m understanding correctly, under normal circumstances the binary sensor’s should never have the same value for more than 30 seconds… so you should be able to just compare them for equality with a duration requirement:

trigger: template
value_template: |
  {{states('binary_sensor.example_chicken_coop_open') == states('binary_sensor.example_chicken_coop_closed')}}
for: "00:01:00"
1 Like

Thx a lot for this solution…not 100% what i had envisioned, but nice solution…
Used it already successful.

1 Like