ESP32 Gate Opener

So I actually looked up the spec sheet for the onto-coupler. The 5v for the relay I was fine with as there is a VCC input on the board for this and I used the 5v available from the ESP Devboard.

My query was about the voltage being applied to the signal pins that trigger the optocoupler. As mentioned, I’ve looked them up with a working range up to 6v max, so figured the 3.3v would be fine. I’ve tested it and it works perfectly.

I installed it onto my gates this weekend and now have a pulse from one relay to open the gates and I’ve put the second relay to use on the safety closure circuit enabling me to hold the gates open until I release which is a handy feature to add as previously the gates would always close after 30 seconds or so unless I went and blocked the light beam safety closure.

I’ve attached the ESPHome programming below as I’ve also added temp and light sensors as well as a bluetooth proxy.

esphome:
  name: esphome-web-xxxxx
  friendly_name: ESPHome Gate

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

# Enable logging
logger:

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

ota:

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

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Esphome-Web-xxxxxx"
    password: "xxxxxxxxxx"

captive_portal:

i2c:
  sda: 21
  scl: 22
  scan: true
  id: bus_a

sensor:
  - platform: bme280_i2c
    temperature:
      name: "Gate Temperature"
      oversampling: 16x
    pressure:
      name: "Gate Pressure"
    humidity:
      name: "Gate Humidity"
    address: 0x76
    update_interval: 60s

  - platform: bh1750
    name: "Gate Illuminance"
    address: 0x23
    update_interval: 60s

switch:
  - platform: gpio
    pin: 25
    id: relay1
    inverted: True
    restore_mode: ALWAYS_OFF
    name: "Gate Switch"
    icon: "mdi:gate-open"
    device_class: switch
    on_turn_on:
    - delay: 500ms
    - switch.turn_off: relay1

  - platform: gpio
    pin: 26
    id: relay2
    inverted: True
    restore_mode: ALWAYS_OFF
    name: "Gate Hold"
    icon: "mdi:gate-alert"
    on_turn_on:
    - delay: 250ms
    - switch.turn_on: relay1

esp32_ble_tracker:
  scan_parameters: 
    #interval: 1100ms
    #window: 1100ms
    active: True

bluetooth_proxy:
  active: True

I’ve added 3 contact sensors to a Brizebox parcel / letterbox fitted next to the gates. Unfortunately the bluetooth signal is a bit weak because of the distance between the ESP32 and the Brizebox and the fact that the Brizebox is a big metal container.

I’ve ordered a PoE ESP32 to replace the Wifi board there and will disable / remove the Wifi element as it will be conflicting with the Bluetooth signal a bit in the hope that this will be sufficient to make the bluetooth connection reliable.

It’s called “human error”.

But it’s OK because that only cost me 2 weeks of waiting and ~$5.

On a later post, linked right in the post you’re criticizing, I explain how to use PWM and a MOSFET to drive a bare LED strip:

I’m not entirely sure what the point of your criticism is.

The LED strip got pretty hot to the touch when I turned it on while rolled up for 30 seconds over here.

(No such problem once the LED strip was installed in its destination, a Prusa MK4 enclosure.)

We respectfully disagree.

Yeah, I later realized that you are using a relay module and therefore supplying VCC + signal works fine. Great success!

Yup, that’s what you get as a benefit with all the other gizmos on the module aside from the relay. You should still add a bypass diode between ground and the control pin, lest back EMF fries your ESP32 (I don’t see one on the module).

FYI thanks to you I ordered the exact same modules and I’ll be playing with them next weekend. Thanks!

Have you considered using an ESP with a socket for an external antenna, and routing the antenna out of the mailbox somehow? This should solve your issue without needing to hope for anything.

Thanks for the feedback, I think this is the first bit of electronics I’ve done since playing with model trains 35+ years ago!

With regards to the diode you mention, can you explain a little further how this works and what / where it should be fitted? I understand what it’s intended to protect but I’ve no idea what I should place and where!

