Skip to content

Instantly share code, notes, and snippets.

@HarvsG
Last active October 26, 2024 16:42
Show Gist options
  • Save HarvsG/35aef01640f3e147e31081cd0da53bbf to your computer and use it in GitHub Desktop.
Save HarvsG/35aef01640f3e147e31081cd0da53bbf to your computer and use it in GitHub Desktop.
How I made a dumb Entryphone smart

How I made my doorbell smart

The Problem

I have a simple door entry phone that buzzes when someone rings the bell and lets me 'buzz' them in. I would like some smarts. Firstly I want to be able to notify and automate when someone rings and secondly I would like to be able to buzz people in.

Entry phone systems vary throught the world and so it is unlikely this write-up will work for you, so I have spelt out the general principles I used and the steps I took.

The ingredients:

  • Raspberry Pico W
  • ESP home installed on the above
  • HomeAssistant with ESP home
  • Some electrontics equipment
    • Breadboard for prototyping
    • Opto couplers 2x 4N35
    • N-channel logic MOSFET (I canabalised at 816 48 13NHG from an old xbox 360)
    • Resistors - 2x 1kOhm, 100kOhm, 330 Ohm
    • 1.5kOhm and 220kOhm, 2x 5.1kOhm, 1 mOhm resistors also used during prototyping

The entry phone

image

  • Work out which pins to read for 1. Doorbell rung 2. Door open and 3. Ground
    • CALL, PB and COM (I think)
  • test if CALL goes to 12v on buzzer press
  • Check resistance between CALL and COM in normal state (tape down handset) would 10+2.5 kOhm connection change this resistance
  • Check for voltage spikes on COM/CALL during the push button press that could harm the pico - if multi-tool has a 'max' mode
  • Check voltage across a known resistor when PB CALL is 12v to see if there are any other loads on the circuit (would affect the voltage divider)
    • PB had a 22kOhm load so although to appeared to be at 12v when the circuit closed the PB side dropped to a fraction of that, which meant a few things had to be changed.

The Circuit:

With two optocouplers (what I went with in the end) https://crcit.net/c/14f1505d729144da9be00751296bb810 image

The above shows a Raspberry Pico. The top circuit shows an optocoupler between CALL and COM, with the GP22 PIN with a (possibly unecesassry) external 100kOhm pulldown.

The second circuit is to bridge PB and COM (opening the door when GP20 goes to HIGH - 3.3v). It comprises an optocoupler (4N35 218Q - N.B dimple corresponds to PIN 1, (PINS 6 & 3 unused in this) a resistor and a MOSFET. On the LED side of the optocoupler a 1kOhm resistor keeps the rated current across the LED low. R = (3.3v source - 1.1v LED drop)/Rated Current 0.01 - 0.001 Amps) = 220 - 2200ohms. Online calculator

