Caller ID Component No Number?

Curious if anyone else is using the Caller ID Sensor (https://www.home-assistant.io/components/sensor.modem_callerid/) and having issues with no NUMBER being updated in HA / Hassio.

I used my own VBS script for Caller ID and spam caller filtering in the past on my old home brew home automation system but want to get out of that world. The Caller ID sensor DOES answer and provides the name the bluetooth to home phone adapter provides but no number information. I’ve used the same modem in my VBS code so I know the modem passes the number under the standard AT+VCID=1 setup as that is what I used.

Just curious if others may have similar issues before I dig deeper or re-write my old solution in Python or PHP on my web services server.

Thanks
Stephen

Appears to be an unused component - I ended up with a simple Python script on my web server Pi that listens to the modem, parses and pushes the number to a PHP script for TTS, email, spam check and logging back to Hassio. Works good enough for me…

Hi, is that script something you could share as I am looking to do the exact same thing?

The Python is very very simple based on some examples I found. I am sure others can do much better.
This just hands the number off to my PHP web server that I use for other purposes that then does some lookups and pushes TTS back to Hassio via the API. I’m sure someone could do all that in this script and hit HASSIO directly, I’m just doing it how I could make it work.

#readcid.py - monitor USB Modem for inbound calls call URL to speak and save
#  Most of the work is done on the PHP side for look ups, notifications, etc
# v1.01 - 09/08/2018 - Added .1 sleep time to keep from looping up CPU - still has ok call response

# setup requirement
import serial
import requests
import urllib2
import time

# open up the modem for reading
ser = serial.Serial(
    port='/dev/ttyACM0',\
    baudrate=9600,\
    parity=serial.PARITY_NONE,\
    stopbits=serial.STOPBITS_ONE,\
    bytesize=serial.EIGHTBITS,\
        timeout=0)

# set it up and start
print("connected to: " + ser.portstr)
line = []
ser.write("AT+VCID=1\r\n")

# loop forever to read calls
while True:
    time.sleep(.1)	#give up some CPU with sleep, check every .x
	# read in each byte and build out a line
    for c in ser.read():
        line.append(c)
        # if we have an eol then process the line
        if c == '\n':
            myLine = ''.join(line)
            myLine = myLine.replace("\n", "")
            print myLine
            # once we get a number then process the call off to the PHP code
            if myLine.find("NMBR") != -1:
              myNMBR = myLine.replace("NMBR = ", "")
              print "Inbound : " + myNMBR
              response = urllib2.urlopen('http://<local web server - not hassio>/callerid.php?n=' + myNMBR)
              html = response.read()
              print html
            line = []
            break

ser.close()

This is example .PHP that takes that PY URL call and pushes it to Hassio. Understand that I actually take that number, lookup a local MySQL database for previous calls, spam tags, and/or a name to use before this part gets called but this is the core speaking part. You will need to update the API password if used as well. The PHP also sends an email-to-text of the number/name.

<?php
		//** Example PHP to get caller number and push to Hassio

		$myCallerNumber = filter_input(INPUT_GET, "n");
		$myMediaPlayer = "media_player.hallway_speaker";
		$strJSON = "{" . CHR(34) . "message" . CHR(34) . ":" . CHR(34) . $myCallerNumber . CHR(34) . "," . CHR(34) . "entity_id" . CHR(34) . ":" . CHR(34) . $myMediaPlayer . CHR(34) . "}";
		$context = stream_context_create(
		array(
		    'http' => array(
	        'method' => 'POST',
	        'header' => "x-ha-access: <your password>\r\n" .
	                    "content-type: application/json\r\n",
						'content' => $strJSON
			)));
		$data = file_get_contents("http://hassio.local:8123/api/services/tts/google_say", false, $context);
		echo $data;
		
?>

Thank you, Ill give the first script a try. I’m not sure my modem is working properly, but I’ll find out soon.

Thanks for sharing!

1 Like