First Timer - Chicken Coop Door

Hello.

Sorry if this is a very simple question. I’m just getting started with Home Assistant and ESPHome. I successfully added a temperature sensor and camera to Home Assistant, now I’m trying to automate opening and closing a door for a chicken coop.

I’m using a motor controller board like the TI DRV8833. For one motor, two GPIO inputs are needed, IN1 and IN2. If IN1 high and IN2 low then motor spins forwards. If IN1 low and IN2 high then motor spins backwards.

So far, I’ve tried the following. The “show logs” in ESPHome show that the device has booted succesfully. However I don’t see the two switches in Home Assistant. I saw that one new device was found, but there are no entities attached to the device. Have I made a mistake in this code, for having two switches show up in my Home Assistant dashboard?

esphome:
  name: coop_door
  platform: ESP8266
  board: esp01_1m

wifi:
  ssid: "ABC"
  password: "123"

switch:
  - platform: gpio
    pin: GPIO0
    id: door_up
    interlock: &interlock_group [door_up, door_down]
  - platform: gpio
    pin: GPIO2
    id: door_down
    interlock: *interlock_group

captive_portal:

# Enable logging
logger:

# Enable Home Assistant API
api:

ota:

Notes

  • IN1 and IN2 should never be high at the same time
  • Stage 1 is to just add a switch to have add two switches for motor-forwards and motor-backwards
  • Stage 2 (once I get stage 1 working) - I want to add limit switches and timing. I have a switch that gets closed when the door gets all the way up and another when it gets all the way down. I would like to add logic where motor forwards runs the motor only until the upper switch is hit. Likewise motor-backwards should run the motor only until the lower switch is hit. A timeout will also be necessary so that the motor doesn’t run forever in case of switch error

Thank you!

I am not sure why your switches are not showing.

However for part two, you should take a look at making a cover - see the endstop cover https://esphome.io/components/cover/endstop.html

1 Like

Actually I think it is because you don’t have a name: for each switch, so it is internal only.

1 Like

Yep that’s the issue

Yes

internal ( Optional , boolean): Mark this component as internal. Internal components will not be exposed to the frontend (like Home Assistant). Only specifying an id without a name will implicitly set this to true.

Ah great - thanks @nickrout and @samnewman86 for the fast response. I’ve made the fix - switches show up now and I’m successfully lifting and lowering a 3lb weight. Stage 1 complete.

The endstop cover component looks like exactly what I need for stage 2. Does the following code right?

switch:
  - platform: gpio
    pin: GPIO0
    id: door_up
    interlock: &interlock_group [door_up, door_down]
  - platform: gpio
    pin: GPIO2
    id: door_down
    interlock: *interlock_group

binary_sensor:
  - platform: gpio
    pin: GPIO1
	id: door_up_endstop
  - platform: gpio
    pin: GPIO3
	id: door_down_endstop
	
cover:
  - platform: endstop
    name: "Chicken door"

    open_action:
      - switch.turn_on: door_up
    open_duration: 2.1min
    open_endstop: door_up_endstop

    close_action:
      - switch.turn_on: door_down
    close_duration: 2min
    close_endstop: door_down_endstop

    stop_action:
      - switch.turn_off: door_up
      - switch.turn_off: door_down

Questions

  • Do I need to add a pulldown resistor to GPIO0 and GPIO2? (Actually I think boot fails if pulled LOW). I’m relatively new to electronics - is there a “floating pin” issue here?
  • Note that I’m using an esp01s. As far as I understand, the esp01s breaks out 2 normal GPIOs (GPIO0 and GPIO2), but RX and TX can be used as GPIOs as well (GPIO3 and GPIO1 respectively). Do I need to set GPIO3 and GPIO1 to output mode? I guess I’ll need them for the endstop switches
  • I’d like to have the door raise and lower at 7am/7pm respectively. Is it common to do this within the sketch on the device itself or to have Home Assistant make the calls. Ideally I’d have this logic on the device itself in case Home Assistant or the router are down.

Will an endstop switch even be possible with an esp01s?

I’ve just seen on esp8266-pinout-reference-gpios that GPIO 0, 1, 2, 3 all either need to be high at boot or fail if pulled low at boot. The endstop switches will essentially force the pin to be pulled high or low (depending on if the switch is engaged or not).This means that if the esp01s power cycles while the pin is pulled low, the device won’t boot.

Is there any way around this? Are there any tricks to get an endstop switch working with an esp01s?

Use a module with more gpios exposed?

I’ve nearly found a solution with the esp01. The only remaining thing is - how can I perform an action after the endstop is hit?

I have the door working, with endstops. I invert the endstop switches so that GPIO 1 and 3 are default high, but low when the endstop switch is hit.

The remaining problem is that the esp won’t boot if it power cycles while the door is at the top or bottom. To fix this, I would like to have the door reverse direction for a brief period after hitting the endstop. That way it will leave GPIO 1 and 3 pulled high, except for the a brief moment while the switch is hit. I’m fine with the small gap that will be left from the door leaving the endstop position.

esphome:
  name: coop_door
  platform: ESP8266
  board: esp01_1m

wifi:
  ssid: "ABC"
  password: "123"

switch:
  - platform: gpio
    pin: GPIO0
    id: door_up
    interlock: &interlock_group [door_up, door_down]
  - platform: gpio
    pin: GPIO2
    id: door_down
    interlock: *interlock_group

binary_sensor:
  - platform: gpio
    pin: 
      number: GPIO1
      mode: INPUT_PULLUP
      inverted: True
    id: door_up_endstop
  - platform: gpio
    pin: 
      number: GPIO3
      mode: INPUT_PULLUP
      inverted: True
    id: door_down_endstop

cover:
  - platform: endstop
    name: "Chicken door"

    open_action:
      - switch.turn_on: door_up
    open_duration: 10s
    open_endstop: door_up_endstop

    close_action:
      - switch.turn_on: door_down
    close_duration: 10s
    close_endstop: door_down_endstop

    stop_action:
      - switch.turn_off: door_up
      - switch.turn_off: door_down
	  
	max_duration: 15s

captive_portal:

# Enable logging
logger:

# Enable Home Assistant API
api:

ota:

Thanks!

For anyone interested, I was able to back off the endstop using the following. This reverses the direction for 1s after hitting the endstop

stop_action:
  - switch.turn_off: door_up
  - switch.turn_off: door_down
  - if:
	  condition:
		binary_sensor.is_on: door_up_endstop
	  then:
		- delay: 1s
		- switch.turn_on: door_down
		- delay: 1s
		- switch.turn_off: door_down
	  else:
		if:
		  condition:
			binary_sensor.is_on: door_down_endstop
		  then:
			- delay: 1s
			- switch.turn_on: door_up
			- delay: 1s
			- switch.turn_off: door_up

I 3d-printed enclosures for the endstop switches along with a bracket on the door that hits the endstops.

Bottom endstop video (“https://streamable.com/y5kja4”)

Top endstop video (“https://streamable.com/8328ox”)

Remaining problem
The biggest issue I still have is with wifi connectivity. I’m right on the limit of the reach of my wifi. In testing, it seems like if wifi cuts out once the door is moving, the endstop no longer stops the motion. Luckily I observed this when testing the endstop with my finger and was able to yank the power cord before damage was done. If this were to happen in the real world, it would keep running the motor until the time limit and break the plastic bracket. Does the endstop require wifi to activate?