As one of my first domoticz project I today completed my Sonos barking doorbell. And I am so happy with it, my kids now call me "Doorbell" for the rest of my life.
I used http://www.dannyvanmaanen.nl/?p=1546 info to create a parallel connection to my existing doorbell, running ac 8v by creating a "equalizing bridge" (proper word for 4 diodes?) and elco which drives a relay.

This relay switches the GPIO (pin 17) using a pull up/down schema as presented on https://www.cl.cam.ac.uk/projects/raspb ... _switches/

(has two button detection points, for future use. ps.how can I resize images on this BB?)
Domoticz fires a small php script which kicks the sonos as well as a telegram message. On Action: script:///home/pi/domoticz/scripts/doorbell.php
The sonos.class.php is taken from https://github.com/DjMomo/sonos/blob/ma ... .class.php. I included a small function to find the IP of the Sonos using the name. Maybe not most efficient for the Pi CPU, but easier for me now.
The script tests for repeated doorbell pressing by the person in front or because of the relay clicking too often. The script runs a few seconds. Maybe too long, but for now it works for me.
The barking sound is taken from youtube (keepvid and then use formatfactory to transcode to mp3).
Simple stuff, but so happy my first project is now completed!
doorbell.php
Code: Select all
#!/usr/bin/php
<?php
require_once '/var/www/homealarm/sonos.class.php';
function find_ip_sonos($room_name)
{
$temp_stuff = new SonosPHPController('192.168.178.33');
$devices = $temp_stuff->detect();
foreach ($devices as $device) {
if (strtoupper($device->device_info()['roomName']) == strtoupper($room_name)) {
$raw_ip=explode("-",$device->device_info()['friendlyName']);
return str_replace(" ","", $raw_ip[0]);
}
}
}
// get the time and compare with last doorbelpresstime
$now=time();
if (file_exists("/tmp/doorbell.time") ) {
// read the session date if that exists
$lastchangedate=intval(file_get_contents("/tmp/doorbell.time"));
}
else
$lastchangedate = 0;
// only fire up when there was a press 10 minutes ago
if (($now-$lastchangedate)>10*60) {
// Write the last press time
file_put_contents("/tmp/doorbell.time", $now, LOCK_EX);
//Fire up the Sonos
$sonos_1 = new SonosPHPController(find_ip_sonos("keuken"));
$sonos_1->SetMute(0);
$sonos_1->RemoveAllTracksFromQueue();
$sonos_1->SetVolume(50);
$sonos_1->SetQueue('http://192.168.178.33/homealarm/dog.mp3');
$sonos_1->Play();
$last_line = system('/home/pi/tg/bin/telegram-cli -U pi -k /home/pi/tg/tg-server.pub -W -e "msg My_Name Deurbel gaat!"', $retval);
}
else
{
// otherwise: do nothing (maybe later some implementation)
};
?>
Regards
Tom