Asterisk tips MythTV integration

The open source PVR application suite named MythTV supports on-screen caller ID notifications. The original source of the caller ID information was from an attached modem, but the application structure allows any source to broadcast the caller ID parameters. This example uses a System() call to invoke mythtv's on screen display (OSD) with caller ID information.

In your extensions.conf, add the "Asterisk cmd System()" line to your dialplan where you receive incoming calls:


exten => s,1,System(/usr/bin/mythtvosd --template=/root/mythtv/mythtv/programs/mythtvosd/cid.xml --caller_name="${CALLERID}" --caller_number="${CALLERIDNUM}" --caller_date="${DATETIME}")
exten => s,2,Wait(1)
exten => s,3,Dial(Zap/1|20) ; Calls channel 1

Note: replace the absolute paths with paths appropriate to your system.

This example receives calls in the context "incoming," where MythTV's program mythtvosd will get invoked with the three parameters required by the cid.xml template. The second two lines are examples of how the dial plan can continue after the System call.

Remember that the asterisk server doesn't have to be on a myth box. My asterisk server is running on a PC without a Myth backend, but the multicast nature of MythTV OSD enables caller ID onscreen on all three frontends in my house.

For more information about MythTV and caller ID, please reference the README for mythtvosd included in the MythTV source tree found at:

Q: Can this be compiled on my Asterisk machine separately from the rest of MythTV?
A: Yes, the mythtvosd program does not rely on the other mythtv libraries or programs. You can download the mythtv source code, navigate to the directory "programs/mythtvosd" and then build the mythtvosd application. Somewhere on your network you'll also need mythudprelay running, which is found under "contrib/mythnotify/mythudprelay". This app also builds without the other myth applications.


this is how I made asterisk talk to mythtv on a different box
took me about 15 min to setup, with this howto hopefully will only take you 5 min
if you follow it exactly

on mythtv box...mkdir /etc/asterisk
adduser asterisk
pico /etc/asterisk/


# Read in the string from the connecting client
eval {
local $SIG{ALRM} = sub { die "alarm\n" }; # NB \n required
alarm 30;
$in = <STDIN>;
alarm 0;
if ($@) { die "timeout on input\n"; }
# Get rid of illegal characters in the string
$in =~ s/\r\n//g;

system("/usr/local/bin/mythtvosd --template=scroller --scroll_text='$name $number calling ... $name $number calling'");

chmod +x /etc/asterisk/
if you didn;t compile mythtv from sources then change /usr/local/bin/mythtvosd to /usr/bin/mythtvosd
you can find where it is by typing "which mythtvosd" or "whereis mythtvosd"

pico /etc/xinet.d/callerid
service callerid
disable = no
socket_type = stream
wait = no
user = asterisk
server = /etc/asterisk/
log_on_failure += USERID

add the following on mythtv box
pico /etc/services
callerid 65000/tcp #callerid daemon for asterisk, mythtvosd

restart xinetd
/etc/rc.d/init.d/xinetd restart
if not there "yum install xinetd" on fedora systems
emerge or apt-get for other linux systems
freebsd: cd /usr/ports; make search key=xinetd to dir, make install

great now in your asterisk dialplan somewhere add something like:
exten => s,6,system(echo "${CALLERIDNAME}%${CALLERIDNUM}"| nc 65000) ; tell mythtv we have a call

substitute with ip address of your mythtvbox

i strongly recommend your asterisk box being separate from your mythtv box, you don't need X etc
slowing down your phone system



This is using MythTV SVN as of 12th September 2005, but should apply to packaged releases.

On the Asterisk box, use Matt White's cid.agi script. In extensions.conf, just add an action to call cid.agi.

On the Myth box, build and install mythudprelay. It's in the contrib folder in the source. I compiled it and copied to /usr/bin/local, and copied the XML stylesheet to /etc/mythtv. Then run mythudprelay (you might need an init script to start it at boot time) and Caller ID should work!




The built in OSD in mythtv only display the cid if you are watching a recording or TV (not when you are in movies or wathing a media file). Here is the a quick way to make it appear all time (even when mythtv is not running !!). I used xosd which displays whatever text is sent to it as an overlay over existing x windows screen.

As a side note, contrary to popular belief, mythtv and asterisk can coexist on same computer without any issues. I have my fedora core 5 running asterisk 1.2.3 and mythtv .20 without any issues. It is an old 1.6Ghz machine with 512 MB ram. I have only 30% cpu usage while watching a recording and making two simultaneous calls.

Here are the steps to make callerid working
Install xosd and xosd-devel. In fedora you can do it like this

For fedora

yum install xosd xosd-devel

For ubuntu

apt-get install libxosd-dev libxosd2 xosd-bin

download and install xyac

gunzip xyac-0.1.tar.gz
tar -xvf xyac-0.1.tar
cd xyac-0.1
make install

make sure that xyac runs when mythtv user logs in. To do this i placed a file named in /home/mythtv/.kde/Autostart with following content
Small font

xyac -c yellow -f -adobe-utopia-bold-r-normal--*-400-*-*-*-*-* -s 5 -d 5 &

Or for big font

xyac -c yellow -f -adobe-helvetica-bold-r-normal-*-*-240-100-100-p-*-iso8859-1 -s 5 -d 5 &

Don't forget to make it executable

chmod 755

now on your asterisk machine (could be on same machine as mythtv too) create a agi file which will receive the caller id and send it to xyac for display. name it mythtvosd.php

#!/usr/bin/php -q

define("AGIBIN_DIR", "/var/lib/asterisk/agi-bin");
$stdin = fopen('php://stdin', 'r');
while (!feof($stdin)) {
$temp = fgets($stdin);
$temp = str_replace("\n","",$temp);
$s = explode(":",$temp);
$agi[$s[0]] = trim($s[1]);
if $temp == "") {

$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
if ($socket < 0) {
echo "socket_create() failed: reason: " . socket_strerror($socket) . "\n";

# replace with ip of machine which is running mythtv and xyac
$result = socket_connect($socket, '', '10629');

if ($result < 0) {
echo "socket_connect() failed.\nReason: ($result) " . socket_strerror($result) . "\n";

$in = "@CALL ". $agi["agi_calleridname"] . "~" . $agi["agi_callerid"] . "\0";
socket_write($socket, $in, strlen($in));

If you are running mythtv on a different machine than asterisk, then change the in above file to ip of machine running mythtv and xyac.

now only thing remaining is to tell asterisk to use this agi everytime a call comes in. To do this modify your incoming context


exten => s,1,AGI(mythtvosd.php);
exten => s,2,Wait(1)
exten => s,3,Dial(Zap/1|20) ; Calls channel 1

If you have multiple computers running mythtv, you can modify the php-agi script to write to each computer's ip address.

Another way of sending information to XYAC is directly from within Asterisk:

exten => s,1,System(/bin/echo -n -e "'@CALL${CALLERIDNAME} ~${CALLERIDNUM}'" | nc -w 1 10629)

Additional links------

FreePBX how-to

How to set this up on freePBX, may be useful in general:

Created by: bcorrion, Last modification: Thu 19 of Mar, 2009 (22:33 UTC) by hoolahoous

Please update this page with new information, just login and click on the "Edit" or "Discussion" tab. Get a free login here: Register Thanks! - Find us on Google+

Page Changes | Comments


Featured -