Next up I want to out this is a little box as I don’t like the idea of it laying inside the ip66 gate control box as it seems a bit exposed with the pins etc.

Ah I didn’t know there was such a thing. Damn I’ve already ordered a couple of Poe esp32’s and they probably don’t have that….

Digikey PoE ESP32

Check this out:

Thanks for that. Really interesting. I won’t pretend to understand all of it, but I’m largely there. Will look into the flyback diode and also see if there’s any info on the relays to see if it’s built in.

1 Like

Any relay you buy as a module should have a flyback diode built in.

diode

1 Like

I apologize if it sounded like i wss criticising you or your work, that wasnt my intention. To be 100% honest I think i was a little bit aggregated because, I remember how overwhelming and stressful this stuff was to first learn and I personally thought you were adding unnecessary steps or adding unnecessary confusion to those just starting.

.The time and effort you put into this is very much appreciated and its very obvious that your coming from a place of wanting to help others, it shows.

Believe it or not, I come from that place too but, Im fully aware that I can be seem a little abbrasice or perhaps very abbrasive, IDK.

My comments are just meant to be my opinion of things that can use improvement or edits if you are open to my suggestions.

Keep doing doing what your doing though!

1 Like

Hi all,

A little update. Yesterday I swapped the ESP development board out for an Olimex ESP32-PoE.

The reasoning behind this was that I’d actually put a Wifi AP out by the gate purely for the ESP (un-necessary but wanted to see if I could control the gate) and as part of this ESP’s services, I was wanting to pick up some Bluetooth contact sensors that I’d fitted to my letter box. Unfortunately the bluetooth signal was largely not working which I read was likely to be related to interference from nearby Wifi.

So I swapped out the ESP, removed the wifi configuration and used a new configuration for the Olimex which I connected to a PoE cable. I can now say that the bluetooth is working reliably as well as having the same control over the gate.

I did have to re-allocate the pins for the gate relays as 25 and 26 are not available on the Olimex (not sure why), but after determining that GPIO 3 is either not working on my board or for another technical reason, I got the relays running off of GPIO 1 and 2.

I’ve only 1 problem that has introduced itself as part of this board change, and that is when the ESP board is reset, either by way of plugging in the Cat5e cable or flashing the ESP it triggers both the relays briefly causing the gate to open which isn’t ideal.

I’ve got settings in place already to set the pins to DEFAULT: ALWAYS_OFF, so not sure what else I can do.

Anyone with any thoughts on this? Is it anything to do with the lack of flyback diode already mentioned? Just to note, this didn’t happen on the previous board.

*Edit, just read @Spiro comment showing that the flyback diodes are there already, many thanks!

Thanks
Barry

esphome:
  name: esphome-poe-gate
  friendly_name: ESPHome PoE Gate

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

# Enable logging
logger:

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

ota:

ethernet:
  type: LAN8720
  mdc_pin: GPIO23
  mdio_pin: GPIO18
  clk_mode: GPIO17_OUT
  phy_addr: 0
  power_pin: GPIO12

switch:
  - platform: gpio
    pin: 1
    id: relay1
    inverted: True
    restore_mode: ALWAYS_OFF
    name: "Gate Switch"
    icon: "mdi:gate-open"
    device_class: switch
    on_turn_on:
    - delay: 500ms
    - switch.turn_off: relay1

  - platform: gpio
    pin: 2
    id: relay2
    inverted: True
    restore_mode: ALWAYS_OFF
    name: "Gate Hold"
    icon: "mdi:gate-alert"
    on_turn_on:
    - delay: 250ms
    - switch.turn_on: relay1

esp32_ble_tracker:
  scan_parameters: 
    interval: 1100ms
    window: 1100ms
    active: True

bluetooth_proxy:
  active: True

Also, just to add how I have them controlled from indoors currently.

I’ve added them to Home Assistant, in a very basic form currently.

This is the device view, the ESPHome code creates these switches automatically in HA making it real easy for me to just drop them on a dashboard wherever.

It does nothing more than show the relay switches at this time. I will be adding a sensor to the gates themselves to show their current state and then hopefully making a much nicer button with that information on it and the two opening options.

