1

I'm about to start building a wireless custom doorbell system using pigpio. It is a three piece system that I will be making. The front doorbell which will communicate via two scripts to two different RPIs. This is done because the chime systems have a display value of two items I want from a visual perspective. One will play an MP3 and the other the clip MP4. In both scripts I need to identify a specific MP3 or MP4 for a button press. For example if I press the button on my front door RPI it should run MP3-1 and MP4-1 and if I press it again MP3-2 and MP4-2. I can run multiple using a random number generator which is not difficult

randint(0,9)
if number == 1 etc. 

Assign a value to each mp3 or mp4 and if the number is equal to that number then that file will play. I am trying to run a specific file for the first press and a separate file for the second press on the same button. I am not sure how to count the presses and perform a new action with each one. If I can get the system to recognize press 2 then I should be able to run it. I appreciate any insight.

  • How about setting 'press = 0' then incrementing press each time the doorbell is pressed 'press += 1'. You may want to reset to 0 when 2 is reached or maybe after some delay? – CoderMike Apr 24 at 15:16
  • ok so I could do press=0 the while true if button is pressed then press+=1 which would increment the press then I could if press =1 play this file and if 2 this file and if 3 this file etc. That would work I think. Ill try that – user92521 Apr 24 at 15:19
1

Perhaps a boolean variable named "chimeOne", defaulted to False, paired to a datetime object "dt" containing the time the button was pressed. If the button is pressed, chimeOne = True. If within 30 seconds it is pressed again, (determined by if chimeOne == True: #Add an exception if the time elapsed between now and dt is more than 30 seconds), play the second mp3. However, if 30 seconds (or any other interval you can think of) elapses and chimeOne: then chimeOne = False.

The advantage of this is that you won't have a false alarm, if a visitor pressed once, and a couple days later, another visitor presses the doorbell.

Here's a skeleton script showing the basic outline of the procedure:

import re
from datetime import datetime

"""
When a button is pressed, call the procedure onDoorbell().
Make sure to add code to play the MP3/MP4
"""


timeStamp = None
chimeOne = False

def retTimestamp(type): #Handles date/time settings

 data = re.compile('\w+').findall(text) 

 return data 

def onDoorbell: #Handles doorbell push

 if chimeOne:

  data = retTimestamp()

  oldHour   = int(data[1])
  oldMinute = int(data[2])

  global timeStamp, chimeOne

  timeStamp = datetime.now().strftime('%H %M')

  data = retTimestamp()

  nowHour = data[1]
  nowMinute = data[2]

  if nowHour == oldHour and nowMinute == oldMinute:
   """
   Play the second MP3 if the second push was within
   the same minute of the first.
   """
  else:
   """
   Play the second MP3; the second push happened
   too late.
   """

  chimeOne = False

 else:

  global timeStamp, chimeOne

  timeStamp = datetime.now().strftime('%H %M')
  chimeOne = True

  """
  Play the first MP3.
  """


  • That's actually really interesting because using the hour and minute variables would like you said allow to ensure the same chime does not repeat. I would need to use elif since this will be about 15 mp3s so I would have to add a loop on it so if the pushes were exceeded it would start back at the first MP3 but that's something to look at. Once I get it running ill need to modify – user92521 Apr 24 at 17:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.