Caller ID in HA workflow
-
Has anyone successfully incorporated incoming call(er) information** within an automation workflow?
I'm talking about having Alexa speak out the name and/or phone number of a caller, or activating a routine/scene based on that info.
Always been a dream of mine. Wouldn't know how to achieve it! Do they make an Ethernet/WiFi-connected CallerID box?
**from a LANDLINE, not a MOBILE PHONE (although in the case of my Google Voice #, both lines ring, and if my smartphone is home and turned on, I could see invoking Tasker somehow)
REFERENCES:
[Please file under proper category, as you see fit]
-
As a proof of concept, I rustled up the following workflow, and it works fantastically!
ON VERA:
Created a virtual sensor (dev #365) of type "Generic" using the Virtual Sensor plug-in by @toggledbitsON SMARTPHONE:
Created new Tasker Profile that activates when Phone is Ringing > Runs task: HTTP Request (GET) > payload =http://<my_vera_ip>:3480/data_request?id=variableset&DeviceNum=365&serviceId=urn:toggledbits-com:serviceId:VirtualSensor1:SetValue&Variable=newValue&Value=%CNUM
where the built-in Tasker variable
%CNUM
automatically substitutes the caller's 11-digit phone number.Works a charm! Now, I can have MSR simply monitor the 'New Value' variable on the VS and react accordingly.
-
I have something similar to get the status of my home office PC when in a VOIP call. It will trigger a virtual switch that's driving a BusyLight oustide my office, sending a notification to my TVs and running a couple of scenes based on the time, to turn on a couple of lights automatically when I'm in a videocall.
-
For funsies, I took things a step further using Pushover (recommended by the creator of MSR). After setting up a Desktop notification endpoint in Pushover, I simply instruct MSR to send a push notification to my browser whenever a phone call comes in.
The process starts, as mentioned above, in Tasker. I modified the
value=
component of the GET URL so that it sends more than just the phone number; now, it passes%CNAME
,%CNUM
,'Libra cell'
as a comma-separated list of three items: the caller's name, number and the name I assign to my mobile device.In my
Caller ID Log
rule in MSR, that information (as explained above) gets routed through a virtual sensor on Vera, then pulled into an Expression with:callerNum := getEntity( "vera>device_365" ).attributes.x_vera_svc_toggledbits_com_VirtualSensor1_SetValue.newValue
and turned into a 5-element array using:
callerArr := split( "IN," + timeStamp + "," + trim(callerNum), "," ) // yields [ "IN", <call_time>, <caller_name>, <caller_number>, <device_label> ] // NOTE: timeStamp is a Global Expression that I defined separately in MSR
from which MSR can easily pluck the pieces needed to compose a Pushover notification.
-
For anyone into formatting phone numbers using MSR's built-in Regex engine, here's one possible Expression to try. It takes an 11-digit U.S. phone number string, extracts the digits using capture groups, and formats them with dashes, all in one go:
phNum := a="+12345678901", b=substr(replace(a,"(\\d{1})(\\d{3})(\\d{3})(\\d{4})","$2-$3-$4"),-12,12), b
// yields (string) "234-567-8901"
-
Slight tangent, but I’ve been using sipgate voip service ( https://www.sipgate.co.uk/ ) for years, and I’ve never really explored its API..
There seems to be a wealth of capabilities in there.. - https://api.sipgate.com/v2/doc
If it’s of interest to you or any others, my initial attempt to authenticate / use it is below..
#!/usr/bin/lua print("start of whole code") local https = require "ssl.https" local mime = require "mime" local json = require "dkjson" --local http = require "socket.http" local data = "" local username = "sipname" local password = "sippass" local function collect(chunk) if chunk ~= nil then data = data .. chunk end return true end local ok, statusCode, headers, statusText = https.request { method = "GET", url = "https://api.sipgate.com/v2/history", headers = { ["Accept"] = "application/json", ["Authorization"] = "Basic " .. (mime.b64(username ..":" .. password)), }, sink = collect } print("data = ", data) local sip = json.decode(data) print("---------") for k, v in pairs(sip) do print(k, "\t", v) end print("---------") for n, a in pairs(sip.items) do print(n, "\t", a) end print("---------") for p, k in pairs(sip.items) do --print(n, "\t", a) print("---------") for d, e in pairs(sip.items[p]) do print(d, "\t", e) end end print("---------")
-
So many of the Callback / VOIP / SIP / SMS / etc. services also provide code templates to use against their API, which is awesome. But you bring up an interesting point, @parkerc ... I've never seen "Lua" among the languages they offer, lol!
Nice to see you rolling your own. And if it works, perhaps send the company a copy for them to add to their library?
-
@librasun said in Caller ID in HA workflow:
. But you bring up an interesting point, @parkerc ... I've never seen "Lua" among the languages they offer, lol!
Exactly !, I noticed that too, no one seems to promote Lua
@librasun said in Caller ID in HA workflow:
Nice to see you rolling your own. And if it works, perhaps send the company a copy for them to add to their library?
It took me a while to just get that working, I don’t think those types of companies will want to use my pieced together bits of code
7/8