At this point I can’t see anything in the Faac gate controller that gives an output of the gate operation status that I can easily integrate with the ESP32.

Faac controller manual

I’ve used a helper drop down to report the state of the Brizebox and that helper is used here to show the state in human readable text.

I’ve created an automation that monitors the triggers of 3 bluetooth sensors for the postbox (Brizebox postbox (UK). Ive done this with Xiaomi MCCGQ02HL sensors after watching Mark Watt Tech’s brilliant video of the same Mark Watt Tech Brizebox

The automation I created sends notifications to a group (the adults of our house) when a letter or parcel has been delivered (sensors on both the letterbox flap and the parcel drawer) and also if the parcel drawer or access door has been left open for a long time. The access door sensor also clears down the status of the Brizebox helper to the empty state.

Yaml for the automation below for anyone interested:

alias: Brizebox Status
description: Updates Brizebox Status Helper
trigger:
  - platform: state
    entity_id:
      - binary_sensor.brizebox_letter_sensor_opening
    from: "off"
    to: "on"
    id: LetterboxOpened
  - platform: state
    entity_id:
      - binary_sensor.brizebox_parcel_sensor_opening
    from: "off"
    to: "on"
    id: ParcelDrawerOpened
  - platform: state
    entity_id:
      - binary_sensor.brizebox_access_sensor_opening
    from: "off"
    to: "on"
    id: AccessDoorOpened
  - platform: state
    entity_id:
      - binary_sensor.brizebox_access_sensor_door_left_open
      - binary_sensor.brizebox_parcel_sensor_door_left_open
      - binary_sensor.brizebox_letter_sensor_door_left_open
    id: DoorLeftOpen
    to: "on"
  - platform: numeric_state
    entity_id:
      - sensor.brizebox_access_sensor_battery
      - sensor.brizebox_parcel_sensor_battery
      - sensor.brizebox_letter_sensor_battery
    for:
      hours: 0
      minutes: 1
      seconds: 0
    below: 11
    id: BatteryLow
condition: []
action:
  - choose:
      - conditions:
          - condition: trigger
            id:
              - LetterboxOpened
        sequence:
          - choose:
              - conditions:
                  - condition: state
                    entity_id: input_select.brizebox_status
                    state: is empty
                sequence:
                  - service: input_select.select_option
                    target:
                      entity_id: input_select.brizebox_status
                    data:
                      option: has letter(s)
              - conditions:
                  - condition: state
                    entity_id: input_select.brizebox_status
                    state: has parcel(s)
                sequence:
                  - service: input_select.select_option
                    metadata: {}
                    data:
                      option: has letter(s) & parcel(s)
                    target:
                      entity_id: input_select.brizebox_status
          - service: notify.parent_notifications
            metadata: {}
            data:
              message: Letter(s) have been delivered in the Brizebox.
              title: You've got mail!
      - conditions:
          - condition: trigger
            id:
              - ParcelDrawerOpened
        sequence:
          - choose:
              - conditions:
                  - condition: state
                    entity_id: input_select.brizebox_status
                    state: is empty
                sequence:
                  - service: input_select.select_option
                    metadata: {}
                    data:
                      option: has parcel(s)
                    target:
                      entity_id: input_select.brizebox_status
              - conditions:
                  - condition: state
                    entity_id: input_select.brizebox_status
                    state: has letter(s)
                sequence:
                  - service: input_select.select_option
                    metadata: {}
                    data:
                      option: has letter(s) & parcel(s)
                    target:
                      entity_id: input_select.brizebox_status
          - service: notify.parent_notifications
            metadata: {}
            data:
              message: Parcel(s) have been delivered in the Brizebox
              title: You've got parcels!
      - conditions:
          - condition: trigger
            id:
              - AccessDoorOpened
        sequence:
          - service: input_select.select_option
            metadata: {}
            data:
              option: is empty
            target:
              entity_id: input_select.brizebox_status
      - conditions:
          - condition: trigger
            id:
              - DoorLeftOpen
        sequence:
          - service: notify.persistent_notification
            metadata: {}
            data:
              message: One of the Brizebox openings has been left open!
              title: Brizebox left open!
          - service: notify.parent_notifications
            data:
              message: One of the Brizebox openings has been left open!
              title: Brizebox left open!
      - conditions:
          - condition: trigger
            id:
              - BatteryLow
        sequence:
          - service: notify.frigate_notifications
            metadata: {}
            data:
              message: >-
                One or more of the Brizebox sensor batteries require
                replacement.
              title: Brizebox battery warning.
mode: single

No worries and, believe it or not, i appreciate your criticism. I will try to be more concise!!!

Strapping pins :tired_face::tired_face::tired_face::tired_face:

Ah! Before i forget: for all of us working with MCUs and wanting to see signals and spikes like these back EMF spikes, or noise in PSUs / regulators, or the effects of capacitors on an electrical network, here is a super mega turbo pro tip.

You need an oscilloscope, but you do not need a 10.000 dollar oscilloscope.

I got this thing for less than 70 dollarydoos on AliExpress and it is more than adequate for the job:

https://m.aliexpress.com/item/1005006437581064.html

Truly a modern marvel of tech. Just attach the oscilloscope probes to the pins you want to observe, and bob’s yer uncle.

So much stuff I could finally see for myself! And i don’t have to do any of that stuff at my bench.

1 Like

I did see some messages about strapping pins when I programmed. Is there something g I could do to change this or do I need to use different gpio pins? How do I know which are strapping and which are not?

Thanks

Different pins. Those pins do funky stuff during bootstrapping. Thny must not be used for activities that shouldnt happen during ESP reboot. Imagine a brief brownout and then your garage opens while you are not home. Avoid strapping pins.

This is why you should always look over the pinout for the board you are using. A quick glance and you’d see 25&26 are unavailable along with other ones. You dont know why they’re unavailable on this board? See that big ethernet jack on the board? Thats where all those unavailable gpios went and why the POE boards have such fewer pins and capabilities if you havnt noticed its missing more than a few gpios…

You didnt get any strapping pin warnings? Again, this is why you should always refer to the pinout. Esphome isnt perfect and you shouldn’t assume it will do everything for you, it wont and it can be wrong so you must do your own due diligence.

Its very simple, you just go to your search engine of choice and type in, “(your board) esp32 POE pinout” and there you go. Now you know which pins can and cant be used, which pins have what secondary capabilities(ADC
PWM, i2c, etc) and which pins have special requirements for boot mode or other internal functions that you shoild avoid using.

This is the other reason why you need to do your due diligence and check pinouts and user manual. This is where they put really important information and warnings to prevent you from frying your esp32 or possibly your computer too.


One last thing. People are usually extremely vague when asked or post questions regarding their esp boards. They say I have a… “esp32, esp8266 or esp32 POE”.

Maybe youve noticed that there are dozens of versions of esp8266/esp32 and specifically the Olimex esp32 poe boards, there are 8 different models and theyre each different!

You have to look up the pinout and user manual for the board you actually have and hopefully the reason for that is obvious.

This is actually pretty solid advice. Most LED strips build enough enough heat in their rolled up state that they will destroy the chips on board (or their traces, if it matters).
Testing an led strip for voltage drop or other scenarios should mostly only ever be done when the strip isn’t coiled.
It’s fine to test it for a few seconds (minutes, maybe) , but the longer you have it coiled up, the longer the risk of overheating the strip and causing hardware damage.

1 Like

Thanks for the comprehensive reply…

However I have already referenced all of that data, that’s what I was working from. I am aware which board I have, that’s where I bought them from and I followed the links to the documents from there.

The big issue for me as a noob is that I had no idea what a strapping pin is and even that document doesn’t explain that.

I also understand that some of the pins would be used by the PoE connector, I only mention it as it was a shame the same pins weren’t available for me to simply transfer over. I think I’ll look at using some of the pins on the EXT connector.