ESPHome Cover platform - Closing/Opening status from Motor Voltage?

Greetings,

I’m working on my first custom ESPHome project based on a 4 relay esp32 board. It controls a Coop Controls (CC) door actuator on a chicken coop.

So far I’ve got basics down. Two relays trigger the CC to open or close, and I’m using a reed switch to detect if the door is closed. It’s a swing type door so it’s not practical to use a second reed switch like in this example

Is it possible to use the +/- DC voltage at the motor terminals to detect whether the door is opening or closing, and along with the reed switch infer all the states within the ESPHome programming?

We’d be making an assumption for the “open” state, but the other states should be confident.

Here’s my config so far, but I’m anticipating it will need to get revamped.

config
esphome:
  name: chicken-coop
  friendly_name: Chicken Coop

esp32:
  board: esp32dev
  framework:
    type: esp-idf

# Enable logging
logger:

# Enable Home Assistant API
api:
  encryption:
    key: ""

ota:
  - platform: esphome
    password: ""

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Chicken-Coop Fallback Hotspot"
    password: !secret fallback_password

captive_portal:
    
output:
  - platform: gpio
    pin: GPIO23
    id: led
  - platform: gpio
    pin: GPIO32
    id: relay_pin_1
  - platform: gpio
    pin: GPIO33
    id: relay_pin_2
  - platform: gpio
    pin: GPIO25
    id: relay_pin_3
  - platform: gpio
    pin: GPIO26
    id: relay_pin_4

# # Define the switches based on the relay pins
switch:
#   - platform: output
#     id: relay_1
#     name: "Relay 1"
#     output: relay_pin_1
#   - platform: output
#     id: relay_2
#     name: "Relay 2"
#     output: relay_pin_2
  - platform: output
    id: relay_3
    name: "Relay 3"
    output: relay_pin_3
  - platform: output
    id: relay_4
    name: "Relay 4"
    output: relay_pin_4

button:
  - platform: output
    name: "Open Coop Door"
    id: button_1
    icon: "mdi:door-open"
    output: relay_pin_1
    duration: 500ms
  - platform: output
    name: "Close Coop Door"
    id: button_2
    icon: "mdi:door-closed"
    output: relay_pin_2
    duration: 500ms

binary_sensor:
  - platform: gpio
    name: "Coop Door"
    device_class: door
    pin:
      number: GPIO4
      inverted: true
      mode: INPUT_PULLUP
  - platform: gpio
    name: "Coop Alarm Buzzer Output"
    pin:
      number: GPIO13
      mode: INPUT_PULLUP
  - platform: gpio
    name: "Coop Alarm LED Output"
    pin:
      number: GPIO14
      mode: INPUT_PULLUP
sensor:
  - platform: adc
    name: "Coop Photocell"
    pin: 34


## The following makes the right LED `D14` blink every .5 seconds
# interval:
#   - interval: 1000ms
#     then:
#       - output.turn_on: led
#       - delay: 500ms
#       - output.turn_off: led

Yes. Just make voltage divider with two resistors to drop the sensing voltage to 3.3V. Then with two binary sensors you can detect all 3 states motor has. Make sure to have common GND between door power supply and Esp.

1 Like

Thank you.

I left out a detail, I’ll edit the question. I meant to ask: is it possible to do this within the ESPHome programming itself?

Regarding common GND, the ESP is powered by the CC’d backup 12v battery which is charged by the CC board. How do I assess whether there is a common ground? Is that already the case, or would it be by bringing the - terminal from the motor to a GND on the ESP?

I’m fairly competent with house wiring (electrician background), but electronics is definitely an untrained hobby.

Don’t even think! If your motor driver swaps polarity for reverse direction you short the whole crap.

Why from battery? Tmho it would be better to power it from CC board DC supply. Battery charging circuit does not expect something drawing permanently current from battery and might misbehave (like never stop charging).

Anyway, the setup almost surely shares common ground already, but since esp is powered from battery which has some management circuit, it’s better to verify. Just measure that you have continuity with motor negative and Esp Gnd.

1 Like

Good catch, as that’s exactly what it’s doing, and exactly how I was planning to infer closing vs opening.

For some reason the board is powered by 18v AC, although it does say 18vac/solar and I thought solar was usually DC without an inverter. Maybe the board has a switching power supply?

The ESP can take AC as well, however it’s at 220v, although some listings say 110v/220v which has been confusing.

That’s a valid concern about the charging circuitry. It sounds like a better solution is in order, investigation at least. I did notice yesterday that the board didn’t power up without the battery even though it had AC, and now reading the listing it says “A 12-Volt 7 Amp Hour Battery is required and not included.” Is that any clue as to how the charging circuit works?

Edit - looks like the solar panel puts out DC so the board must be able to handle either. I could presumably get an 18v dv power supply instead of the AC supply they provided.

That’s common, but somewhere there has to be AC/DC converter because it can’t charge battery from AC. Neither it can drive a DC motor from AC.
Do you have any manual or circuit diagram?

Is it powered only from solar or also from mains?

I havent been able to find anything more then extremely basic, nothing with insight to this.

I’m only using mains, solar was an option, and I don’t think you can do both.

Here’s the circuit boards. Sorry I don’t have a clean shot of the front.


I’ve been thinking about this. Is this possible to do within ESPHome? Then I can take those and put them into the lambda in that post I mentioned?

Of course, always do everything within Esphome. Doesn’t relay on HA.

It looks like the whole board works on DC, 18VAC is converted to DC. But I can’t tell from the image if there is any convenient place to get Esp powered. What are the two smaller connectors with double black and white wires?

1 Like

My unfamiliarity with ESPHome made it take a moment to realize I can build out the binary sensors and then template them within the ESPHome itself. Pretty sweet. Thanks for confirming. That was the solution to the main inquiry.

Re: power, my conclusion was also that the board appeared to be DC. The motor is 12v, and the sensor and control switches are 5v per testing.

The second and third set of wires from the bottom left is “power switch” and “photo sensor” respectively. The power connector probably has 12v at all times on one side, so maybe that’s a good place to power the ESP?

Measure, impossible to say.
What about photo sensor, what type of sensor?

I only know a little about photo sensors. How could I tell?

It looks like this, and I’m pretty sure it’s powered by 5v.

So it’s a light sensor?
For “Photo sensor” I imagined photoelectric sensor like break-beam sensor… :sweat_smile:

No luck there.
Remember that for Esp you need at least 300mA, so you can’t wire it to whatever point where you find compatible voltage.

Yes, light sensor, my bad. :slightly_smiling_face:

I think I’ll reach out to the manufacturer to see if they can give any direction.

Since you have mains there, why don’t you just power Esp from Usb charger…

That may be the cleanest option if it turns out the battery is a nogo. The reason it wasn’t the first is that the transformer is zip tied to the other side of the coop under an eve and plugged into an extension cord. Just have to do a little reconfiguration to make that work.

That battery connection probably works just fine, it’s not sophisticated lithium battery management circuit. Even if it keeps the battery under charge, nothing bad really happens…