Fritz!Box TR-064 - Save the number of the last call

Hello Max,

Just checked my sitemap and i’m using “fbLastNumber” and “fbLastName”.

These are my items:

It’s still working for me… on oH 1.8.3!

Cheers
Michael

1 Like

Thank you kindly :slight_smile:
What is different to your previous post:
fbLastNumber and fbLastName are String items now – but it does not matter with regard to my outcome.

… and you are not getting this error (in openhab.log)?

2017-03-04 16:46:49.272 [ERROR] [o.o.c.s.ScriptExecutionThread ] - Error during the execution of rule 'Eingehender Anruf': Cannot cast org.openhab.library.tel.types.CallType to void

I have copied your rule, removed mine, and I get this error and the number does not stick – as in, when I hang up, the numbers disappear. :frowning:

Yes, I am on 1.8.3 too – and only wonder why mine does not work.

I’m currently not at home but will have a closer look once i’m back this evening.

Cheers
Michael

What I just noticed too:
fbLastNumber and fbLastName are String items now, AND changed to [%s] instead of [%1$s].

This solved the issue with the number not sticking – Now it does!

Thank you very much…

Because the 7490 does not resolve the name; I deleted the second phone book, and imported it into the default phone book… which still did not resolve the number.

However, deleting the org.openhab.binding.fritzboxtr064-1.8.3.jar and adding it again, triggered this:

2017-03-04 17:18:18.962 [INFO ] [.service.AbstractActiveService] - FritzboxTr064 Refresh Service has been shut down
2017-03-04 17:18:21.903 [INFO ] [.service.AbstractActiveService] - FritzboxTr064 Refresh Service has been started
2017-03-04 17:18:22.088 [INFO ] [o.o.b.f.i.FritzboxTr064Binding] - Downloading phonebook ID 0
2017-03-04 17:18:23.129 [INFO ] [o.o.b.f.i.FritzboxTr064Binding] - Callmonitor Thread [45770] attempting connection to FritzBox on 192.168.1.1:1012..
2017-03-04 17:18:23.133 [INFO ] [o.o.b.f.i.FritzboxTr064Binding] - Connected to FritzBox on 192.168.1.1:1012
2017-03-04 17:18:41.370 [INFO ] [o.o.b.f.i.FritzboxTr064Binding] - Trying to resolve number 0411511002 to name comparing 7 characters
2017-03-04 17:18:41.370 [INFO ] [o.o.b.f.i.FritzboxTr064Binding] - Trying to resolve number 0411511002 to name comparing 7 characters
2017-03-04 17:18:41.378 [INFO ] [o.o.b.f.i.FritzboxTr064Binding] - Trying to resolve number 0411511002 to name comparing 7 characters
2017-03-04 17:18:41.383 [INFO ] [o.o.b.f.i.FritzboxTr064Binding] - found name match MaxG in phonebook by comparing 2001151140 with 2001151
2017-03-04 17:18:42.401 [WARN ] [ore.internal.items.ItemUpdater] - InstantiationException on org.openhab.core.library.types.StringType
2017-03-04 17:18:44.634 [INFO ] [nhab.model.script.RuleLastCall] - Der Anruf von 0411511002 (MaxG (Mobile)) wurde als Letzter Anrufer gespeichert.

with the interesting part being:
2017-03-04 17:18:22.088 [INFO ] [o.o.b.f.i.FritzboxTr064Binding] - Downloading phonebook ID 0

I am glad I remembered seeing this before… phonebook id 0

So… all working now!!

Thank you again for helping me out.

I think there is already an 1.9.0 of the Fritz!Box TR-064 Binding.

Glad that everything works now.
I also had some issues finding the right combination.

Going to post the final working combination this evening.

Cheers
Michael

One thing at the time (at least for me)… if 1.8.3 is working, then I need to replicate this first… then go explorer newer things. :slight_smile:

I modified your version to the following:

rule "Eingehender Anruf"
when
  Item fbKlingel changed from OFF to ON
then
  // Letzter Anrufer aktualisieren
  val CallType call = fbAnruf.state as CallType
  val String LastCallNumber = call.destNum.toString()
  val String LastCallName   = fbAnrufName.state.toString()

  LastCallName = LastCallName.removeStart("0754246505##")

  postUpdate(fbLastNumber, LastCallNumber)
  postUpdate(fbLastName, LastCallName)

  logInfo("RuleLastCall", "Last call from " + LastCallNumber + " --> " + LastCallName)
end

