TR-064 Thing Action phonebookLookup not working

sometimes it is too easy. works perfect with me as well-. No rules needed for phonebook lookup beside that I rule the last caller into an item so that it is saved until the next call comes. Thanks Christian.

OK, this nearly works for me.

I define the item via UI, String item, phonebook profile, I can select the phonebook. Now there is one remaining problem: It resolves correctly the name, but tells in the log:

Exception while formatting value 'Philipp' of item FRITZBox_AusgehenderAnruf with format '%1$s to %2$s': Format specifier '%2$s'

I have not defined this format specifier, somehow it seems to have been predefined.

(If I define a Call item from the same channel, without phonebook profile, it correctly shows “phonenumber1 to phonenumber2”.)

I am using OH 3.0 Stable. Should I update to 3.1 Snapshot?

I updated the binding to 3.1.0, ( deleted the binding from OH3 and placed the snapshot 3.1.0 jar file to addons )

can you double check that your item is really a string? I struggled with that as well and I created a call item by mistake first.
i have added meta data to my string item, state description pattern %s . Not sure if this solves the issue

The meta data state description %s did the trick! Is working now, still with avmfritz 3.0.0.
Thank you!

I might have discovered a bug. I tried the following item definition

Call Fritz_Incoming_Call “Anrufende Nummer [$1$s an %2$s]” { channel=“avmfritz:fritzbox:192_168_178_1:incoming_call” [profile=“transform:PHONEBOOK”, phonebook=“dca2683d47:Google”, phoneNumberIndex=1]}

This gives following error:

Cannot initialize PHONEBOOK transformation profile: UID must have at least 3 segments… Profile will be inactive.

Setting the item definition to

Call Fritz_Incoming_Call “Anrufende Nummer [$1$s an %2$s]” { channel=“avmfritz:fritzbox:192_168_178_1:incoming_call” [profile=“transform:PHONEBOOK”, phonebook=“tr064:fritzbox:dca2683d47:Google”, phoneNumberIndex=1]}

Cannot initialize PHONEBOOK transformation profile: Cannot split ‘phonebook’ parameter. Profile will be inactive.

I think the problem is in PhonebookProfile.java. If I understood correctly it tries to parse the thing UID from the phonebook param. But it splits the param by : Since the thinguid itself contains : this won’t work.

Here’s how I finally got it to work: when looking at the “comprehensive example”, don’t get distracted by the <PHONEBOOK_NAME> voodoo.

When your name for the Thing (Bridge) is

tr064:fritzbox:1

then your PHONEBOOK profile in your item must be exactly the same name, just with the colons URL-encoded (3A), so it should say

[profile="transform:PHONEBOOK", phonebook="tr064_3Afritzbox_3A1"]

So, full example would be:

tr064.things

Bridge tr064:fritzbox:1 "FRITZ!Box 7590" [
    host="fritz.box", 
    user="USER",
    password="PASSWORD",
    phonebookInterval="86400"
    ]

avm.items

// Call Monitor Equipment

Group gCALLMONITOR "Call Monitor" ["Equipment"]

Call fritzIncomingCall "Incoming Call [from %2$s to %1$s]" (gCALLMONITOR) ["Status"] { channel="avmfritz:fritzbox:1:incoming_call" }

Call fritzActiveCall "Active Call [from %1$s]" (gCALLMONITOR) ["Status"] { channel="avmfritz:fritzbox:1:active_call" }

Call fritzOutgoingCall "Outgoing Call [from %2$s to %1$s]" (gCALLMONITOR) ["Status"] { channel="avmfritz:fritzbox:1:outgoing_call" }

String fritzCallRinging "Status [%s]" (gCALLMONITOR) ["Status"] { channel="avmfritz:fritzbox:1:call_state" }

// resolved numbers (only if TR-064 binding is installed)

String fritzIncomingCallCallee "Incoming Call - Callee [%s]" (gCALLMONITOR) ["Status"] { channel="avmfritz:fritzbox:1:incoming_call" [profile="transform:PHONEBOOK", phonebook="tr064_3Afritzbox_3A1"] }

String fritzIncomingCallCaller "Incoming Call - Caller [%s]" (gCALLMONITOR) ["Status"] { channel="avmfritz:fritzbox:1:incoming_call" [profile="transform:PHONEBOOK", phonebook="tr064_3Afritzbox_3A1", phoneNumberIndex=1, matchcount="8"] }

String fritzActiveCallCaller "Active Call - Caller [%s]" (gCALLMONITOR) ["Status"] { channel="avmfritz:fritzbox:1:active_call" [profile="transform:PHONEBOOK", phonebook="tr064_3Afritzbox_3A1"] }

String fritzOutgoingCallCallee "Outgoing Call - Callee [%s]" (gCALLMONITOR) ["Status"] { channel="avmfritz:fritzbox:1:outgoing_call" [profile="transform:PHONEBOOK", phonebook="tr064_3Afritzbox_3A1"] }

String fritzOutgoingCallCaller "Outgoing Call - Caller [%s]" (gCALLMONITOR) ["Status"] { channel="avmfritz:fritzbox:1:outgoing_call" [profile="transform:PHONEBOOK", phonebook="tr064_3Afritzbox_3A1", phoneNumberIndex=1, matchcount="8"] }

I appreciate the work put in this, but the existing documentation for caller number lookup is a complete guessing game.

And the README.md description in the binding is misleading. In the Bridge definition the term

tr064:fritzbox:rootuid 

is used, and in the Item definition the example provided is

phonebook="tr064_3Afritzbox_3AfritzboxTR064"

With rootuid and fritzboxTR064, this will not work.

2 Likes

Hi Alexander,

Thanks for finding this out as well as describing it so detailed. With having this change applied, I also don´t get any failure message anymore and the items are responding well. But it always shows me the telephone number, not a name.

Did you test it with the standard binding of openHAB 3.0 or a 3.1 snapshot?

And is it OK to have a space in the phonebook name or might this limit the binding to look into it? As I understood with the code you stated it should look in all ponebooks, or?

Hi Tobias,

here’s my log - getting the names from numbers.

Call initiation (outbound):

2021-01-26 20:52:38.290 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'fritzOutgoingCall' changed from UNDEF to 012345678,0987654321

2021-01-26 20:52:38.290 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'fritzOutgoingCallCaller' changed from UNDEF to Doe John

2021-01-26 20:52:38.290 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'fritzOutgoingCallCallee' changed from UNDEF to Miller Jane

2021-01-26 20:52:38.290 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'fritzCallRinging' changed from IDLE to DIALING

2021-01-26 20:52:49.796 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'fritzActiveCall' changed from UNDEF to 012345678,

2021-01-26 20:52:49.796 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'fritzActiveCallCaller' changed from UNDEF to Miller Jane

2021-01-26 20:52:49.796 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'fritzOutgoingCall' changed from 012345678,09876543211 to UNDEF

2021-01-26 20:52:49.796 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'fritzOutgoingCallCaller' changed from Doe John to UNDEF

2021-01-26 20:52:49.797 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'fritzOutgoingCallCallee' changed from Miller Jane to UNDEF

2021-01-26 20:52:49.797 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'fritzCallRinging' changed from DIALING to ACTIVE

and hanging up:

2021-01-26 21:05:52.563 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'fritzActiveCall' changed from 0621896949, to UNDEF
2021-01-26 21:05:52.563 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'fritzActiveCallCaller' changed from Miller Jane to UNDEF
2021-01-26 21:05:52.563 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'fritzCallRinging' changed from ACTIVE to IDLE

I’m on standard 3.0 binding:

openhab> bundle:list | grep TR-064
250 │ Active │  80 │ 3.0.0                   │ openHAB Add-ons :: Bundles :: TR-064 Binding

The example code in post #19 should to my best knowledge use all phonebooks available.

If you have a “space” character in your phonebook’s name, try substituting this (if you select it at all…) with _20, like in Google_20Telefonbuch. But you should not have to do this as the items (as shown above) can be used directly in rules, without translation.

Bonus: rules to push the identified caller name / numbers via pushover binding:

fritzbox.rules

rule "Incoming Call"
when
    Item fritzCallRinging changed to RINGING 
then
    // dissect the calling numbers with avmfritz binding

    val incCall = fritzIncomingCall.state as StringListType
    val ourNumber = incCall.getValue(0)
    val callerNumber = incCall.getValue(1)

    // do something with callerNumber
    val actions = getActions("pushover", "pushover:pushover-account:account")	
    var String msg = "Eingehender Anruf: " + fritzIncomingCallCaller.state + " (" + callerNumber + ") auf " + ourNumber
    logInfo("FRITZ!Box", msg)
	actions.sendMessage(msg, "openHAB")
end

rule "Outgoing Call"
when
    Item fritzCallRinging changed to DIALING 
then
    // dissect the calling numbers with avmfritz binding

    val outCall = fritzOutgoingCall.state as StringListType
 
    var String calledNumber = outCall.getValue(0)
    var String ourNumber = outCall.getValue(1)
 
    val actions = getActions("pushover", "pushover:pushover-account:account")	
    var String msg = "Ausgehender Anruf: " + fritzOutgoingCallCallee.state + " (" + calledNumber + ") über " + ourNumber
    logInfo("FRITZ!Box", msg)
	actions.sendMessage(msg, "openHAB")
end

rule "Connection established - outgoing"
when
    Item fritzCallRinging changed from DIALING to ACTIVE
then
    logInfo("FRITZ!Box", "Outgoing call: Connection established")
end

rule "Connection established - incoming"
when
    Item fritzCallRinging changed from RINGING to ACTIVE
then
    logInfo("FRITZ!Box", "Incoming call: Connection established")
end


rule "Connection dropped"
when
    Item CallStatfritzCallRinging changed from ACTIVE to IDLE
then
    logInfo("FRITZ!Box", "Active call: Connection dropped")
end

1 Like

Hi Alexander,

I tried several things, but still don´t get any name.

What I changed/resolved:

  • By reading in the phonebook, a warning was raised “Scheduled runnable ended with an exception: java.lang.IllegalStateException: Duplicate key …”
  • I removed the empty space in the name of the phonebook in the Fritz!Box
  • I changed “matchCount” into “matchcount” as I found this difference compared to your example. But actually with “machtcount” it didn´t show me the defined value in the UI, therefore I changed it back. Also in this regard, I added the quotes to the number, but thereby I did also not get it working
  • I activated the DEBUG logging for the TR-064 binding. It proves me the following info “Number ‘’ not found in phonebook ‘null’ from provider ‘tr064:fritzbox:1’”. Does this tell that it can´t refer to a phonebook?
  • When I set the binding to TRACE logging, I can see that it retrieves the list of calls with all the names

Still cannot get this to work.
TR-064-Bridge Thing UID is:

tr064:fritzbox:dca2683d47

Item/Transform definition is:

Call Fritz_Incoming_Call "Anrufende Nummer [$1$s an %2$s]" { channel="avmfritz:fritzbox:192_168_178_1:incoming_call" [profile="transform:PHONEBOOK", phonebook="tr064_3Afritzbox_3Adca2683d47", phoneNumberIndex=1]}

Log still says:

2021-01-27 15:52:45.635 [WARN ] [.internal.phonebook.PhonebookProfile] - Cannot initialize PHONEBOOK transformation profile: UID must have at least 3 segments.. Profile will be inactive.

What am I missing?

@maihacke
I would say you have to change the Item into a String first and use [%s] as “unit formatter” or however this should be called.

See the example:

Hmm, I’m not sure if this addresses the point. The Item definition itself is working (without the profile). The error log, is also related to the profile…

I did some more tests, now the error message is gone. I did not change the item definition, so it was probably some caching/restart issue.
The problem is, that the phonebook lookup is not working, there is no error, but also no named resolved.

Try this. Seems you’re mixing up Calls and Strings, and you have a $ instead of % in your format string.

The incoming call is a string list (so no PHONEBOOK transformation here):

Call Fritz_Incoming_Call "Eingehender Anruf [von %2$s an %1$s]" (gCALLMONITOR) { channel="avmfritz:fritzbox:192_168_178_1:incoming_call" }

The number you try to find a name for is a single string.

String Fritz_Incoming_Call_Caller "Eingehender Anruf - Anrufer [%s]" { channel="avmfritz:fritzbox:192_168_178_1:incoming_call" [profile="transform:PHONEBOOK", phonebook="tr064_3Afritzbox_3Adca2683d47", phoneNumberIndex=1, matchcount="8"] } 

No, sadly this doesn’t make a difference.
Items:

/* Fritzbox */
Call	Fritz_Incoming_Call		    "Anrufende Nummer [%s]"      { channel="avmfritz:fritzbox:192_168_178_1:incoming_call" }
String	Fritz_Incoming_Caller	    "Anrufer [%s]"               { channel="avmfritz:fritzbox:192_168_178_1:incoming_call" [profile="transform:PHONEBOOK", phonebook="tr064_3Afritzbox_3Adca2683d47", phoneNumberIndex=1, matchcount="8"]}

Rule

rule "Jemand ruft an"
when
    Item Fritz_Ringing changed to RINGING
then
    //Letze Nummer aktualisieren
    logInfo("Telefon", "Jemand ruft an.")

    val incCall = Fritz_Incoming_Call.state as StringListType
    var callerName = "unbekannt"
	var callerNumber = "-"
		
    logInfo("Telefon", incCall.toFullString())
    logInfo("Telefon", Fritz_Incoming_Caller.state.toFullString())
  ...

Log

2021-01-28 07:30:07.882 [INFO ] [rg.openhab.core.model.script.Telefon] - Jemand ruft an.
2021-01-28 07:30:07.897 [INFO ] [rg.openhab.core.model.script.Telefon] - 9868757,01604772820
2021-01-28 07:30:07.908 [INFO ] [rg.openhab.core.model.script.Telefon] - 9868757

As you can see Fritz_Incoming_Caller.state contains the number not the callers name.
How does the binding decide which phonebook to use on the fritzbox? Could it me that it uses the wrong phonebook?

I got it working!

Actually the problem on my side was reading in the phonebook.

@maihacke: You may should check if you have the same problem.

When restarting openHAB or actualizing the Thing, it reads in the phonebook. And when you have entries with the same number twice, it raises an error. I had to adapt two entries of the phonebook until the reading in worked properly. Unfortunately it seems to skip the complete phonebook in such a case and not just only the one entry.

1 Like

That is probably a problem for me also. My phonebook, contains several number more than once. I like to have different contacts with the same number in my phonebook, e.g. persons with different mobile phones living in the same household and therefore the same landline number. I think this is more a bug in the binding, which should be fixed…

Hello to all,
my English is really bad. Sorry for that.
But luckily there is deepl.com

I got it working!
Here is a little tutorial for all of you who use OH3:

You have to install these two bindings: AVM FRITZ!Box Binding & TR-064 Binding

AVM.items

Group gAnrufmonitor “Anrufmonitor” [“Equipment”]
Call FritzEingehenderAnruf “Eingehender Anruf [von %2$s to %1$s]” (gAnrufmonitor) [“Status”] {channel=“avmfritz:fritzbox:192_168_178_1:incoming_call”}
Call FritzAktiverAnruf “Aktiver Anruf [von %1$s]” (gAnrufmonitor) [“Status”] {channel=“avmfritz:fritzbox:192_168_178_1:active_call” }
Call FritzAusgehenderAnruf “Ausgehender Anruf [von %2$s to %1$s]” (gAnrufmonitor) [“Status”] {channel=“avmfritz:fritzbox:192_168_178_1:outgoing_call”}
String FritzAnrufzustand “Anrufzustand [%s]” (gAnrufmonitor) [“Status”] {channel=“avmfritz:fritzbox:192_168_178_1:call_state”}
String FritzEingehenderAngerufener “Eingehender Anruf - Angerufener [%s]” (gAnrufmonitor) [“Status”] {channel=“avmfritz:fritzbox:192_168_178_1:incoming_call” [profile=“transform:PHONEBOOK”, phonebook=“tr064_3Afritzbox_3Ad1e06eda99”]}
String FritzEingehenderAnrufer “Eingehender Anruf - Anrufer [%s]” (gAnrufmonitor) [“Status”] {channel=“avmfritz:fritzbox:192_168_178_1:incoming_call” [profile=“transform:PHONEBOOK”, phonebook=“tr064_3Afritzbox_3Ad1e06eda99”, phoneNumberIndex=1, matchcount=“8”]}
String FritzAktiverAnrufer “Aktiver Anruf - Anrufer [%s]” (gAnrufmonitor) [“Status”] {channel=“avmfritz:fritzbox:192_168_178_1:active_call” [profile=“transform:PHONEBOOK”, phonebook=“tr064_3Afritzbox_3Ad1e06eda99”]}
String FritzAusgehenderAngerufener “Ausgehender Anruf - Angerufener [%s]” (gAnrufmonitor) [“Status”] {channel=“avmfritz:fritzbox:192_168_178_1:outgoing_call” [profile=“transform:PHONEBOOK”, phonebook=“tr064_3Afritzbox_3Ad1e06eda99”]}
String FritzAusgehenderAnrufer “Ausgehender Anruf - Anrufer [%s]” (gAnrufmonitor) [“Status”] {channel=“avmfritz:fritzbox:192_168_178_1:outgoing_call” [profile=“transform:PHONEBOOK”, phonebook=“tr064_3Afritzbox_3Ad1e06eda99”, phoneNumberIndex=1, matchcount=“8”]}

IMPORTANT: To be able to read the phonebook, the identifier of the profile (phonebook=“tr064_3Afritzbox_3Ad1e06eda99”) must be adjusted to your ID!

AVM.rules

rule “Eingehender Anruf”
when
Item FritzAnrufzustand changed to RINGING
then
val incCall = FritzEingehenderAnruf.state as StringListType
val ourNumber = incCall.getValue(0)
val callerNumber = incCall.getValue(1)
var String msg = “Eingehender Anruf: " + FritzEingehenderAnrufer.state + " (” + callerNumber + ") auf " + ourNumber
var String msg2 = "Eingehender Anruf von: " + FritzEingehenderAnrufer.state
logInfo(“FRITZ!Box”, msg)
Alexa_Bad_EG_Ankuendigung.sendCommand(msg2)
end

The Rule stores in the LOG who is calling your number and with which number.

In addition, the Alexa outputs the following: Incoming call from CALLER

I hope I can help someone with this!

Best regards
DJFlaxi

1 Like

Hey @maihacke,
As I have been informed, the issue we experienced has already been solved in the further development of the binding. So please try to update the binding to the latest snapshot (the command for it you find further up in a post from 8 of January 2021).