Need help/idea how to fail proof my chicken door

Hello everyone…
I am in need of a better chicken door logic but i am pulling blank when i try think of something useful
Right now it is a simple string pulling mechanism that lift and lowers the door with a pretty powerfull gearbox.
Controlled by esp on a relay board with 2 relays in an alternating setup so that i can just open and close via the relay switching.
Over all, it is just set to open or close for 1 second which roughly opens and closes it correctly, but as said, just roughly.
For some reason, someties the setup goes into a prolonged running spree and would rip the line, so i added microswitches to interrupt power when door reaches a certain height.
But i would like to have more relebale and more controlled and if possible with a notification if the door did not reach a certain state at a specific time of day aka open in morning or closed in the evenning.
I tried the search, but wasnt to successful with coming up with something i could adapt.
So every idea is more than welcome

thx in advacne

To get a notification of the position you would need feedback of the position. Micro switches could provide that feedback but why not use them to correctly open/close the door?

Why isn’t it working for you now?

the switches dont give feedback to the esp, they just cut power to the motor in case it runs out of defined moving range…
The relay board i am using only uses a esp8266 that has no available inputs or outputs besides for the control of the relays

I have a bucket full of di minis, but i am not sure if i can control the relays using the header pins, since i havent found much about those header pins so far…
And for some reason, once in the blue moon, the esp runs a relay for an undefined time…so i am ending up with the door pulled up all the way into the limiter switches, and from there is no way back via remote and i have to pull the door down below the switches to have power to the motor again…
so in case i can utilize the header pins to use the relay board without the esp8266, i could utilize the microswitches…but there i call blank

Of course you can use that relay module with other Esp boards.

Reason for this should be investigated…

What kind of motor you have and how are the limit switches connected to it?

1 Like

Superficially it seems like you have reasonable hardware and your general approach seems reasonable too.

So therefore I think the issue could be in your wiring or configuration.

So sharing both of that may help debugging.

Here is a page with more information about the relay board you have.

The way it works is the ESP-01 sends serial commands to another microcontroller on the board and that UC controls the relays. The header pins pretty much mirror the socket the ESP is connected to. You can easily replace the 01 with a D1 mini using the sample code on that page.

As for feedback, you could use micro switches or a magnet and reed switches on the open and closed positions of the door connected to the D1 and just run the door until it’s where it supposed to be.

It’s not a bad idea to have micro switches at each end of travel to cut power to the motor. Many commercial actuators work this way with limit switches built in, so you can leave power applied but it still stops when it reaches the end of it’s travel. The key is that you have to wire them such that they don’t prevent energizing the motor to move back in the other direction.

For example, assuming this is a DC motor, you could have the motor terminals connected to the common terminal of each relay, ground from your power supply connected to NC of each relay and positive to NO of each relay. So, both terminals are normally grounded and activating a relay would supply positive for one direction or the other. In this case, your limit switches would cut the + power line going to their corresponding relay, but the other relay would be unaffected. Then you can run the motor for several seconds to be sure it has had plenty of time and don’t need to worry about breaking anything or burning out the motor.

Another thing to remember is that the wifi connection to these modules are unreliable (which is probably why you were having issues to begin with) and that you should handle as much of the logic and automation on the ESP as possible and not in HA. HA can handle notifications and updates.

Sooo, i have a geared 12 volt motor as the drive ( in the process of getting a pwm speed controller fir it since it is a little bit fast).
The esphome just activates on relay to drive the motor one way or the other relay to drive the motor the other way around(polarity changing circuit).
Its only on a timed approach. 1.6 seconds for up and 1 sec for down.
Works so far good enough that i only have to correct once or twice month.
The microswitches are in each wire towards the motor in case it goes mayhem and would cut itself power as soon it reaches top dead end. Thats works also pretty good, but since it cuts the supply circuit, the logic can not work again until i pull it out of the dead end switch area.

I like your idea with the switches cutting power but not preventing reverse driving.
Do u have an example drawing for the curcuit?
Mine is cuting alsways the complete circuit so coming out of dead band is impossible.
And how can i do the driving automatism in esphome and not coming from hass?

And how would i then get reporting info in hass?

Thx in advance