… and this works without any errors in openhab.log :slight_smile:

1 Like

Just tried your modified version, it´s working!
Thanks for that.
Sometimes it´s not that easy to write some “clean code” when this isn´t your job :slight_smile:

Binding: Fritzbox TR-064 1.9.0 SNAPSHOT

Items:

/* Fritz!Box */
Switch fbKlingel "Telefon klingel [%s]" <phone> {fritzboxtr064="callmonitor_ringing"}
Call fbAnruf "Anruf von [%1$s]" <phone> {fritzboxtr064="callmonitor_ringing"}
Call fbAnrufName "Anruf von [%1$s]" <phone> {fritzboxtr064="callmonitor_ringing:resolveName"}
String fbLastNumber "Letzter Anrufer: [%s]" <phone>
String fbLastName "Letzter Anrufer: [%s]" <phone>

Sitemap:

Text item=fbLastNumber
Text item=fbLastName

The rule:

import org.openhab.library.tel.types.CallType
import org.openhab.core.library.types.*
import org.openhab.core.persistence.*
import org.openhab.model.script.actions.*

rule "Eingehender Anruf"

when

  Item fbKlingel changed from OFF to ON

then

  // Daten des CallType auslesen
  val CallType call = fbAnruf.state as CallType
  // Die Variablen anlegen und mit der Nummer bzw. Namen des Anrufers füllen
  val String LastCallNumber = call.destNum.toString()
  val String LastCallName   = fbAnrufName.state.toString()
  // Die eigene Rufnummer aus der Variable entfernen
  LastCallName = LastCallName.removeStart("1234567##")
  // Prüfen ob der Anrufer unbekannt ist
  if(LastCallName.startsWith("Name not found for"))
  {
    // Den Namen mit Unbekannt füllen
    LastCallName = "Unbekannt"
  }
  // Die Daten in die Items eintragen
  postUpdate(fbLastNumber, LastCallNumber)
  postUpdate(fbLastName, LastCallName)
  logInfo("RuleLastCall", "Der Anruf von " + LastCallNumber + " (" + LastCallName + ")" + " wurde als Letzter Anrufer gespeichert.")

end

1234567 = your number
Maybe check the log which number is used.

Hope that helps some people :smiley:

Cheers
Michael

1 Like

And just for the heck of it, further simplification:

from

if(LastCallName.startsWith("Name not found for"))
  {
    // Den Namen mit Unbekannt füllen und die Daten in die Items eintragen
    LastCallName = "Unbekannt"
    postUpdate(fbLastNumber, LastCallNumber)
    postUpdate(fbLastName, LastCallName)
    logInfo("RuleLastCall", "Der Anruf von " + LastCallNumber + " (" + LastCallName + ")" + " wurde als Letzter Anrufer gespeichert.")
  }
  else
  {
    // Die Daten in die Items eintragen
    postUpdate(fbLastNumber, LastCallNumber)
    postUpdate(fbLastName, LastCallName)
    logInfo("RuleLastCall", "Der Anruf von " + LastCallNumber + " (" + LastCallName + ")" + " wurde als Letzter Anrufer gespeichert.")
  }

to

if (LastCallName.startsWith("Name not found for"))  {
  // Den Namen mit Unbekannt füllen und die Daten in die Items eintragen
  LastCallName = "Unbekannt"
}
// Die Daten in die Items eintragen
postUpdate(fbLastNumber, LastCallNumber)
postUpdate(fbLastName, LastCallName)
logInfo("RuleLastCall", "Der Anruf von " + LastCallNumber + " (" + LastCallName + ")" + " wurde als Letzter Anrufer gespeichert.")

:smiley:

1 Like

Changed :slight_smile:

Hello,

I have the problem that since I am working with openhab2 the rule to resolve the caller Name/Number ends in a failure. Now I have tried your rule with nearly the same result:

Rule 'Eingehender Anruf': void

What is the problem? Are there any changes in openhab2 in relation to the variable CallType?

Thank you for your help

Hi Johannes,
indeed there was a change in OH2: The CallType Type has been depreciated and is not used any more.
You will need to change your rule like so:

val incCall = fboxIncomingCallResolved.state as StringListType
    val callerNumber = incCall.getValue(1)
    var Anrufer = callerNumber.replace("Name not found for"," ")

Designer will complain and mark the line red; just ignore this it will run just fine.
HTH,
-OLI

Hi Oli,
thank you for your fast response. But please explain me, which part of the old rule I have to replace with your new expression? I have tried a few combination but without success.

