My Smart Chicken Coop Adventure: ESP32 and Stepper Motor Setup

Hey everyone, I wanted to share my recent project—automating my chicken coop door using an ESP32 and a 12V stepper motor. It’s been a fun challenge, and I thought I’d walk through my setup and some of the troubleshooting I’ve done along the way.

Setup Overview
I’ve set up a system where the chicken coop door opens and closes automatically based on sunrise and sunset times. I’m using a stepper motor to control the door mechanism and a zigbee door sensor to monitor the door’s status. The ESP32 acts as the brain of the operation, handling the motor control and sensor input.

Here’s a snippet of my code setup:
yaml
cover:

  • platform: template
    name: “Poulailler”
    id: poulailler
    device_class: door
    open_action:
    • stepper.set_target:
      id: my_stepper
      target: 0
    • sensor.template.publish:
      id: position
      state: !lambda return id(my_stepper).target_position;
      close_action:
    • stepper.set_target:
      id: my_stepper
      target: 50500
    • sensor.template.publish:
      id: position
      state: !lambda return id(my_stepper).target_position;
      stop_action:
    • stepper.set_target:
      id: my_stepper
      target: !lambda return id(my_stepper).current_position;
    • sensor.template.publish:
      id: position
      state: !lambda return id(my_stepper).current_position;
      optimistic: true
      assumed_state: true

The Challenge
Last night, I noticed something odd—the ESP32 became unavailable, and the door didn’t open as scheduled. The door sensor showed the door was closed (position value 50500), but when I checked in the morning, the position value was 0, meaning the door was open. This left my chickens stuck outside! I’m wondering if the ESP32 rebooted or if there was a power issue.

What I’m Thinking
I’m considering adding a failsafe mechanism to ensure the door opens regardless of the ESP32’s state. Maybe using a cron job or a separate microcontroller to monitor the door’s position and trigger the motor if needed. I’d love to hear if anyone has experience with similar setups or suggestions on how to implement this.

Lessons Learned
This project has taught me the importance of monitoring device availability and having backup systems in place. It’s also highlighted how crucial it is to test systems thoroughly, especially when they involve animals. I’m grateful for the community here—I’ve learned so much from others’ experiences and troubleshooting tips!

If anyone has insights into why the ESP32 might be becoming unavailable or suggestions for a failsafe, I’d be thrilled to hear them. Let’s keep the chickens safe and happy! :chicken::sparkles: