How to make OpenHab make a phone call?

Hi all,

I’ve searched but couldn’t find anything specific or tutorials on how to achieve that, that usually means I’m going in the wrong direction. Specially in openhab where I’m such a noob.

My idea was to make phone calls everytime my movement sensor triggers when my family (mobiles) are not on the network, I made it to work with Telegram IM but how many times we dismiss notifications on mobile, or even sometimes not connected due to roaming etc.

It seems Plivo/Twilio free trial allows to make some limited amount of calls: https://support.plivo.com/support/solutions/articles/17000011977-what-is-a-free-trial-account-
https://support.twilio.com/hc/en-us/articles/223136107-How-does-Twilio-s-Free-Trial-work-

I wouldn’t even need to pick-up the call, but this would “alarm” me better than Telegram IMs.

And I saw someone in another post that REST API for PLIVO is simple, so, has anyone ever tested this? Or is there any binding for Plivo/Twilio? I’m looking at the HTTP binding but I’m a bit noob, if you have any pointers I would appreciate.

Here is how to make a call in Plivo:

Tks alot!

  • Platform information:
    • Hardware: CPUArchitecture/RAM/storage
    • OS: what OS is used and which version
    • Java Runtime Environment: which java platform is used and what version
    • openHAB version:
  • Issue of the topic: please be detailed explaining your issue
  • Please post configurations (if applicable):
    • Items configuration related to the issue
    • Sitemap configuration related to the issue
    • Rules code related to the issue
    • Services configuration related to the issue
  • If logs where generated please post these here using code fences:

There are some threads here, e.g.

Do you use VoIP? Any additional hardware/software (I’m using asterisk here, so I have the option to use the solution in this thread)

Hi, tks! No I don’t have any hw/sw for VOIP, my idea was trying to have as less moving parts as possible, I’ve read about asterisk etc but was wondering if I could do it without…

Sure, but then you will need hardware. Where is your phone plugged in?

I recommend to use CallMeBot API to make Telegram Phone Calls (ringing your phone and reading the message that you want with TTS).

It is free and easy to use. No Account/Registration/Bot is required. Only using the CallMeBot API.

Have a look here:
https://community.openhab.org/t/openhab-can-make-telegram-phone-calls-now-with-tts-voice/

I use it for urgent notifications and it is working very well.

Just to give someone searching for this another idea this is how i did this on ubuntu.
I’m using Linphone to do all the calling stuff.

  1. Login using SSH to your ubuntu machine and install linphone-nogtk package using apt-get
sudo apt-get install linphone-nogtk
  1. test linphone using linphonecsh
    linphonecsh is a console program to control linphonec (this is a console app for linphone also installed with linphone-nogtk).
    Best use openhab user for this.
sudo -u openhab /bin/bash

Test calls:

// creates a new instance of linphone. Only one instance allowed
linphonecsh init 

//Register your linphoneclient at your SIP Server
linphonecsh register --host [SIPHostAdddress] --username [SIP Username] -- password [SIP Password] 

//Check Status of registration
linphonecsh status register
-> should return something like: registered to identitiy

//call a number
linphonecsh dial 123456789 

//exit linphonecsh
linphonecsh exit

I had an issue where status register always returned “-1”. This was caused by an issue where linphonec couldn’t create it’s databasefile. Took me some hours to find the root cause. You will get an warning when starting linphonec.
To fix this I had to create the folder where the databasefile is safed. I don’t know the location any more.

Now time for my JS Rule Script using ECMAScript262 (JS Scripting rule)

var Duration = Java.type("java.time.Duration");

var callingtimeouttimer;

//cechk if timer exists
if (cache.private.exists("callingtimeouttimer"))
{
  callingtimeouttimer = cache.private.get("callingtimeouttimer");
}

//cancel timer and stop linphonecsh
if (callingtimeouttimer!= null)
{
  callingtimeouttimer.cancel();
  callingtimeouttimer = null;
}

//stop linphone for now to get shure it is sopped
actions.Exec.executeCommandLine("linphonecsh", "exit");
java.lang.Thread.sleep(500);
//start a new instance
actions.Exec.executeCommandLine("linphonecsh", "init");
java.lang.Thread.sleep(500);
//register at Phoneline
var re = actions.Exec.executeCommandLine(Duration.ofSeconds(1),"linphonecsh", "register", "--host", "192.168.1.xx", "--username", "SIPUSER", "--password", "SIPPASSWORD");
java.lang.Thread.sleep(1000);
//get registerstatus
var resp = actions.Exec.executeCommandLine(Duration.ofSeconds(1), "linphonecsh", "status", "register");
//setup linphone to play soundfiles
actions.Exec.executeCommandLine(Duration.ofSeconds(1),"linphonecsh", "generic", "soundcard use files");
java.lang.Thread.sleep(100);
//startplayback
actions.Exec.executeCommandLine(Duration.ofSeconds(1),"linphonecsh", "generic", "play /etc/openhab/sounds/AlarmSound.wav");

//check if registering was possible. Log error if not and cancel
if (!resp.includes("identity"))
{
  console.error("Error registering at SIP Client:" + resp);
  actions.Exec.executeCommandLine("linphonecsh", "exit");
 
}
else
{
  //call a number
  actions.Exec.executeCommandLine("linphonecsh", "dial", "123456789");
  //setup timeout to and calling after x time
  callingtimeouttimer = actions.ScriptExecution.createTimer("callingtimeout", time.ZonedDateTime.now().plusSeconds(30),endCall);
  cache.private.put("callingtimeouttimer", callingtimeouttimer);
  
}


//end call timer callback
function endCall(){
  actions.Exec.executeCommandLine("linphonecsh", "exit");
  if (cache.private.exists("callingtimeouttimer"))
  {
    var callingtimeouttimer = cache.private.get("callingtimeouttimer");
    callingtimeouttimer.cancel();
    cache.private.remove("callingtimeouttimer");
  }
}

What this script does is calling a number for max of 30 seconds an playing an wave file located in “Sounds” folder under OHConfig files location.

linphonecsh generic “xyz” runs command “xyz” on linphonec.
For more information on this run linphonec and enter help. you could also enter help advanced for some more help informations.

Hope this helps someone in the future as it took me some days to get this up running. Linphone has pretty much functions and i think you could do nearly everything using this.

1 Like