[SOLVED] FritzBox TR064 Binding Rule Errors

  • Platform information:
    • Hardware: Raspberry Pi 2 Model B Rev 1.1
    • OS: Raspbian GNU/Linux 9 (stretch)
    • Java Runtime Environment: openjdk version “1.8.0_152” OpenJDK Runtime Environment (Zulu Embedded 8.25.0.76-linux-aarch32hf) (build 1.8.0_152-b76) OpenJDK Client VM (Zulu Embedded 8.25.0.76-linux-aarch32hf) (build 25.152-b76, mixed mode, Evaluation)
  • openHAB version: openHAB 2.4.0-1 (Release Build)
  • Issue of the topic:

I created (stole) a rule for monitoring outgoing calls on my Fritz!Box 7362SL using the FritzBox TR064 Binding (binding-fritzboxtr0641 - 1.13.0) and changed it to mute my media devices when dialing out.

The muting works fine, the telephone number is displayed, but the rule generates an error as follows:

[ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule 'Outgoing Call: An error occurred during the script execution: index=1, size=1

which I guess is a type assignment mismatch for one of the val values.

Also as you can see I put in some loginfo statements to capture what is returned, but these don’t show up in the log (again probably the same issue).

The calledName is not resolved, which is strange, as the binding returms my name as can be seen in the logs below (I am dialing my mobile phone).

I would be grateful if someone can inform me what I am doing wrong.

Many thanks in advance!

Vincent

  • Items configuration related to the issue
// FritzBox Call Monitoring
Switch  	fboxRinging         	"Phone ringing in [%s]"            				(FritzBox_PHO)		{fritzboxtr064="callmonitor_ringing" }
Switch  	fboxRinging_Out     	"Phone ringing out [%s]" 						(FritzBox_PHO)		{fritzboxtr064="callmonitor_outgoing" }
Call    	fboxIncomingCall    	"Incoming call: [%1$s to %2$s]"   				(FritzBox_PHO)		{fritzboxtr064="callmonitor_ringing" } 
Call    	fboxOutgoingCall    	"Outgoing call: [%1$s to %2$s]"    				(FritzBox_PHO)		{fritzboxtr064="callmonitor_outgoing" }

// FritzBox Resolve Numbers to Names via Phonebook
Call    	fboxIncomingCallResolved    "Incoming call: [%1$s to %2$s]" 			(FritzBox_PHO)	    {fritzboxtr064="callmonitor_ringing:resolveName" } 
Call    	fboxOutgoingCallResolved    "Outgoing call: [%1$s to %2$s]" 			(FritzBox_PHO)	    {fritzboxtr064="callmonitor_outgoing:resolveName" }
String 		fbLastNumber 			"Last Caller No.: [%s]" <phone>					(FritzBox_PHO)
String 		fbLastName 				"Last Caller Name: [%s]" <phone>					(FritzBox_PHO)

  • Rules code related to the issue
rule "Outgoing Call"
when
    // fboxRinging_Out is a switch item which switches to ON if call is made
    Item fboxRinging_Out changed
then
    switch fboxRinging_Out.state {
		case ON: {
			// Mute media devices
			lounge_tv_mut.sendCommand (ON)
			if (kitchen_music.state == ON) {kitchen_music_mut.sendCommand (ON)}
			if (lounge_music.state == ON) {lounge_music_mut.sendCommand (ON)}

			logInfo("Outgoing Call:", "Generating called name message...")
			
			// fboxOutgoing call receives numbers/name of number dialed
			val outCall = fboxOutgoingCall.state as StringListType
			val calledNumber = outCall.getValue(0)
			logInfo(calledNumber)
			val outCallResolved = fboxOutgoingCallResolved.state as StringListType
			val calledName = outCallResolved.getValue(0)    
			logInfo (calledName)
			// do something with calledName
			logInfo("Call made to:", calledName, " at ", calledNumber)
			postUpdate(fbLastNumber, calledNumber)
			postUpdate(fbLastName, calledName)
		}
		case OFF: {
			// Unmute media devices
			lounge_tv_mut.sendCommand (OFF)
			if (kitchen_music.state == ON) {kitchen_music_mut.sendCommand (OFF)}
			if (lounge_music.state == ON) {lounge_music_mut.sendCommand (OFF)}
				
			logInfo("Phone Call Finished")
		}
	}
end
  • Services configuration related to the issue
## Binding for accessing FritzBoxes using the TR064 protocol. Uses http(s) requests.

# URL. Either use http://<fbox-ip>:49000 or https://<fbox-ip>:49443 (https preferred!)
url=http://192.xxx.xxx.x:49000

# Refresh Interval (60000ms default)
#refresh=60000

# User Name (only use this value if you configured a user in fbox webui/config!)
# If this parameter is missing, "dslf-config" is used as default username
# It is recommended to to switch to authentication by username in fritzbox config
# and add a separate config user for this binding.
user=xxxxxx

# PW
pass=xxxxxxxxx

fritzboxtr064:phonebookid=1
  • If logs where generated please post these here using code fences:
==> /var/log/openhab2/openhab.log <==
2019-01-27 01:57:55.616 [INFO ] [el.core.internal.ModelRepositoryImpl] - Refreshing model 'fritzbox-tr6401-outgoing-call.rules'
==> /var/log/openhab2/events.log <==
==> /var/log/openhab2/openhab.log <==
2019-01-27 01:58:05.795 [INFO ] [tzboxtr064.internal.PhonebookManager] - Trying to resolve number 0176xxxxxxxx to name comparing 7 characters
2019-01-27 01:58:05.795 [INFO ] [tzboxtr064.internal.PhonebookManager] - Trying to resolve number 0176xxxxxxxx to name comparing 7 characters
2019-01-27 01:58:05.803 [INFO ] [tzboxtr064.internal.PhonebookManager] - Found name match 'Bevan Vincent' in phonebook by comparing incoming number '0176xxxxxxxx' with address book entry '0176xxxxxxxx' 
==> /var/log/openhab2/events.log <==
2019-01-27 01:58:05.836 [vent.ItemStateChangedEvent] - fboxOutgoingCall changed from , to 0176xxxxxxxx,6409664
2019-01-27 01:58:05.846 [vent.ItemStateChangedEvent] - fboxOutgoingCallResolved changed from , to Name not found for 0176xxxxxxxx,6409664
2019-01-27 01:58:05.855 [vent.ItemStateChangedEvent] - fboxRinging_Out changed from OFF to ON
2019-01-27 01:58:09.554 [ome.event.ItemCommandEvent] - Item 'lounge_tv_mut' received command ON
==> /var/log/openhab2/openhab.log <==
2019-01-27 01:58:09.576 [INFO ] [marthome.model.script.Outgoing Call:] - Generating called name message...
2019-01-27 01:58:09.600 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule 'Outgoing Call': An error occurred during the script execution: index=1, size=1
==> /var/log/openhab2/events.log <==
2019-01-27 01:58:09.617 [ome.event.ItemCommandEvent] - Item 'kitchen_music_mut' received command ON
2019-01-27 01:58:09.635 [vent.ItemStateChangedEvent] - lounge_tv_mut changed from OFF to ON
2019-01-27 01:58:09.726 [vent.ItemStateChangedEvent] - kitchen_music_vol changed from 100 to 0
2019-01-27 01:58:12.711 [nt.ItemStatePredictedEvent] - kitchen_music_mut predicted to become ON
2019-01-27 01:58:12.727 [vent.ItemStateChangedEvent] - kitchen_music_mut changed from OFF to ON
2019-01-27 01:58:16.181 [vent.ItemStateChangedEvent] - fboxOutgoingCall changed from 0176xxxxxxxx,6409664 to ,
2019-01-27 01:58:16.223 [vent.ItemStateChangedEvent] - fboxOutgoingCallResolved changed from Name not found for 0176xxxxxx,6409664 to ,
2019-01-27 01:58:16.235 [vent.ItemStateChangedEvent] - fboxIncomingCallResolved changed from , to ,
2019-01-27 01:58:16.244 [vent.ItemStateChangedEvent] - fboxIncomingCall changed from , to ,
2019-01-27 01:58:16.261 [vent.ItemStateChangedEvent] - fboxRinging_Out changed from ON to OFF
2019-01-27 01:58:16.494 [vent.ItemStateChangedEvent] - network_pingdevice_859d7d07_latency changed from 4136.0 to 248.0
2019-01-27 01:58:16.515 [ome.event.ItemCommandEvent] - Item 'lounge_tv_mut' received command OFF
==> /var/log/openhab2/openhab.log <==
2019-01-27 01:58:16.516 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule 'Outgoing Call': An error occurred during the script execution: index=1, size=1
==> /var/log/openhab2/events.log <==
2019-01-27 01:58:16.529 [ome.event.ItemCommandEvent] - Item 'kitchen_music_mut' received command OFF
2019-01-27 01:58:16.541 [vent.ItemStateChangedEvent] - lounge_tv_mut changed from ON to OFF
2019-01-27 01:58:16.562 [nt.ItemStatePredictedEvent] - kitchen_music_mut predicted to become OFF
2019-01-27 01:58:16.591 [vent.ItemStateChangedEvent] - kitchen_music_mut changed from ON to OFF
2019-01-27 01:58:16.603 [vent.ItemStateChangedEvent] - kitchen_music_vol changed from 0 to 100

It looks like the rule doesn’t even execute the first line of the rule. Add more logInfo:

rule "Outgoing Call"
when
    // fboxRinging_Out is a switch item which switches to ON if call is made
    Item fboxRinging_Out changed
then
    logInfo("STEP 1: ", fboxRinging_Out.state.toString)
    switch fboxRinging_Out.state {
                logInfo("STEP 2: ", fboxRinging_Out.state.toString)
		case ON: {
                        logInfo("STEP 3: ", fboxRinging_Out.state.toString)
                        // Mute media devices
			lounge_tv_mut.sendCommand (ON)
			if (kitchen_music.state == ON) {kitchen_music_mut.sendCommand (ON)}
			if (lounge_music.state == ON) {lounge_music_mut.sendCommand (ON)}

Hi Vincent

many thanks for your suggestions - using loginfo to ascertain breakpoints in the rule is a good idea and I will use this more often in the future.

The main problem throwing the error
[ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule 'Outgoing Call': An error occurred during the script execution: index=1, size=
was an error in the syntax of the last loginfo statement, it requires a sub-package, text, i.e.:
loginfo ("<sub-package>","<text>"+"<text>") `referenced here.
Further I had some syntax errors using commas instead of + signs in appending further text and values in the loginfo statements… classic RTFM issue :slight_smile:

Many thx again for your assistance.

Cheers

Vincent

ReadTheManual3

indeed :frowning:

Could you post your working code and tick the solution, please?
Thanks

Sure was just tidying it up. I have two working rules, one for outgoing calls and one for incoming calls. I enclose both here. My example contains actions to mute my media devices. Of course these can be replaced with whatever actions you want to perform, e.g. flash or change colour of lights.

Hope this helps others, I spent some time looking for some of the rule logic, and a lot of it was available from Michael Bredmich, so thank you Michael!

Cheers

Vincent

Outgoing Calls Rule

rule "Outgoing Call"
when
    // fboxRinging_Out is a switch item which switches to ON if the phone is offhook and an outgoing call is started
    Item fboxRinging_Out changed
then
			
	switch fboxRinging_Out.state 
	{
		case ON: // outgoing call is ringing (offhook)
		{
			logInfo("Outgoing Call Rule:", "Get called name and number...")
			
			// Query fboxOutgoingCall to get numbers/name of telephone number dialed from Fritz!Box phone directory used
			val outCall = fboxOutgoingCall.state as StringListType // get call state as a list type
			val calledNumber = outCall.getValue(0) // get called telephone number from list
			val outCallResolved = fboxOutgoingCallResolved.state as StringListType // get resolved name from call item value as a list type
			val calledName = outCallResolved.getValue(0) + "," + outCallResolved.getValue(1) // format name from values 0 and 1 in the listtype - lastname and firstname
			val callerNumber = outCallResolved.getValue(2) // get own phone number from call item value 
			if (calledName.contains("not found")) {callerName = "Unknown Number"} // if caller name cannot be resolved from directory set value as "Unknown Caller"
	
			// Outgoing Call started - mute my media devices
			if (lounge_tv_netonl.state == ON) {lounge_tv_mut.sendCommand (ON)}
			if (kitchen_music.state == ON) {kitchen_music_mut.sendCommand (ON)}
			if (lounge_music.state == ON) {lounge_music_mut.sendCommand (ON)}

			logInfo("Outgoing Call Rule:", "Call made to: " + calledName + " at " + calledNumber + " from " + callerNumber)
			
			// Update last called name with calledName, last called number with calledNumber and own number called on - to be displayed on sitemap
			postUpdate(fbLastNumber, calledNumber)
			postUpdate(fbLastName, calledName)
			postUpdate(fbLastPhone, callerNumber)
		}
		case OFF: // Outgoing Call stopped ringing 
		{
			logInfo("Outgoing Call Rule:","Phone stopped ringing")
	
			val outCall = fboxOutgoingCall.state as StringListType
			val calledNumber = outCall.getValue(0)

			if (calledNumber == "") // Outgoing Call has stopped (onhook)
			{
				logInfo("Outgoing Call Rule:","Phone disconnected")

				// Phone has stopped ringing and not connected - unmute my media devices
				if (lounge_tv_netonl.state == ON) {lounge_tv_mut.sendCommand (OFF)}
				if (kitchen_music.state == ON) {kitchen_music_mut.sendCommand (OFF)}
				if (lounge_music.state == ON) {lounge_music_mut.sendCommand (OFF)}
			}
		}
	}
end

Incoming Calls Rule

rule "Incoming Call"
when
    // fboxRinging_In is a switch item which switches to ON if an incoming call is detected
    Item fboxRinging_In changed
then
    switch fboxRinging_In.state
	{
		case ON: // Incoming Call ringing
		{
			// Mute media devices
			if (lounge_tv_netonl.state == ON) {lounge_tv_mut.sendCommand (ON)} 
			if (kitchen_music.state == ON) {kitchen_music_mut.sendCommand (ON)} 
			if (lounge_music.state == ON) {lounge_music_mut.sendCommand (ON)} 
			
			logInfo("Incoming Call Rule:", "Get called name and number...")
			
			// Query fboxOutgoingCall to get numbers/name of telephone number dialing from Fritz!Box phone directory used
			var incCall = fboxIncomingCall.state as StringListType // get incoming call state as list type
			var calledNumber = incCall.getValue(0) // get own number called
			var callerNumber = incCall.getValue(1) // get caller number
			val incCallResolved = fboxIncomingCallResolved.state as StringListType // get resolved name from call item value as a list type
			val calledName = incCallResolved.getValue(1) + "," + incCallResolved.getValue(2) // format name from values 1 and 2 in the listtype - lastname and firstname
			if (calledName.contains("not found")) {callerName = "Unknown Caller"} // if caller name cannot be resolved from directory set value as "Unknown Caller"
			
			logInfo("Incoming Call Rule:", "Incoming Call from " + calledName + " on " + callerNumber + " to " + calledNumber)
		}
		case OFF: 
		{
			logInfo("Incoming Call Rule:","Phone stopped ringing")

			val incCall = fboxOutgoingCall.state as StringListType
			val callerNumber = incCall.getValue(0)

			if (callerNumber == "") // Incoming Call has stopped (onhook)
			{
				logInfo("Incoming Call Rule:", "Phone disconnected")

				// Unmute media devices
				if (lounge_tv_netonl.state == ON) {lounge_tv_mut.sendCommand (OFF)}
				if (kitchen_music.state == ON) {kitchen_music_mut.sendCommand (OFF)}
				if (lounge_music.state == ON) {lounge_music_mut.sendCommand (OFF)}				
			}
		}
	}
end

think I chose the wrong post to reply to… anyway I posted my cleaned up working rule and maked it as solved :wink:

I tried to do the same as you for resolving the name for an outgoing call. However it always fails even if the person is in my address book because it tries to resolve the called number with an appended # as in this example:

I am calling 0123-45678 and the log says (with 0049987654321 being correctly my number I call from):

Trying to resolve number 012345678# to name comparing 7 characters
fboxOutgoingCallResolved: Name not found for 012345678,#0049987654321

How do I get the name resolved correctly for outgoing calls?