Thanks to Felix Mueller ,SlimServer announcement script http://www.gwendesign.com/slimserver/dev_software.htm.
Just copy the script to your scripts folder and name it (mine is deurbel1.pl).
Fill in your ip of your lms and cli port (standard 9090). Tell where your mp3 file is to be playing (mine is /volume1/Music/Deurbel/Christmas.mp3).
You can set if you want the mixervolume on line 173.
Now make in domoticz a dummy switch and paste in the 'on action' the name of the script (script:///volume1/@appstore/domoticz/var/scripts/deurbel1.pl).
So when the switch is on , you here your sound through the speakers. A use it for the doorbell ringing.
Note: when music playing (radio, etc...) the music paused , mp3 sound come through and then the music unpaused and plays on.
Hope someone can use it.
Happy 2017 !!
Code: Select all
#!/usr/bin/perl
# ********************************************************************
# Simple announcement script for SlimServer using the CLI v0.6
#
# Copyright (c) 2003 Felix Mueller (felix.mueller(at)gwendesign.com)
#
# This file might be distributed under the same terms as the
# SlimServer (www.slimdevices.com)
#
# Description:
# Plays a sound and shows a message interupting the current song
# - Store current parameters
# - The sound is appended to the current playlist and played
# - After the duration of the sound the sound is removed
# - Resume playing the current song
# - Restore current parameters
#
# Plattform tested:
# - Linux
#
# Known restrictions:
# - trancoded files (i.e. ogg) will restart at the beginning after
# the announcement
# - a shuffled playlist will be reshuffled
# - does not work with iTunes (maybe works only with real SLIMP3)
#
# History:
# 0.6 - Added parameters for user/password (thanks to Mario Wagner)
# 0.5 - Adapted and tested with SlimServer 5.1.1
# 0.4 - Added command line parameter: --name --server --ip --line1 --line2 --sound
# - Added player selection by name
# 0.3 - Added power and volume persistency
# ********************************************************************
use strict;
use Getopt::Long;
use IO::Socket;
# Parameter defaults overridden by command line
my $szServerIP = "your ip here";
my $iServerCLIPort = 9090;
my $szPlayerName = "Keuken";
my $szLine1 = "Line1 text";
my $szLine2 = "Line2 text";
my $szSound = "/volume1/Music/Deurbel/Christmas.mp3"; # path on the machine where announcement.pl runs
my $user = "";
my $passw = "";
# Internal parameters
my $debug = 0; # 0 = off, 1 = on
GetOptions( "server:s" => \$szServerIP,
"port:i" => \$iServerCLIPort,
"name:s" => \$szPlayerName,
"line1:s" => \$szLine1,
"line2:s" => \$szLine2,
"user:s" => \$user,
"passw:s" => \$passw,
"sound:s" => \$szSound);
# Check for a player name
showUsage() if( $szPlayerName eq "");
# Prepare variables
$szPlayerName = encodeChars( $szPlayerName);
$szLine1 = encodeChars( $szLine1);
$szLine2 = encodeChars( $szLine2);
$szSound = encodeChars( $szSound);
# Try to open a connection to the SLIMP3 CLI
my $socket = IO::Socket::INET->new( PeerAddr => $szServerIP,
PeerPort => $iServerCLIPort,
Proto => "tcp",
Type => SOCK_STREAM);
# Check if socket was opened successful
if( !defined( $socket))
{
print "Cannot connect to $szServerIP:$iServerCLIPort\n";
exit;
}
# Login
if ($user ne "")
{
my $login = sendAndReceive("login $user $passw");
print $login;
$debug && print "user: $user, passw: $passw\n";
}
# Get the # of players
my $iNumPlayer = sendAndReceive( "player count ?");
$debug && print "iNumPlayer: $iNumPlayer\n";
# Get the player ip and port from the name
my $szPlayerIPAndPort = "";
for( my $i = 0; $i < $iNumPlayer; $i++)
{
if( $szPlayerName eq sendAndReceive( "player name $i ?"))
{
$szPlayerIPAndPort = sendAndReceive( "player address $i ?");
last;
}
}
$debug && print "szPlayerName: $szPlayerName\n";
# Check if successful
if( $szPlayerIPAndPort eq "")
{
print "Player with name: $szPlayerName could not be found!\n";
close( $socket);
exit;
}
$debug && print "szPlayerIPAndPort: $szPlayerIPAndPort\n";
# Get power status (on, off)
my $iPower = sendAndReceive( "power ?");
$debug && print "iPower: $iPower\n";
# Get shuffle status (on, off)
my $iShuffle = sendAndReceive( "playlist shuffle ?");
$debug && print "iShuffle: $iShuffle\n";
# Turn shuffle off
sendAndReceive( "playlist shuffle 0");
# Get mode (play, stop, pause)
my $iMode = sendAndReceive( "mode ?");
$debug && print "iMode: $iMode\n";
# Get current song
my $iIndex = sendAndReceive( "playlist index ?");
$debug && print "iIndex: $iIndex\n";
# Get path and filename to current song
my $iPath = sendAndReceive( "playlist path $iIndex ?");
$debug && print "iPath: $iPath\n";
# Check the song file type (mp3, ogg, wav)
my $iMP3 = 0;
$iMP3 = 1 if( $iPath =~ m/mp3$/);
$debug && print "iMP3: $iMP3\n";
# Get the current position (in s)
my $iTime = sendAndReceive( "time ?");
$debug && print "iTime: $iTime\n";
# Stop the current song
sendAndReceive( "stop");
# Add the announcement sound file at the end of the playlist
sendAndReceive( "playlist append $szSound");
$debug && print "szSound: $szSound\n";
# Get the number of tracks in the playlist
my $iTracks = sendAndReceive( "playlist tracks ?");
$iTracks -= 1;
$debug && print "iTracks: $iTracks\n";
# Is now -1 if playlist was empty
$iTracks = 0 if( $iTracks < 0);
# Get the volume
my $iVolume = sendAndReceive( "mixer volume ?");
$debug && print "iVolume: $iVolume\n";
# Set a volume for the announcement
sendAndReceive( "mixer volume 65");
# Play the announcement sound
sendAndReceive( "playlist index $iTracks");
# Get the duration of the announcement sound
my $iDuration = sendAndReceive( "playlist duration $iTracks ?");
$debug && print "iDuration: $iDuration\n";
sleep( 1);
# Show the announcement message
sendAndReceive( "display $szLine1 $szLine2 $iDuration");
# Wait until announcement sound has finished
sleep( $iDuration);
# Stop it
sendAndReceive( "stop");
# Mute output
sendAndReceive( "mixer volume 0");
# Remove the announcement sound from the playlist
sendAndReceive( "playlist delete $iTracks");
# Reselect the old song
sendAndReceive( "playlist index $iIndex");
# Set the player in the old mode
if( $iMode eq "stop")
{
sendAndReceive( "stop");
}
elsif( $iMode eq "pause")
{
if( $iMP3 == 1)
{
sendAndReceive( "time $iTime");
sleep( 1);
}
sendAndReceive( "mode pause");
}
elsif( $iMode eq "play")
{
if( $iMP3 == 1)
{
sendAndReceive( "time $iTime");
}
}
# Reinstate the volume
sendAndReceive( "mixer volume $iVolume");
# Reinstate the shuffle mode
sendAndReceive( "playlist shuffle $iShuffle");
# Reinstate the power mode
sendAndReceive( "power $iPower");
close( $socket);
# ---------------------------------------------
sub sendAndReceive
{
my $cmd = shift;
return if( $cmd eq "");
# $cmd = $szPlayerIP . encodeChars( ":") . $iPlayerPort . " " . $cmd;
if( $szPlayerIPAndPort ne "")
{
$cmd = $szPlayerIPAndPort . " " . $cmd;
}
print $socket "$cmd\n";
my $answer = <$socket>;
$answer =~ s/$cmd //i;
$answer =~ s/\n//;
return $answer;
}
# ---------------------------------------------
sub encodeChars
{
my $myChars = $_[0];
my $MetaChars = quotemeta(' ;,/?\|=+)(*&^%$#@!~`:');
$myChars =~ s/([$MetaChars\"\'\x80-\xFF])/"%" . uc( sprintf( "%2.2x", ord($1)))/eg;
return $myChars;
}
# ---------------------------------------------
sub showUsage
{
print "usage: slimp3announcement.pl <parameters>\n";
print "\n";
print "Mandatory parameter:\n";
print "--name=<player name>\ti.e.: \"my slimp3\"\n";
print "\n";
print "Optional parameters:\n";
print "--server=<ip>\t\tdefault: 127.0.0.1\n";
print "--port=<nr>\t\tdefault: 9090\n";
print "--line1=<text>\t\tdefault: \"Line1 text\"\n";
print "--line2=<text>\t\tdefault: \"Line2 text\"\n";
print "--user=<text>\t\tdefault: \"\"\n";
print "--passw=<text>\t\tdefault: \"\"\n";
print "--sound=<soundfile>\tdefault: /music/_Diverses/gotmail19.mp3\n";
exit;
}