rule "Eingehender Anruf"

when

  Item fboxRinging changed from OFF to ON

then

  val incCall = fbAnruf.state.state as StringListType
  val callerNumber = incCall.getValue(1)
  var Anrufer = callerNumber.replace("Name not found for"," ")
  
  postUpdate(fblastNumber, callerNumber)
  postUpdate(fbLastName, Anrufer)
	logInfo("RuleLastCall", "Der Anruf von " + callerNumber + " (" + Anrufer + ")" + " wurde als Letzter Anrufer gespeichert.")
end

End in the following error:

19:35:19.264 [ERROR] [.script.engine.ScriptExecutionThread] - Rule 'Eingehender Anruf': An error occured during the script execution: The name '<XMemberFeatureCallImplCustom>.state' cannot be resolved to an item or type.

I think I am a blockhead:-)

Have a nice evening

Johannes

Most obvious is your double use of .state:

fbAnruf.state.state

try:

fbAnruf.state

instead :slight_smile:
Edit: in your original rule, it should be sufficient to just replace “CallType” with “StringListType”.

Mhhhhhhh you are right Oli, thank you! Perfect!
One more question, How I can use the Name for an item when the name is saved in the phonebook.
A combination of your solution and the solution mentioned in this post does not run. Can you give me a hint?

Greetings

Johannes

Glad you got it working.
But i’mnot sure what you want to achieve…do you want an item for each phonebook entry which is named like the phonebook entry? so you can keep a record how often someone called?

Sorry my question was imprecise.

The result of the rule should give me the following Info:

Der Anruf von 1234567890 (“Caller Name from fritzbox phonebook”) wurde als Letzter Anrufer gespeichert.

With the actually solution I get:

Der Anruf von 1234567890 (1234567890) wurde als Letzter Anrufer gespeichert.

logInfo("RuleLastCall", "Der Anruf von " + callerNumber + " (" + Anrufer + ")" + " wurde als Letzter Anrufer gespeichert.")

val callerNumber and var Anrufer give me the same information (the caller number)

The solution from Max and Michael should give also the Name of the caller if saved at the intern phonebook of the fritzbox. The item “{fritzboxtr064=“callmonitor_ringing:resolveName”}” will give these information with an expression where you can extract the caller name.
I hope you understand my problem now.

Greeting Johannes

OK got it.
Look in the post marked as solution.
You need two Items to get this; one for the number and one for the Number resolved to name from phonebook(or to “Name not found for”).

Call fbAnruf "Anruf von [%1$s]" <phone> {fritzboxtr064="callmonitor_ringing"}//Nummer des Anrufers
Call fbAnrufName "Anruf von [%1$s]" <phone> {fritzboxtr064="callmonitor_ringing:resolveName"}//Name des Anrufers, wenn in Telefonbuch, sonst "Name not found for"

these are both Items of type “Call”, so in your rule use " as StringListType" for both.

Hi Oli,

I tried the following rule with the mentioned items:

rule "Eingehender Anruf"

when

  Item fboxRinging changed from OFF to ON

then

  // Daten des CallType auslesen
  val incCall = fbAnruf.state as StringListType
  val callerNumber = incCall.getValue(1)
  // Die Variablen anlegen und mit der Nummer bzw. Namen des Anrufers füllen
  val String LastCallName   = fbAnrufName.state.toString()
  // Die eigene Rufnummer aus der Variable entfernen
 LastCallName = LastCallName.removeStart("1234567##")
  // Prüfen ob der Anrufer unbekannt ist
 if(LastCallName.startsWith("Name not found for"))
  {
    // Den Namen mit Unbekannt füllen
  LastCallName = "Unbekannt"
  }
  // Die Daten in die Items eintragen
  postUpdate(fbLastNumber, callerNumber)
  postUpdate(fbLastName, LastCallName)
	logInfo("RuleLastCall", "Der Anruf von " + callerNumber + " (" + LastCallName + ")" + " wurde als Letzter Anrufer gespeichert.")
end

With the following output:

Der Anruf von 0987654321 (1234567, Johannes (Mobile)) wurde als Letzter Anrufer gespeichert.

I think “LastCallName = LastCallName.removeStart(“1234567##”)” doesn’t work.

Any ideas?

Thank you for your help and your effort

johannes

check: LastCallName.removeStart(“1234567##”)

i doubt your own number starts with “1234567##”

1 Like

For sure, I replaced it for the post. Filled with my number same result… I double checked this.