Skip to content

Instantly share code, notes, and snippets.

@dglaude
Last active April 29, 2020 06:36
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dglaude/7ac54e7a198c2a869879c8b016703431 to your computer and use it in GitHub Desktop.
Save dglaude/7ac54e7a198c2a869879c8b016703431 to your computer and use it in GitHub Desktop.
Xmas doorbell using automation hat (@pimoroni) with some debounce.

The door button is connected to input 1. This is an indirect connection, the button trigger a relay (not on the Automation HAT). That relay does trigger a traditional doorbell, but also connect the 5V from the automation HAT to the input 1.

On relay 3 o I have a battery powered amplifier, the relay is between the amplifier and the battery. Turning the relay 3 on, power from the battery goes to the amplifier. This is done to avoid emptying the battery when no sound is produced.

At that point I can play audio on the analogue output of the Pi and play some music.

Randomly, the automation hat (library) would register an event when there was no one on the door. So I added some "debounce" to verify that the event is real and stay visible for an extra 0.1 second.

I hope this will not wake me up in the middle of the night or very early in the morning.

#!/usr/bin/env python
import time
import pygame
import automationhat
pygame.mixer.init()
pygame.mixer.music.load("test.wav")
if automationhat.is_automation_hat():
automationhat.light.power.write(1)
while True:
if automationhat.input.one.is_on():
print('Is this a ghost event???')
time.sleep(0.1)
if automationhat.input.one.is_on():
print(' Someone has his finger on it.')
automationhat.relay.three.on()
time.sleep(0.5)
pygame.mixer.music.play()
while pygame.mixer.music.get_busy() == True:
continue
time.sleep(0.5)
automationhat.relay.three.off()
else:
print(' Someone not pressing long enough?')
time.sleep(0.1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment