I post here because I have a problem with my chicken house door managed by an ESP32 and a 12v stepper motor.
Here are some pictures of my setup. You can see a zigbee door sensor, it gives me the status of the door.
This morning, I think because of a reboot around 0:15 AM, the value should be 50500 but it was 0. So the door didn’t open, poor chickens were stuck in their house !
Why does the ESP32 become unavailable/undefined ? Do you think it reboots ?
Is there a way to “push” this value according to the door state ? Maybe it’s possible to set this “position” value when the ESP32 is available again ?
I would add 2 magnetic contact door sensors so you know the door is open/closed or in between. Define 2 input pins with internal pullup - a wire connected to ground and the other to your input pin from the sensor.
Then use the sun platform in ESPHome and open the door after sunrise (based on a condition the door is closed or not open).
ESPHome can work offline so your feathered friends will not depend on wifi connectivity. I realize I haven’t answered your original question but wifi disconnects can happen and in that case it is good to have a fall back.
I think it would be good if someone could offer a suggestion on the motor that you are using?
I’ve used a stepper motor for a sliding door type while this looks like a drawbridge. That means your stepper motor would have to be powered constantly or the door would slowly open because of gravity. For a portcullis type of door I have used a wormgear motor as that stays in position while powered off.
Code for opening, to stop the motor and to check the sensor which stops the motor at door open/close, so you’ll need to duplicate closing and one more sensor for open/close. I only open if not already open and close if not already closed. A lot off mqtt status publishing too which you can ignore.
stepper:
- platform: a4988
id: my_stepper
step_pin: GPIO26
dir_pin: GPIO25
max_speed: 600 steps/s
sleep_pin: GPIO27
acceleration: 100 // use low acceleration as motor does not have torque at high speed
deceleration: inf
switch:
- platform: template
id: esp32lr5_op
name: "Openen"
restore_state: false
turn_on_action:
if:
condition:
binary_sensor.is_off: sensorGeopend // open ony if the open sensor is not on
then:
- switch.template.publish:
id: esp32lr5_op
state: on
- stepper.report_position:
id: my_stepper
position: 0
- stepper.set_target: // run the motor for a long time
id: my_stepper
target: 50000
- stepper.set_speed:
id: my_stepper
speed: 600 steps/s
- platform: template // stop and deactivate motor - stop action
id: esp32lr5_stop
name: "Stop"
restore_state: false
turn_on_action:
- stepper.report_position:
id: my_stepper
position: 0
- stepper.set_target:
id: my_stepper
target: 0
- stepper.set_speed:
id: my_stepper
speed: 1 steps/s
- switch.template.publish:
id: esp32lr5_op
state: off
- switch.template.publish:
id: esp32lr5_neer
state: off
binary_sensor:
- platform: gpio
pin:
number: GPIO32
mode: INPUT_PULLUP // if contact is closed then pin is connected to ground so inverted sensor
inverted: true
name: "Geopend"
id: sensorGeopend
filters:
- delayed_on_off: 300ms
on_press:
then:
- switch.turn_on: esp32lr5_stop // if open/close sensor is on then perform stop action
- mqtt.publish:
topic: home/open/status
payload: Aan
retain: true
on_release:
then:
- mqtt.publish:
topic: home/open/status
payload: Uit
retain: true
I’ve made a similar chicken door control, that operates according to the light levels, ie dusk and it closes, sunrise opens …also this does not connect to homeassistant as its located far away from server, therefore once programmed via USB and installed, it generates it’s own local hotspot for controlling the open / close / stop / action from your phone, when you are close by. Connected to a car battery which is topped up from solar panel and has been running without any problems for the last 6 months.