How to get TR064 actions in Javascript rules

Hi.

Using oh 3 and I’m trying to change all rules from DSL to Javascript. Seems to be the next great thing. First problem: How do I get the binding actions in the javascript rules?

actions.get( "tr064", "tr064:fritzbox:aa8537b549" ).phonebookLookup( incoming );

results in

2021-04-27 21:01:27.747 [ERROR] [internal.handler.ScriptActionHandler] - Script execution of rule with UID 'cc11248494' failed: TypeError: null has no such function "phonebookLookup" in <eval> at line number 9

Am grateful for any help.

Hagen

The call is correct. So the problem is likely either the name of the binding is wrong, the ChannelID is wrong, there is a timing issue and the Thing doesn’t exist or isn’t online when the action is called, or you have a typo in the name of the action function itself(e.g. should be phoneBookLookup or something like that).

Dear Rich. Thank you very much for your quick answer.

Good to know. Unfortunately, there are many examples out there that look very different.

Let me give your ideas numbers:

  1. the name of the binding is wrong
  2. the ChannelID is wrong
  3. there is a timing issue and the Thing doesn’t exist or isn’t online when the action is called
  4. you have a typo in the name of the action function itself (e.g. should be phoneBookLookup or something like that).

to 1.) This is the corresponding binding. Seems the name is right:

to 2.) This is the binding configuration.

UID: tr064:fritzbox:aa8537b549
label: FritzBox
thingTypeUID: tr064:fritzbox

to 3.) I can’t say much about that. Just that the thing was set up via the GUI and I don’t see any reason why it shouldn’t be there. Do you have any more information for me?

to 4.) I think that can’t be the problem, because

actions.get( "tr064", "tr064:fritzbox:aa8537b549" )

returns null.

@J-N-K Can you say something about the problem?

Are all those examples the same language? Different how? Are they different from the example in the addon’s docs?

If that call returns null then that almost certainly is the problem. That or 1 is the problem. You are trying to get the actions for the binding “tr064” and Thing with the ID “tr064:fritzbox:aa8537b549”. If you get back a null it means there is no such action. The only time there would be no such action is, assuming the binding name is correct which appears to be the case, if the Thing by that ID doesn’t exist.

You’ve not shown your Thing definition. You’ve not show the Rule you are trying to use it in. You’ve not mentioned when this rule runs. You’ve not mentioned if the Thing is showing as online.

Dear Rich. Thank you for investing time to help me!

I’ve looked at following places.

Here are my thing and my rule.

Thing in GUI

Thing code

UID: tr064:fritzbox:aa8537b549
label: FritzBox
thingTypeUID: tr064:fritzbox
configuration:
  phonebookInterval: 600
  host: 192.168.178.1
  refresh: 60
  password: *****
  tamIndices:
    - "0"
    - "1"
  user: *****

Rule code

triggers:
  - id: "1"
    configuration:
      itemName: FRITZBox6590Cable_EingehenderAnruf
    type: core.ItemStateUpdateTrigger
conditions: []
actions:
  - inputs: {}
    id: "2"
    configuration:
      type: application/javascript
      script: >-
        var incoming = items[ "FRITZBox6590Cable_EingehenderAnruf" ];

        // TEST code on
        incoming = "99887766,01122334455";
        // TEST code off

        // LEARN Investigate why undef and not undefined or null
        if( incoming !== null && incoming != "UNDEF" ) {
          if( incoming.indexOf( "," ) != -1 ) {
            incoming = incoming.slice( incoming.indexOf( "," ) );

            incoming = actions.get( "tr064", "tr064:fritzbox:aa8537b549" ).phonebookLookup( incoming );
          }
          events.postUpdate("textMessage", "Anruf von " + incoming );
        }
    type: script.ScriptAction

Here are my technical data. I omitted that in the first post.

runtimeInfo:
  version: 3.0.1
  buildString: Release Build
locale: de_DE
systemInfo:
  configFolder: /etc/openhab
  userdataFolder: /var/lib/openhab
  logFolder: /var/log/openhab
  javaVersion: 11.0.9.1
  javaVendor: Azul Systems, Inc.
  javaVendorVersion: Zulu11.43+100-CA
  osName: Linux
  osVersion: 5.10.21-rockchip64
  osArchitecture: aarch64
  availableProcessors: 6
  freeMemory: 9357440
  totalMemory: 230686720
bindings:
  - avmfritz
  - dwdpollenflug
  - dwdunwetter
  - mqtt
  - telegram
  - tr064
  - zwave
timestamp: 2021-04-29T07:10:44.382Z

I think you’ve just overwritten the ‘standard’ actions and destroyed them. Don’t do that. Just delete that line.

Thank you for that hint. Unfortunately: mea culpa. That was part of my several try-and-errors. I removed that line, but the result is still the same.

I tried the example code in a DSL rule. So it doesn’t work either.

Could someone try it out on himself to see if it works? Just create a new rule via GUI, copy the javascript code

actions.get( "tr064", "tr064:fritzbox:XXXXXXXXX" ).phonebookLookup( "0123456789" );

or DSL code

getActions("tr064", "tr064:fritzbox:XXXXXXXXX").phonebookLookup( "0123456789" )

into it, replace the fritzbox:XXXXXXXXX with the correct key, save it, run it and look at the log for the javascript error

TypeError: null has no such function “phonebookLookup” in

or the DSL error

The method phonebookLookup(String) is undefined for the type ThingActions;

Maybe @Bredmich? I read that you have the same version of openHAB and using the binding.

Thanks in advance to everyone for your support!

Give me some time :slight_smile:
I´m still figuring out how to use oH 3 and what to do with my rules.

1 Like
actions.get( "tr064", "tr064:fritzbox:XXXXXXXXX" ).phonebookLookup( "0123456789" );

works fine in openHAB 3.1.0 Build #2326

1 Like