You should post a scheme of your actual wiring, to propose changes.
Also, ideally the whole automation is coded to esphome, so it works independently from Hass. What automation you have at the moment? Time based, light based…?

Hello, here my esphame and automation code:

Close

alias: RelayCloseChickenDoor
description: 25 min after sunset
triggers:
  - event: sunset
    offset: "00:25:00"
    trigger: sun
conditions: []
actions:
  - type: turn_on
    device_id: 53e2d60fed3f6d56cb5ffd9708346e7c
    entity_id: 0c902eaee2b093d1c6a07a20ee7a9ab2
    domain: switch
  - delay:
      hours: 0
      minutes: 0
      seconds: 1
      milliseconds: 200
  - type: turn_off
    device_id: 53e2d60fed3f6d56cb5ffd9708346e7c
    entity_id: 0c902eaee2b093d1c6a07a20ee7a9ab2
    domain: switch
mode: single

Open

alias: RelayOpenChickenDoor
description: 25 min after sunrise
mode: single
triggers:
  - event: sunrise
    offset: "00:30:00"
    trigger: sun
conditions: []
actions:
  - type: turn_on
    device_id: 53e2d60fed3f6d56cb5ffd9708346e7c
    entity_id: 0dbab37cec02a51af34e543c6f3fbc59
    domain: switch
  - delay:
      hours: 0
      minutes: 0
      seconds: 1
      milliseconds: 300
  - type: turn_off
    device_id: 53e2d60fed3f6d56cb5ffd9708346e7c
    entity_id: 0dbab37cec02a51af34e543c6f3fbc59
    domain: switch

Sketch:
9eb5f706128f89f28c97e7229e60c37520c6fe7e

My microswitches are on the two cables towards the motor. How about moving them into the us line to each relay? Would that not be the teick to cut power but leave power for the other direction?

I would definitely be moving this logic from HA to ESPHome as part of overall reliability improvements.

You could do something similar to below. Cover components are quite flexible these days.

You current issue could be something as simple as the ESP losing connection half way through your HA actions. Which won’t be an issue if you move it to the ESP.

##########################################################################################
# Motor Control
##########################################################################################
#Set up control, Define Pins
#GPIO15 = D8 >>> IN3
#GPIO13 = D7 >>> IN4
output:
  - platform: gpio
    id: 'win_close_living'
    pin: D8
  - platform: gpio
    id: 'win_open_living'
    pin: D7
  
#USe the pins above in two switches.
switch:
  - platform: output
    name: "winclose_living"
    output: 'win_close_living'
    id: winclose_living
    internal: true
    # on_turn_on:
       # - delay: 200s   
       # - switch.turn_off: winclose_living 
       # - switch.turn_off: winclose_living 
    
  - platform: output
    name: "winopen_living"
    output: 'win_open_living'
    id: winopen_living 
    internal: true
    # on_turn_on:
       # - delay: 200s   
       # - switch.turn_off: win_open_living 
       # - switch.turn_off: winclose_living 

#Use the switches to define a cover.
cover:
  - platform: template
    name: "Living Room Window"
    id: tr_win_open_living
    device_class: window
    lambda: |-
      if (id(living_win_state).state) { // On means open
        return COVER_OPEN;
      } else {
        return COVER_CLOSED;
      }
    # optimistic: true
    open_action:
        #Open if closed
      then:
        if:
          condition:
            binary_sensor.is_off: living_win_state  # Off means closed
          then:
          - switch.turn_off: winclose_living
          - switch.turn_on: winopen_living 
          - delay: 165s
          - switch.turn_off: winopen_living
          else:
    
    close_action:
        #Close if open
      then:
        if:
          condition:
            binary_sensor.is_on: living_win_state # On means open
          then:
          - switch.turn_off: winopen_living
          - switch.turn_on: winclose_living
          - delay: 185s
          - switch.turn_off: winclose_living
          else:

#for stop button
    stop_action:
      - switch.turn_off: winclose_living
      - switch.turn_off: winopen_living

##########################################################################################
# End Stop
##########################################################################################
binary_sensor:
  - platform: template
    name: "Cover State"
    device_class: DOOR
    lambda: |-
        return id(tr_win_open_living).position == COVER_OPEN ;

  - platform: status
    name: "Living Room Window ESP32 Status"
