Notice: This forum has been recovered from an old backup, so some content, links, and dates may be outdated. The forum is currently read-only while we restore sign-in and registration functionality. Details

If you find this forum valuable and would like to help keep it online, donations to help cover hosting and domain costs are greatly appreciated, but never expected. You can support the forum through Buy Me a Coffee or Ko-fi. Thank you for helping preserve the EventGhost community.

Caller ID

If you have a question or need help, this is the place to be.
Post Reply
Lilak
Posts: 36
Joined: Fri Dec 28, 2012 9:06 am
Location: Sweden

Caller ID

Post by Lilak »

Hi!

Can someone please help me out.

When I get a call to my phone, I get: TCP.PhoneState.RINGING ['192.168.0.162', u'0000000000'] in EG. The zeros are the phone number.

I know about the OSD-plugin, no problem there.

But how do I get the phone number to show up on the OSD?

Thanks

Jonas
User avatar
kgschlosser
Site Admin
Posts: 5190
Joined: Fri Jun 05, 2015 5:43 am
Location: Rocky Mountains, Colorado USA

Re: Caller ID

Post by kgschlosser »

very simple...

in the field in the osd plugin. enter the information in the code block below. what is happening here is every time an event is fired. there is data sent along with the event. this is called a payload. the sata can come in many forms.. but with yours it's a list I know this because of the use of the []'s and lists are like a grocery list. but are numbered starting from 0

so the first item being your IP address is in spot 0. and the number is in spot 1

now upon closer inspection of the items in the list.
['192.168.0.162', u'0000000000']

i can see that the item i am wanting to deal with has single quotes around it
so the item is a string. and compatible to be sent to the OSD plugin without any conversion.. but in the example below I have included the conversion anyways so you can see.. so i wrapped the payload item specifying list item [1] with str() which would turn it into a string

Code: Select all

{str(eg.event.payload[1])}
but if you want to format the phone number out to have the dots then it would have to be done from code.. like so and this code can be copied and pasted into a python script action and that action placed right before the osd action... this reformatts the phone number to have the dots

with strings we can slice them or cut chunks off
so if a positive number is after the colon it will return the # of characters starting from the left
so if you had 1234567890 it would make this 123
if you put a negative number after the colon. it will remove that number from the right of the string
so if you did -3 after the colon you would get 1234567.. so now knowing that if you put a -7 after the colon what would you get back??
123 same as putting a 3 there

now if you move the 3 to before the colon it will cut that number off the front and you would end up with 4567890
and if you put the -3 before the colon you will get back 890

so we want the first 3. the middle 3 and the last 4

so [:3] is the first 3
and [-4:] is the last 4
so if we combine the 2 but swapping spots it will cut the first 3 off the string. and the last 4 off as well... returning the middle 3 [3:-4]

Code: Select all

phone = eg.event.payload[1]
eg.event.payload[1]= '%s.%s.%s' % (phone[:3], phone[3:-4], phone[-4:])
If you like the work I have been doing then feel free to Image
User avatar
kgschlosser
Site Admin
Posts: 5190
Joined: Fri Jun 05, 2015 5:43 am
Location: Rocky Mountains, Colorado USA

Re: Caller ID

Post by kgschlosser »

sorry about providing so much information.. I am a big fan of sharing the knowledge.
If you like the work I have been doing then feel free to Image
User avatar
kgschlosser
Site Admin
Posts: 5190
Joined: Fri Jun 05, 2015 5:43 am
Location: Rocky Mountains, Colorado USA

Re: Caller ID

Post by kgschlosser »

But what really gets cool is if you go into your phone settings and turn off DHCP for your wifi connection and manually enter the numbers... the item in the list is an identifier of who's phone it is.. so if you have multiple phones.. you would now be able to have them all work with the OSD with a way to know which one is which... and you can do that with the incoming phone number as well. so it would give a nice friendly name for who is calling if that number is added into a lookup table of sorts.
If you like the work I have been doing then feel free to Image
Lilak
Posts: 36
Joined: Fri Dec 28, 2012 9:06 am
Location: Sweden

Re: Caller ID

Post by Lilak »

Thank you, it works perfectly!

I like that you provide so much extra info. I now understand a little bit about how it works, but in coding I'm a total idiot.

Networking on the other hand, I know a little bit more about. I haven't use DHCP for years.