Because the photoresistor on the 12v cannot take much current it is in parallel with an N-channel (logic) MOSFET, the MOSFET allows current from the Drain to the Source only if the Gate has a positive voltage (compared with source). So in combination when the optocoupler LED is off there is no connection between PB and COM. When the LED is on, the resistance across the photoresistor drops a lot, meaning that the gate now rises to approx 12v (turns out there is a 22kOhm load earlier in the PB-COM circuit so the voltage didn't rise as high as this), this 'opens' the MOSFET and connects PB and COM, opening the door. In the end I had to reduce that resistor from 100kOhm to 1kOhm - it then started working. Anything higher didn't. I still don't understand why. On discussion with an expert - this is probably because when the resistor is too high the potential across the phototransistor drops below the forward voltage and so there is no flow acrross the photoresistor to the gate.

Possible diagram (With only 1 optocoupler)

In this version a the voltage divider is used instead of an optocoupler in reverse, this means that there is not complete electrical isolation between the 12v and 3.3v side. I could not get the voltage divider to work reliably but YMMV.

https://crcit.net/c/b0f986634f6d4ad8b117fb7180860448 image

The 10khm, 2.5kOhm take means that the voltage between the two resistors is and input of 9v -> 18v corresponds to 1.8v -> 3.6v at the divider (Pico threshold for reading HIGH is approx 1.8v and can safely take up to 3.7v).

Prototyping

Working Breadboard with Dual optocouplers: image Incoming jumpers (Orange 5v power, Black GND, White is CALL, Green COM, Brown PB) N.B using GPIO 18 as door open output and GPIO 21 as doorbell input (internal pull down off).

Breadboard (using 5v instead of 12v so voltage divider resistors are 1.5kOhm and 1kOhm instead) Unfortunately this didn't work in the 12v wild, probably due to other loads in the circuit and/or floating voltages. image The white LED and 220ohm resistor simulates the load between PB and COM (solonoid door opener) The button before the voltage divider simulates the doorbell, rising CALL to the higher voltage.

Micropython prototyping. How to install, and using the REPLY serial interpreter to do live testing

>>> from machine import Pin
>>> led = Pin("LED", Pin.OUT)
>>> pb = Pin(20, Pin.OUT)
>>> call = Pin(22, Pin.IN, Pin.PULL_DOWN)
>>> pb.value(1) # should light the white LED
>>> pb.value(0) # should turn off the white LED
>>> print(call.value()) # should return 1 when button is pressed and 0 otherwise

>>> while True:
...     led.value(call.value())
# Should cause the onboard LED to light up whenever the button is pressed.

MK 1

I re-made the (dual optocoupler) circuit on a strip board, which turned out to be much simpler once I worked out how to cut tracks. I used different GPIO pins from the ones in the prototype (I think I might have fried GPIO22). image image

This is a much closer wiring diagram to how I wired it: https://www.circuit-diagram.org/circuits/ff130116e43f4b0aa6a463ca0cdf300e image A few differences to the real thing

  • I used a different GND for the power supply - but it would look ugly on the diagram.
  • The call optocoupler in real life had diodes that runs the otherway to 3v3 is below the resistor.
  • The 1kOhm resistor is acutally under the MOSFET which is mounted on raised header pins.

I then compiled and installed the below yaml file.

It works great!

Credits

Thans to u/sparks333 who was a great help in this thread

Notes:

  • I avoided Pins 26-29 as they are used for ADC (analog inputs) and so are less tolerant of over-voltage!
  • Current limiting resistor on the optocoupler LED should be 220-2,200 ohms. (Aiming 1-10mA with voltage drop of 1.1 - 3.3-1.1/0.01)
  • When I couldn't compile ESPHome on HomeAssistant or RPi 4, I used esphome on a local docker install sudo docker run --privileged -v /home/george/esphome/config:/config -v /etc/localtime:/etc/localtime:ro --name esphome -p 6052:6052 esphome/esphome (And made sure to copy the API and OTA keys from the yaml from the HA install of ESPhome). Navigate to 127.0.0.1:6052
  • I found that even if I kept it on 'unlock' the solonoid had a timer (presumably a safety feature) so then this switch state would go out of sync, so I switched to a button press.

Rescources:

Searching for 806-20MDP600-10

Got me here: https://www.channelsafety.co.uk/door-entry-systems/entritech-audio-only/surface-mounted-kits/entritech-audio-only-6-way-surface-mounted-kit/

Wiring diagram:https://www.channelsafety.co.uk/wp-content/uploads/2015/09/Audio-Door-Entry-with-Trade-Button-and-Lock-Indication.pdf

Data Sheet: https://www.channelsafety.co.uk/wp-content/uploads/2015/08/ENTRitech-Audio-Only-013-2.pdf

Unfortunately the colours used in the diagram don't seem to correspond to the colours on the wiring I have.

esphome:
name: front-door
rp2040:
board: rpipicow
framework:
# Required until https://github.com/platformio/platform-raspberrypi/pull/36 is merged
platform_version: https://github.com/maxgerhardt/platform-raspberrypi.git
# Enable logging
logger:
# Enable Home Assistant API
api:
encryption:
key: "redacted"
ota:
password: "redacted"
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
# Enable fallback hotspot in case wifi connection fails
ap:
ssid: "Front-Door Fallback Hotspot"
password: "l1NcPs6FoV8G"
output:
- platform: gpio
pin:
number: 18
mode: output
id: PB
- platform: gpio
pin:
number: 32 # 25 for Pico (non-W)
mode: output
id: LED
light:
- platform: binary
name: "Onboard LED"
output: LED
entity_category: config
restore_mode: ALWAYS_ON
switch:
- platform: output
output: PB
id: unlock
restore_mode: ALWAYS_OFF
internal: true
button:
- platform: template
id: unlock_for_5
name: Door Release (5s)
on_press:
then:
- switch.turn_on: unlock
- delay: 5s
- switch.turn_off: unlock
binary_sensor:
- platform: gpio
pin:
number: 21
mode:
input: true
pulldown: false
id: CALL
name: Door Bell
device_class: sound
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment