TR-064, FritzBox, phonebookLookup action and multiple phonebook entries?

Hi *,

I am trying to figure out the details of the phonebookLookup action for the Fritzbox. Since I am only interrested in a list of missed calls in the last 3 days, I have defined a linked item to the channel “CallList_3” of the FritzBox “thing”.
The item gets filled up with the json structure of the calllist, which then is further processed in a rule to fetch just “type 2” (missed…) calls (using JSONPATH in a rule), which works pretty well. Furthermore this rule is using the phonebookLookup action to translate (incoming) call numbers to phonebook entries. This also works as expected, using the current snapshot-version of the tr064-binding.
If there is some interrest, I will add code and description to this topic…

Now the question: an entry in the phonebook of the Fritzbox often has several numbers attached to the name, i.e. on number for private, one for office and one for mobile phones. But the phonebookLookup action just returns the name of the entry and NOT (additionally) the type of the number. This worked in the old bindings of Openhab 1 and 2.
Has anybody a solution? How can I fetch not only the name but also the type of the number from the phonebook? Any hints are welcome…

thanks and have fun!

Not possible with the current code.

I’m about to implement the Fritz-phonebook and the according thread is somewhat long and confusing to an OH-beginner like me :wink:
So I’d be very interested in your code and description :slight_smile:

How long does it take to retrieve the phonebook?

The phonebook is retrived automatically every xxx seconds, see the desciption of the TR-064 binding wiht the extention for the Fritzbox…

I know that. I wrote that code. I was talking about the time it takes to get the phonebook.

Ok, you have asked for, here comes the rule and the details of my implementation:

  • I am looking only for the missed calls in the last few days, 3 in my case.
  • I am restricting the missed calls to at most 4 calls, so I have defined 4 string items for the results.
  • The “thing” for the Fritzbox (tr064-binding) has to be configured and a string item for the “Call List Days” (advanced thing configuration) has to be linked.
  • Phonebook retrieval has to be enabled at thing level. I am using an update interval of 1200 seconds…
  • The actual processing is done by a rule (still in DSL) which is triggered, when the thing item for the CallList has changed.
rule "Process CallList"
	when Item Fritzbox_CallList changed
	then {
		var Integer i =0			// Loop counter, starts with 0
		var Integer j =0			// Counter für missed calls
		var Boolean entry			// false, is either the CallList is empty or the max. count of missed calls is reached
		var String calltype			// calling type, 2 is "missed call"
		var String telnr			// number of the caller
		var String caller			// caller name from the phonebook
		var String datum			// date and time of the call
		val fboxactions = getActions("tr064","tr064:fritzbox:mybox")	// actions for the phonebook, does NOT work in OpenHAB version 3.0.1, install a newer version of the tr064 binding!!!

		logInfo ("RULE", "========== Fritzbox CallList ==========")
		FritzBox_MC1.postUpdate("")  // clear the result strings
		FritzBox_MC2.postUpdate("")
		FritzBox_MC3.postUpdate("")
		FritzBox_MC4.postUpdate("")
		do {
			// $.[0] JSONPATH parse a single entry of the list: from 0 until...
			// remember: JSONPATH returns the complete json-struct, is the path can not be resolved!
			// If the first char of the path start with "[", we have reached the end of the struct
			calltype =transform("JSONPATH", "$.["+ i +"].type", FritzBox_CallList.state.toString)
			entry = ! calltype.startsWith("[")
			if (entry && calltype == "2") {
				// valid entry and the type == 2, this is a "missed call"
				telnr = transform("JSONPATH", "$.["+ i +"].remoteNumber", FritzBox_CallList.state.toString)
				caller = fboxactions.phonebookLookup(telnr, 10)         // looking for a phonebook entry...
				if (! caller.equals(telnr)) telnr = caller +" ("+ telnr +")"  // ...which exists
				datum = transform("JSONPATH", "$.["+ i +"].date", FritzBox_CallList.state.toString)
				datum = " at "+ datum.substring(8,10) +"."+ datum.substring(5,7) +". "+ datum.substring(11,16)  // add the date and time of the call
				switch (j) {   // the list is automatically sorted by date/time from newest to oldest entry
					case 0: FritzBox_MC1.postUpdate(telnr + datum)
					case 1: FritzBox_MC2.postUpdate(telnr + datum)
					case 2: FritzBox_MC3.postUpdate(telnr + datum)
					case 3: FritzBox_MC4.postUpdate(telnr + datum)
					case 4: entry =false  // we restict the missed calls to at most 4 entries...
					}
				j = j +1
				}
			i = i +1
			} while (entry)
		}
end

The code should be “understandable”… it works in my case…

Please note: During startup of the rule engine it may take a while, until everything is setup. The rule my have been fired before during the startup, so you will not see the results after the CallList item actually has changed (any incoming or outgoing call will trigger a change).

Hope this helps… at least it is a starting point for processing json structs in a loop, filtering some array/list records from a json struct and update items accordingly…

have fun!

hmm… only a few seconds I guess. The phonebook has about 30 entries…