Thank you again!

Best regards

Jonas
User avatar
kgschlosser
Site Admin
Posts: 5190
Joined: Fri Jun 05, 2015 5:43 am
Location: Rocky Mountains, Colorado USA

Re: Caller ID

Post by kgschlosser »

well if you don't use DHCP. then you can do something like this... which you may like this
put the code block below into a python script fill in the necessary bits and place it before the OSD action

in this example we are using what is called a dictionary for the phone names and the phone book
it consists of keys and values. much like a normal dictionary

so we use the ip address of the phone as a key. and the value would be the name of the phone.. so by putting the key into the []'s it will give us back that nice friendly name
now you can put a dict under a key and we did this in the phonebook. in this case you would have to provide the first key in the first set of []'s which would be the friendly name and in the second we put the number we are looking for.

the if statements are there for checking to make sure there is a key by that name before we try and request the value for it.. if we don't you will get an ugly red error.

Code: Select all

# this is where you would put friendly names to your ip addresses
# to identify the phone

ipAddresses = {
    '192.168.0.162': 'Jonas Phone',
    '192.168.0.163': 'Another Phone'
}

# and here is where you put the contacts for each phone

phoneBook = {
     'Jonas Phone': {
        '0000000000': 'Mom',
        '1111111111': 'Another Person'
    },
     'Another Phone': {
        '0000000000': 'Another Contact'
    }
}

ip, phone = eg.event.payload

if ip in ipAddresses:
    ip = ipAddresses[ip]

    if phone in phoneBook[ip]:
        phone = phoneBook[ip][phone]

eg.event.payload = [ip, phone]

and in the field where you enter the text in the action configuration. you will want to put this

{'Incoming call on ' + '\n'.join(eg.event.payload) + 'is Calling'}

now what this does is it will join a list of strings which is what you payload data is.. the \n is a newline character.. like pressing enter to type on the next line. so your OSD would look like this


Incoming call on Jonahs Phone
Mom is Calling
If you like the work I have been doing then feel free to Image
Lilak
Posts: 36
Joined: Fri Dec 28, 2012 9:06 am
Location: Sweden

Re: Caller ID

Post by Lilak »

Hi!

At this time there's only one phone at my home, so I modified your script a little bit.

Code: Select all

ipAddresses = {
    '192.168.0.162': 'Jonas Phone'
}

phoneBook = {
     'Jonas Phone': {
        '0123456789': 'NAME NAME HOME'
    }
}

ip, phone = eg.event.payload

if ip in ipAddresses:
    ip = ipAddresses[ip]

    if phone in phoneBook[ip]:
        phone = phoneBook[ip][phone]

eg.event.payload = phone
Coding is a dangerous thing, I have noticed. Didn't get any sleep last night because I tried to do things on my own, but I couldn't get it to work out. Here's what I tried to do:

In "phoneBook" I have "NAME NAME HOME". I would like to have that presented on two lines in OSD. NAME NAME on the first line and HOME on the second line.

Could you please help me out?

If you don't want any more questions from me, please tell me.

Best regards

Jonas
User avatar
kgschlosser
Site Admin
Posts: 5190
Joined: Fri Jun 05, 2015 5:43 am
Location: Rocky Mountains, Colorado USA

Re: Caller ID

Post by kgschlosser »

This is gonna irk ya a little. Especially since ya spent a good chunk of time trying to do something and it was right there. I have been there many times. Don't beat yourself up about it either..

Read the thread.. I told ya what the new line character is...

LOL

I don't want to just tell ya. but it's in my last post
If you like the work I have been doing then feel free to Image
User avatar
kgschlosser
Site Admin
Posts: 5190
Joined: Fri Jun 05, 2015 5:43 am
Location: Rocky Mountains, Colorado USA

Re: Caller ID

Post by kgschlosser »

Lilak wrote:At this time there's only one phone at my home, so I modified your script a little bit
It's fine to alter it.. It was showing you how to set it up if there was more then one phone.. But you do have the script correct at first glance.
Lilak wrote:If you don't want any more questions from me, please tell me.
No way in hell I would eve dot hat to someone... I have no problems with your asking questions.. I know how frustrating it can be... I didn't have anyone to ask. I learned the really really really hard way.. by constantly trying things over and over and over again.. sometimes it would take me weeks to get something to work right... So I am here to help anyone and everyone. My answer may not be the best way. and it may not even be correct on things.. But it usually can point someone in the right direction. And the last thing I ever want someone to do is give up.. So ask any questions you want. if I know the answer I will provide one.. and even if i don't know.. I might be able to provide that tidbit of information that manages to get you past where you are stuck.

