Rule not working from parsed phone number coming from fritzbox binding

  • Hardware: Raspberry Pi 3 Model B Rev 1.2
  • OS: openhabian
  • openHAB version: 2.2.0~20171028111659-1 (Build #1071)
    Some weeks ago the migration from OH 1.8 to 2.2 unstable was done according the tutorial. Half of the rules transfer went good, most others could be changed and are up and running. Also hardwaremigration from a Tinkerforge RedBrick (running since beginning of 2016) to a Raspberry Pi3 openhabian. And also a lot of code cleaning. But I’m unable to bring the last rule up again since two weeks. It was running well with OH 1.8.

The gate should open when a specific phonenumber calls a specific phone number. The fritzbox binding can see the call. Tried also the fritzbox tr064 binding. So this should not be the issue. However the rule starts but is logged with an error and ‘void’ and does not trigger anything. See below.

Items:

Switch    Incoming_Call     "Ringing"                        (Phone)    { fritzbox="inbound" }
Call      Active_Call       "Connected to [%1$s from %2$s]"  (Phone)    { fritzbox="active"  }
Call      Incoming_Call_No  "Caller No. [%2$s]"              (Phone)    { fritzbox="inbound" }

Rule

rule "Mache Tor auf wenn von einer bestimmten Nummer die 98765 angerufen wird"
when
    Item Incoming_Call changed to ON
then
		var call = Incoming_Call_No.state as CallType
        var destNum = call.getDestNum()
        var origNum = call.getOrigNum()
if (call.origNum.toString.contains("012345678")) 
{
    if (call.destNum.toString.equals("98765")) 
    {  
        Tor_Impuls_Beide_Fluegel.sendCommand(ON)
     }
}
end

Eclipse Smart home designer says for the rule:
"Multiple markers at the line with “var call”

  • The method or field Incoming_Call_No is undefined
  • CallType cannot be resolved to a type."

And for the lines with “var destNum” and “var origNum”
“The value of the local variable origNum is not used”

Log file

2017-11-08 19:25:07.104 [vent.ItemStateChangedEvent] - Incoming_Call_No changed from  to 012345678,98765
2017-11-08 19:25:07.111 [vent.ItemStateChangedEvent] - Incoming_Call changed from OFF to ON
11-08 19:25:07.119 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule 'Mache Tor auf wenn von einer bestimmten Nummer die 98765 angerufen wird': void

Adding this to the rule did not help

import org.openhab.library.tel.types.CallType

When the rule is loaded after saving, the log confirms this without error.
What could be wrong with the rule, or do I misunderstand something else here?

I guess that CallType is not present in openHAB Designer, so this Marker can be ignored.

That is because you never use the vars. Please change your rule to

var String origNum = call.getOrigNum()
var String destNum = call.getDestNum()
if (origNum.toString.contains("012345678")) 
...
if (destNum.toString.equals("98765")) 
...
1 Like

First of all, is Incoming_Call defined in a .items file or was it defined through one of the UIs like PaperUI? If it was defined through one of the UIs ESH Designer will be unaware of those Items and mark them as being an error. ESH Designer may also be unaware of the CallType state.

That one is simple. You define destNum and origNum but you never actually use those in the rule. You get those values from the call directly.

It wouldn’t, as it says in the Migration Tutorial, everything that was in org.openhab has moved somewhere else.

I don’t quite understand this statement. Are you saying that when you save the .rules file there are no errors in openhab.log? That is good news as it means that there is nothing syntactically wrong with the file. You are running a recent enough version of OH that problems with the syntax generates errors in the logs with line and column numbers for the source of the problem.

I’m going to recommend trying out the VSCode openhab plugin over ESH Designer. It is almost as good at ESH Designer at finding errors and it is more up to date. ESH Designer is kind of at a dead end. See if it tells you of any errors in your code.

To debug the problem, add some logging to the top of your rule to see what we are dealing with.

I could not find a CallType class anywhere in the logs so I don’t know if this still exists. Add the following log statements:

logInfo("call", "Incoming_Call.state is of type " + Incomming_Call.state.class.name)
logInfo("call", "Incoming_Call.state as String is " + Incoming_Call.state.toString)
logInfo("call", "Incoming_Call.state has the following methods: " + Incoming_Call.state.class.methods.toString)

I’m going from memory so the two statements that use class might be wrong.

Or if you just want a quick workaround you can use the following code:

var call = Incoming_Call_No.state.toString.split(",")
var origNum = call.get[0]
var destNum = call.get[1]
if(origNum.contains("012345678") && destNum.contains("98765") {
    Tor_Impuls_Beide_Fluegel.sendCommand(ON)
}
1 Like

Why so complicated ???

Do it like this :slight_smile:

rule "Mache Tor auf wenn von einer bestimmten Nummer die 98765 angerufen wird"
when
  Item Incoming_Call changed to ON
then
  if(Incoming_Call_No.state.toString == "98765,012345678"){
    Tor_Impuls_Beide_Fluegel.sendCommand(ON)
  }
end
1 Like

@Udo_Hartmann @rlkoshak @ei_Gelb_Geek Thanks a lot to you all.
I’m unsure about what the solution was. After testing all 3 solutions from your posts carefully - no success. Debugging, testing… in total 3 days 2-3 hours each day or night.
Then I uninstalled the fritzbox binding via paper UI (never used it before), deleted the name of the binding in the addons.cfg (binding = …). Deleted the fritzbox.cfg file. New installation of the binding. And all of your solutions worked.