I wrote a comprehensive example of how to use the new features provided by avmfritz Binding combined with TR-064 Binding.
avmfritz Binding
- provides the Call Monitor
TR-064 Binding
- provides information about number of incoming, outgoing or missed calls
- provides the phone book: a Profile and Thing Actions to look-up phone numbers
- (optionally) allows to configure and a FRITZ!Box integrated TAM (Telephone Answering Machine) - not included in the example
Example
Assuming we have a FRITZ!Box with IP-Address XXX.YYY.ZZZ.1 (<IP>
) represented in openHAB by two Things (one for avmfritz, the other one for tr064) with <THING_ID> = XXX_YYY_ZZZ_1
. We use the same Id for both Bindings.
For simplification I replaced the name of the phone book by <PHONEBOOK_NAME>. You can extract the available phone book names when configuring a phone book Profile via UI. There always is a default phone book which name is related to the IP-Address (e.g. "tr064_3Afritzbox_3AXXX_5FYYY_5FZZZ_5F1"
- be aware of the "XXX"
, "YYY"
, "ZZZ"
and "1"
).
*.things
Bridge avmfritz:fritzbox:<THING_ID> "FRITZ!Box" [ipAddress="<IP>", user="<USER>", password="<PASSWORD>"]
Bridge tr064:fritzbox:<THING_ID> "FRITZ!Box" [host="<IP>", user="<USER>", password="<PASSWORD>"]
avmfritz.items
// Call Monitor Equipment
Group gCALLMONITOR "Call Monitor" ["Equipment"]
Call fritzIncomingCall "Incoming Call [von %2$s an %1$s]" (gCALLMONITOR) ["Status"] { channel="avmfritz:fritzbox:<THING_ID>:incoming_call" }
Call fritzActiveCall "Active Call [von %1$s]" (gCALLMONITOR) ["Status"] { channel="avmfritz:fritzbox:<THING_ID>:active_call" }
Call fritzOutgoingCall "Outgoing Call [von %2$s an %1$s]" (gCALLMONITOR) ["Status"] { channel="avmfritz:fritzbox:<THING_ID>:outgoing_call" }
String fritzCallRinging "Status [%s]" (gCALLMONITOR) ["Status"] { channel="avmfritz:fritzbox:<THING_ID>:call_state" }
// resolved numbers (only if TR-064 binding is installed)
String fritzIncomingCallCallee "Incoming Call - Callee [%s]" (gCALLMONITOR) ["Status"] { channel="avmfritz:fritzbox:<THING_ID>:incoming_call" [profile="transform:PHONEBOOK", phonebook="<PHONEBOOK_NAME>"]
String fritzIncomingCallCaller "Incoming Call - Caller [%s]" (gCALLMONITOR) ["Status"] { channel="avmfritz:fritzbox:<THING_ID>:incoming_call" [profile="transform:PHONEBOOK", phonebook="<PHONEBOOK_NAME>", phoneNumberIndex=1] }
String fritzActiveCallCaller "Active Call - Caller [%s]" (gCALLMONITOR) ["Status"] { channel="avmfritz:fritzbox:<THING_ID>:active_call" [profile="transform:PHONEBOOK", phonebook="<PHONEBOOK_NAME>"] }
String fritzOutgoingCallCallee "Outgoing Call - Callee [%s]" (gCALLMONITOR) ["Status"] { channel="avmfritz:fritzbox:<THING_ID>:outgoing_call" [profile="transform:PHONEBOOK", phonebook="<PHONEBOOK_NAME>"] }
String fritzOutgoingCallCaller "Outgoing Call - Caller [%s]" (gCALLMONITOR) ["Status"] { channel="avmfritz:fritzbox:<THING_ID>:outgoing_call" [profile="transform:PHONEBOOK", phonebook="<PHONEBOOK_NAME>", phoneNumberIndex=1] }
You can omit the PHONEBOOK_NAME
in the Profile configuration as it is an optional parameter. If you do not pass it, all available phonebooks will used to determine the name. Additionally there is another optional parameter matchCount
.A configured integer
vauue is counted from the right end of the phone number and denotes the number of matching characters needed to consider this number as match for a name.
tr064.items
// Incoming, Outgoing and missed calls in the last 7 days
Number fritzboxIncomingCalls "Incoming Calls [%d]" (gCALLMONITOR) ["Status"] { channel="tr064:fritzbox:<THING_ID>:inboundCalls_7" }
Number fritzboxOutgoingCalls "Outgoing Calls [%d]" (gCALLMONITOR) ["Status"] { channel="tr064:fritzbox:<THING_ID>:outboundCalls_7" }
Number fritzboxMissedCalls "Missed Calls [%d]" (gCALLMONITOR) ["Status"] { channel="tr064:fritzbox:<THING_ID>:missedCalls_7" }
Jython Rule
from core.actions import LogAction
from core.rules import rule
from core.triggers import when
def getTR064Actions():
return actions.get("tr064","tr064:fritzbox:<THING_ID>")
@rule("Trigger for fritzOutgoingCall changed")
@when("Item fritzOutgoingCall changed")
def Changed(event):
if not isinstance(event.itemState, UnDefType):
callee = event.itemState.getValue(0)
caller = event.itemState.getValue(1)
LogAction.logInfo("avmfritz", "Outgoing call: {} [Caller={}, Callee={}]", event.itemState, caller, callee)
tr064Actions = getTR064Actions()
#calleeResolved = tr064Actions.phonebookLookup(callee)
calleeResolved = tr064Actions.phonebookLookup(callee, <PHONEBOOK_NAME>)
#callerResolved = tr064Actions.phonebookLookup(caller)
callerResolved = tr064Actions.phonebookLookup(caller, <PHONEBOOK_NAME>)
LogAction.logInfo("avmfritz", "Caller={}, Callee={}", callerResolved, calleeResolved)
Output
2021-01-07 12:00:23.067 [INFO ] [g.openhab.core.model.script.avmfritz] - Outgoing call: 015119644845,6816477 [Caller=123, Callee=555 - 555 666 777]
2021-01-07 12:00:23.075 [INFO ] [g.openhab.core.model.script.avmfritz] - Caller=Mr. X, Callee=Christoph
Call Monitor Card