I will tell you this. I started programming a year and a half ago.. never programmed a thing besides my alarm clock. and I wish I had found programming way before the age that I am. because of how much i enjoy doing it..

If you are still stuck after reading my last post. drop another line.. and I will tell ya.. But the answer is in that post.

K
If you like the work I have been doing then feel free to Image
Lilak
Posts: 36
Joined: Fri Dec 28, 2012 9:06 am
Location: Sweden

Re: Caller ID

Post by Lilak »

I don't know if it's the right way, but I did get it to work out.

Script:

Code: Select all

ipAddresses = {
    '192.168.0.162': 'Jonas Phone'
}

phoneBook = {
     'Jonas Phone': {
        '0123456789': 'NAME NAME' '\n' 'HOME'
    }
}

ip, phone = eg.event.payload

if ip in ipAddresses:
    ip = ipAddresses[ip]

    if phone in phoneBook[ip]:
        phone = phoneBook[ip][phone]

eg.event.payload = phone
OSD:

Code: Select all

{str(eg.event.payload)}
I remembered that, \n, made a new line, but I just tried to write it in the code for the OSD.

Now to the next question. In your first reply you explained how to format the phone number. Can I combine that with what I got now. So, when a number that's not in the phone book shows, I get it formated?

Best regards

Jonas
User avatar
kgschlosser
Site Admin
Posts: 5190
Joined: Fri Jun 05, 2015 5:43 am
Location: Rocky Mountains, Colorado USA

Re: Caller ID

Post by kgschlosser »

just shove it into the middle of the string.

no extra quotes or anything.. because it is apart of the string..

it would be encompassed by the first quote and the last. but that will bring me to another point... anytime you want to join 2 strings.. you are ...... adding them together

so use a + between them..

'NAME NAME' + '\n' + 'HOME'

but that is really not the proper way

'NAME NAME\nHOME'

that is the proper way

a new line character is just like any other character in a string.. it's just then when you program you can see it because it is "escaped" that's what the \ symbolizes...

so if you did '\r'

that is for carriage return, it was in the past for a line to end in \r\n usually only windows tho. this was really never used on any other platform. only \n was. so the \n has now become more prevalent.

or even with the use of Hexadecimal you need to escape it..

Code: Select all

\x45\x76\x65\x6e\x74\x47\x68\x6f\x73\x74\x20\x52\x6f\x63\x6b\x73\x21
Put the example above into the OSD plugin

Code: Select all

{'\x45\x76\x65\x6e\x74\x47\x68\x6f\x73\x74\x20\x52\x6f\x63\x6b\x73\x21'}
and then put this in.. what the {}'s (curly braces) do is to tell the OSD plugin to evaluate what is between them. you can put in a global variable name. like eg.event.payload or you can also put in code if you wanted to.

Code: Select all

 {'\n'.join(list( str(i) for i in range(5)))}
can you tell me what kind of an OSD would show up with the above?
If you like the work I have been doing then feel free to Image
Lilak
Posts: 36
Joined: Fri Dec 28, 2012 9:06 am
Location: Sweden

Re: Caller ID

Post by Lilak »

I have no idea what that code do. Not before I tried it out, that is.
User avatar
kgschlosser
Site Admin
Posts: 5190
Joined: Fri Jun 05, 2015 5:43 am
Location: Rocky Mountains, Colorado USA

Re: Caller ID

Post by kgschlosser »

in that last example... I will break it down for ya...



so essentially what you ended up with is
'0\n1\n2\n3\n4'
so looping code is using "for" or "while". so for does what is called an iteration. as long as information keeps on coming it keeps on looping

range(5) is where the information comes from. and "i" is the container we put that information in.

so if i did this it would be the same thing

Code: Select all

osdtext = ''
for i in range 5:
    osdtext = osdtext + str(i) + '\n
that produces the same thing as

Code: Select all

osdtext = '\n'.join(list(str(i) for i in range 5))
If you like the work I have been doing then feel free to Image
Post Reply