Converting a simple existing door bell to a smart doorbell with Domoticz

The purpose of this document is to illustrate how to configure and connect Domoticz/Raspberry controller to get a snapshot on our Telegram app when someone push the doorbell.
The 12Vac used to supply the door bell chime or buzzer is connected to an optoisolated input on the DomBus23 module, so when the chime/buzzer is supplied, a trigger is sent to Domoticz that activates a script to grab a picture from the IPcam and send it to a Telegram channel or group, so the family members can receive the photo on their smartphones as soon as someone push the doorbell button.

Hardware example using a DomBus module

Converting an existing door bell to a smart doorbell using Domoticz and Creasol DomBus23

DomBus23 has many inputs and outputs and can be used to performs other functions, such as opening a pedestrian gate or main door (it has 2 relay outputs), manage a courtesy light with led stripe with dimming function (it has a 30V 12A mosfet), ....
If the doorbell uses 230Vac or 110Vac power, it's possible to connect the chime/buzzer to the IN3 optoisolated input, that supports high voltages.

DomBus modules are designed to have a very low power consumption, less than 10mW, and get a very reliable connection to the domotic controller by RS485 bus (simple shielded cable with 4 wires, 2 for data and 2 for 12V power supply). Using a 12V power supply with lead-acid backup battery permits to get the system working even in case of power outage.

Software configuration

It's assumed that you already have Domoticz installed in a computer, like Raspberry PI or another single board computer, or a PC/Mac.
DomBus modules are connected to the domotic computer through a USB/RS485 adapter, and a 12V power supply.

Select the IN1 input device on Domoticz Switches panel, and specify the script to activate when the doorbell ring.

domoticz virtual sensor4

Download the scripts sendsnapshot.sh and telegramSendText.sh from GitHub and put them in DOMOTICZ/scripts directory.
Edit those files to set the IPCam and Telegram parameters.

How to query ONVIF camera to get the video stream and snapshot URI

Some bad chinese ONVIF ipcams do not have snapshot URI: very bad, but we can generate a snapshot from the video stream, using ffmpeg!!

ONVIF is a standard protocol to query ONVIF ipcams, so it's possible to get ipcam characteristics sending some queries using SOAP system.

A very good tutorial to detect video and snapshot URI of your ONVIF camera can be found at http://me-ol-blog.blogspot.com/2017/07/getting-still-image-urluri-of-ipcam-or.html

How to get a Telegram token and chat_id, needed to send messages/pictures by Telegram

Telegram is a very powerful instant messaging system, similar to whatsapp, but much better because open-source, multi-platform (not only for smartphones....Telegram Desktop works on Linux, Mac, Windows!), and very customizable through its API.

The following instructions can be used to get a photo on Telegram when someone push the door bell button.

Below the step-by-step instructions to create a BOT on Telegram and a channel used to send notifications to you and other people:

  1. obviously, you must have telegram installed on your smartphone, and also Telegram Desktop on your PC/Mac/Linux : you can download it from https://desktop.telegram.org/
  2. search in you contact list for BotFather, select it and start it
  3. type /newbot
  4. type a name for this bot, for example domApi
  5. type a username, ending with "bot", for example domApiUserbot
  6. at this point, BotFather will return you an API key (below an example in bold) that you must store somewhere:
    784324329:EETRNJU3jQEGWQdjNv3llb4bnDSDREGuuuL
  7. Now, using your smartphone, create a new channel (not group: channel!), select a name for it (for example Domoticz), set it public and specify a link for it (must be unique), for example t.me/dom123abc 
    Please note that only the channel owner is able to configure the channel as public!
    Add members to this channel: your partner, sons, everyone that should receive domoticz notifications
  8. Enter the channel, and add a new administrator: select the bot that you just created at step 3-6 (search for domApiUserbot or the username typed at step 5)
  9. Add to that channel any other users you want, if you need to send picture/notifications to those users.
  10. Open the following URL from your browser (replace the API key with your, and channellink with your):
    https://api.telegram.org/bot
    784324329:EETRNJU3jQEGWQdjNv3llb4bnDSDREGuuuL/sendMessage?chat_id=@dom123abc&text=test
  11. You'll get an output like the following picture: store somewhere the ID (-1001194779203, in this example): this is the ID for your channel, where domoticz have to send notifications, and you have to write it (with the minus sign, if exist) in the sendsnapshot.sh script below (variable TELEGRAMCHATID).
    telegram channel id
  12. From Telegram on your smartphone, configure the created channel to set channel type Private.
  13. On Domoticz, go to Switches, select the doorbell button input, Edit, and write into the "On Action" text box script://sendsnapshot.sh  : in this way, every time people push the doorbell button, Domoticz will execute sendsnapshot.sh script that will grab a snapshot from the IPCam and send it to Telegram channel, so every user you have put in that channel will receive the photo of people that rang the door bell.