ESPhome for gate motor

Hello,

Using esphome for the first time and whipped up the following on an esp32.

It has a reed switch and a push button as input.
The push button triggers gpio 13 to complete the circuit of the motor.

The physical push button before the esp32 was push once, motor on. push again, motor off.

I connected the motor switch wire to ground and as soon as I connect the 2nd wire to gpio13, it turns on/off the motor.

Is there a way to address this? There is a small ~ 1.5 V through the two wires.

To prevent the motor from turning on or off when the second wire is connected to the GPIO pin on the ESP32 board, you can use a transistor as a switch to control the motor circuit.

A transistor is a three-terminal electronic device that can be used to amplify or switch electrical signals.

When a small current flows through the base terminal of the transistor, it allows a larger current to flow through the collector and emitter terminals, allowing you to control a high-power device such as a motor using a low-power device such as an ESP32.

Here is an example YAML configuration that uses a transistor to control the motor circuit with the ESP32:

# Configure the GPIO pin for the motor control
output:
  - platform: gpio
    pin: 13
    id: motor_control_pin

# Configure the motor control switch
switch:
  - platform: gpio
    pin:
      number: 13
      mode: INPUT_PULLUP
    name: "Motor Control Switch"
    id: motor_control_switch
    on_turn_on:
      - switch.turn_off: motor_control_pin
    on_turn_off:
      - switch.turn_on: motor_control_pin

# Configure the transistor for the motor control
output:
  - platform: gpio
    pin: 4
    id: transistor_pin

# Configure the push button for the motor control
binary_sensor:
  - platform: gpio
    pin:
      number: 0
      mode: INPUT_PULLUP
    name: "Motor Push Button"
    on_press:
      - switch.turn_on: transistor_pin
    on_release:
      - switch.turn_off: transistor_pin

In this configuration, the output component is used to define the GPIO pin that will be used to control the motor.

The switch component is then used to define a switch that will be controlled by the motor control switch, and the on_turn_on and on_turn_off actions will be used to turn the motor control pin on or off accordingly.

The output component is then used to define the GPIO pin that will be connected to the base terminal of the transistor, and the binary_sensor component is used to define a push button that will control the transistor.

The on_press and on_release actions will be used to turn the transistor on or off accordingly, allowing the motor to be controlled by the push button.

You can customize this configuration by changing the GPIO pin numbers and the transistor pin number to match your setup.

The question is lacking many details. It’s unclear e.g. what voltages are involved. Your gate controller could be 5V whereas the ESP is 3.3V. Connecting the board directly is probably looking for trouble. Your safest option is to use a relay, as it would keep the circuits separate.

Rather draw a picture of your current circuits and provide the configs to get better help.

Hello,

Here is the schematics existing and what I want to implement.

I can’t access the controller etc, am able to use only the push button.

NOTE: Its Normally Open instead of Normally Closed as in the diagram.

Thanks for the detailed explanation. I have a irf520n handy from an arduino kit that I can use.
However, getting some error on the coding part.

It says ‘duplicate’ error on the second output and I am not able to regroup it under the first output. It fails to see the switch and binary_sensor.

Thanks again.

How do you plan on powering the ESP32?

EDIT: Is that really a normally closed switch? (so the controller is looking for an open circuit?)

The “duplicate” error that you are encountering likely indicates that you have defined the same entity (such as a switch or binary sensor) multiple times in your ESPHome configuration. ESPHome does not allow you to define the same entity more than once, so you will need to make sure that each entity has a unique ID and name.

Here is an example of how you could modify your ESPHome configuration to avoid the “duplicate” error:

Copy code

gpio:
  - platform: ESP32_GPIO
    pin: 13
    mode: INPUT_PULLUP

binary_sensor:
  - platform: gpio
    pin:
      number: 13
      mode: INPUT_PULLUP
    name: "Motor Switch"
    id: motor_switch
    on_press:
      - switch.turn_on: motor
    on_release:
      - switch.turn_off: motor

switch:
  - platform: output
    id: motor
    output: 13

In this configuration, the binary sensor and switch each have a unique ID and name, so the “duplicate” error should not occur. The binary sensor is also configured to trigger the motor switch when the pin is pressed or released, so you should be able to control the motor using the push button.

Thanks for the explanation. Reason why I had always been using Tasmota, albeit here esphome would be faster.

The code still throws an error on the platform: ESP32_GPIO

 Component gpio cannot be loaded via YAML (no CONFIG_SCHEMA).

:neutral_face:

My mistake, its Normally Open