#D5 > yellow > C
#Ground > black > NO
  - platform: gpio
    device_class: window
    internal: false
    pin:
      number: D5
      #reliability problems try activating pullup...
      mode: INPUT_PULLUP
    name: "living window state"
    id: "living_win_state"
    on_release: #Release = off = closed
      then:
        - delay: 2s
        - switch.turn_off: winclose_living
        - switch.turn_off: winopen_living
    filters:
      - delayed_on: 500ms
      - delayed_off: 3s
# ##########################################################################################
# # Button 
# ##########################################################################################      
               
  - platform: gpio
    pin: D4
    internal: false
    name: "toggle living window"
    id: "toggle_living_window"
    filters: 
      invert: 
    on_press: 
      then:  
        - lambda: | 
            if (id(tr_win_open_living).position == COVER_OPEN) {        // if  OPEN
              if (id(winopen_living).state) {                                 // If OPENING, STOP it
                id(tr_win_open_living).stop();                                
              } else {                                                
                id(tr_win_open_living).close();                               // If NOT OPENING, CLOSE it
              } 
            } else {
              if (id(winclose_living).state) {                           // If NOT OPEN
                id(tr_win_open_living).stop();                                // If CLOSING, STOP IT
              } else {
                id(tr_win_open_living).open();                                // If NOT CLOSING, OPEN IT
              }
            }


image
For example like this.

1 Like

Hello, just did that and it works.
Will now try to mive the logic into esphome.
Than the last thin i would have on my wishlist is the feedback if it is ipen ir closed.
And somehow, change the gpio to have it not always freak out on a flash or power cycle, preferrred moving the relay board from a esp01 to a di mini, but havent seen anything in the mentioned link higher up

Ahh, when you said limit switches I assumed (wrongly) that you used above circuit or the more general one where you bypass the switch with a diode (that way you can still move it in the other direction). That’s why I didn’t see a problem with that approach :smiley:

As for getting it into HA, I would make a template switch or template cover which switches on the open or close relay. Because the limit switches will kill the power, there is no need to time it anymore:

cover:
  - platform: template
    name: "Door"
    id: door
    open_action:
      - switch.turn_off: relay_close
      - switch.turn_on: relay_open
    close_action:
      - switch.turn_off: relay_open
      - switch.turn_on: relay_close

Hello…

I did assimilate your code and was wondering how this would get triggered…
I dont see and buttons or switches new and i am also quite frankly unable to understand of hand what cover templates actual are/do…no to mention to code sun set/sun rise into it :slight_smile:
I will keep diggin…

Just read the docs;)

While you’re there, take a look at the different types of covers and determine which type is the best fit for your project. Possibly Template, Feedback or Endstop.

Covers are designed for what you are doing.

95% of the time the docs have decent examples and going there as a first port of call and spending some time to navigate and understand them will get you far.

My sample code was a remake of this, which is a good walk though. The code is several years old and there may be more modern eats to do it as more cover types have been added since then.

What kind of feedback? It is open if your automation opened it. Or you don’t trust your code? Or you don’t trust your motor, wiring or limit switches? Then you need a separate feedback sensor.

I guess my issue is that I am ot native English and cover does not really wants to stick with my head.
And the lack of time…i always just squeeze those development/investigations in 5 min sections between household and errands.probably not the most efficient way of doing it.

1 Like

Fair enough.
That will make learning a bit harder.
These things do take some time to understand.
You can copy/paste code but that will only get you so far.

Soo…
Due to all of the help here, i was now able to have the logic in my esphome code…and so far, it seems to trigger the open and close on a roughly wanted time…still playing with the fie tuning on the degrees above or below horizon.
Speed controller for the motor came also and will be wired in this weekend…
Now my question on top of this all…since i am still using the tiny esp01 on my 2 relay board…and occupy two of its available pins for the open and close function…can on of the others be used to relay back a “closed” signal? my limiter switches have NC and NO on them, and i use the NC for stopping the door, but could get a signal from the NC contact to get a “yes its closed” response.
Any ideas on that one?
Will share the code as soon my home has internet again…