My 15-year-old T-Concept with door intercom is pretty far away from a smart solution. But with a Raspberry Pi it’s possible to bring them a little bit closer to a smart home and add some useful features.
The most important thing for me was to know when the door bell was pressed and to be informed by e-mail every time someone ring. In addition, a photo should be created on the Picamera and added to the mail.
Sounds easy - after a few tests, many meaningless mails and adjustments it was done ...System design
The Raspberry Pi requires an installed Picamera. To find a favorable position of the camera the included ribbon cable is normally too short. Fortunately, there are also much longer variants to buy. For me, a length of 2 m works still perfect. The Raspberry itself needs as usual Raspbian as the operating system. The version of the Raspberry does not matter. I use a Raspberry Pi B +, which I have integrated into my network via WLAN stick.
The telephone system offers the possibility to program user 4 contacts. This helps excellently to produce a bell signal - without much soldering - for further actions on the Raspberry. If the manual is no longer available, a short Google search with "Operating Instructions T-Concept x311" helps. Deutsche Telekom kindly provides all documents in its archive. The programming of the contacts is dedicated to a separate chapter. For the setting, only the phone at port <21> can be used. If you know this, that's no problem. If you don't want to try all, the easiest way is to temporarily connect a disused phone to the <21> port for programming.
The programming itself is done quickly. I have chosen the switching contact 1. Each time the bell button 1 is pressed, the contact 1 will be switched on for 3 seconds. Why 3 seconds you get to know below.
- Press (R) key
- Dial (8) (8) >> wait 5 seconds, the you hear a verification tone
- Dial again (8) (8) >> verification tone
- Enter (1) >> contact 1 (possible are 1..4), operating mode 2 (contact mode) for bell key 1
- Dial (8) (1) (3) for contact closing time 3 seconds
- Hang up
The wiring is done by the contacts on the screw terminals.
Any GPIO contact can be used for signal recognition. My example uses pin 16. As with any switch, the signal is pulled by a pull-up resistor against 5 V.
In my home the wires from the Raspberry to the T-Concept are about 30 m long and consists of an existing telephone line. At the beginning, the pin switches reliably on every ring, but also in completely different situations. I suspect that the long line works similar to an antenna, because opening the electric garage door already generated a "bell signal" on pin 16.
My first solution was to install a capacitor between the pin contacts and GND. The first disturbances were so eliminated. But when the lights turned on, there was still a false signal.
To exclude this, I decided to combine it with a software solution. The interference signals always occur very briefly in the milliseconds. A time stamp is set in the program after the first occurrence of a signal. After 1 second it is checked whether the signal is still present. If this is the case, it is now recognized as a real ring signal and further processed. Otherwise it was a malfunctioning signal and is not observed.
The possibility of programming a 3-second switching signal in the telephone system was enormous.
That’s how the programming of the pin looks like:
... pressed16=False ... try: while True: time.sleep(0.2) if GPIO.input(16)==False: #signal recognized, maybe a interference if pressed16==False: #new signal recognized pressed16=True print("Signal at pin 16") #save timestamp time16=datetime.datetime.now() else: #lasts signal longer then 1 seconds? if datetime.datetime.now()-time16>datetime.timedelta(milliseconds=1000): print("Door bell signal") #further steps after door bell ring time16=datetime.datetime.now() pressed16=False ...
In principle, you could also simplify the if condition by using the following structure:
if GPIO.input(16)==False: #signal recognized, maybe a interference #wait 1 second time.sleep(1) #is the signal still there? if GPIO.input(16)==False: print("Door bell signal") #further steps after door bell ring
If only one pin is queried, it does not matter. However, if multiple pins are queried (e.g. as part of a Smarthome solution), you might miss an event. That's why I prefer the first solution.Take a picture
With the Picamera it is very easy to create a picture. Only the library Picamera has to be included in the source code. To take a picture, only 3 lines of code are used:
import picamera camera=picamera.PiCamera() camera.capture('bild.jpg',resize=(1920,1080)) camera.close()
As soon as the camera is contacted, a small red led on the camera will light up. This may not be desirable. To turn this off, you have to insert an additional line in the file /boot/config.txt.
The Raspberry Pi Foundation has now also released its own e-book that explains all the functions excellently. For a link, see www.raspberrypi.org/magpi/issues/essentials_camera_v1.Send an email with picture
There are also ready-made functions for sending mails in Python. If you do not know the setting values for your mail access by heart, look best in the used mail program-mostly under account-after.
Start Python programs automatically
def MailVersendenMitFoto(betreff,txt): try: sfrom='Smarthome <firstname.lastname@example.org>' sto='Thomas Angielsky <email@example.com>' #Path to picture of the Picamera sfn='/home/pi/smarthome/bild.jpg' #create mail body stxt=txt+'\nTime: '+zeit.strftime('%d.%m.%Y %H:%M:%S') stxt=stxt+'\n\nPicture:' mime=MIMEMultipart() mime['from']=sfrom mime['to']=sto mime['subject']=Header(betreff,'utf-8') mime.attach(MIMEText(stxt,'plain','utf-8')) f=open(sfn,'rb') part=MIMEApplication(f.read(),Name=basename(sfn)) f.close() part['Content-Disposition']='attachment' filename='"'+basename(sfn)+'"' mime.attach(part) #SMTP server smtp=smtplib.SMTP('smtp.mailadresse.de') smtp.starttls() smtp.login('name@mailadresse','kenntwort') #Mail senden smtp.sendmail(sfrom,[sto],mime.as_string()) smtp.quit() except: print('Error sending mail')
There are several ways to start a program automatically with the system. I use the the/etc/rc.local. The rc.local is executed at the end of the start process of Linux.
The following line has to be inserted in the rc.local before exit 0:
su pi -c “python /home/pi/smarthome/smartgpio.py &“
With this, smartgpio.py starts automatically with every boot and waits for ring signals.Expansions
The door intercom is an interesting area for smarthome and further ideas. I have marked the following for me:
- Instead of sending a picture, also record a video, eg. B. 10 seconds after ringing
- Make all events available through a web server: ring list with date, time per day, show the pictures in the list, play the videos in the list
Maybe I can report later on this project.
PS: Wenn Sie diesen Beitrag in Deutsch lesen möchten, schauen Sie doch in meinen Blog auf techpluscode.de.