Skip to content

Add a FRITZ!Box to openHAB, using Ansible

Next step on my way to add home automation: the FRITZ!Box. Mostly for the current IP-address, and call information.

After some research it became obvious that more manual work is required, hence again something which can be automated.



openHAB has 3 different modules available which support the AVM FRITZ!Box:

  • AVM FRITZ! Binding: This only supports the home automation on the FRITZ!Box, no information about calls or the box itself is available. Not sure if that will be added to this binding at some point. That is also the only extension which is native for 2.0.
  • Fritzbox Binding (using TR064 protocol): This extension provides call and status information from the FRITZ!Box itself. It's a legacy 1.0 extension, and uses the TR064 protocol to fetch the information.
  • Fritz!Box Binding: That's an old and legacy 1.0 binding which requires telnet access to the FRITZ!Box. Since the telnet support is disabled since FRITZ!OS 6, this extension is more or less useless these days.

For my purpose I need the "fritzboxtr0641" binding in order to receive status and call information. Given that it's a legacy binding, first the legacy bindings need to be activated:

- name: Update extensions configuration
    dest: /etc/openhab2/services/addons.cfg
    regexp: "{{ item.regexp }}"
    line: "{{ item.line }}"
    state: "{{ item.state }}"
    create: yes
    - { regexp: '^#? *package', line: 'package = expert', state: present }
    - { regexp: '^#? *remote', line: 'remote = true', state: present }
    - { regexp: '^#? *legacy', line: 'legacy = true', state: present }


The binding needs the libhttpclient library for Java:

- name: Install required packages
  apt: name={{ item }} state=present
    - openhab2-addons
    - openhab2-addons-legacy
    - libhttpclient-java


The extension install:

- name: Get list of available and installed extensions
    url: "http://{{ ansible_host }}:8080/rest/extensions"
  register: oh2_extensions
  changed_when: false

- name: Install extensions
    url: "http://{{ ansible_host }}:8080/rest/extensions/{{ item }}/install"
    method: POST
  when: "not (oh2_extensions.json|byattr('id', item))[0].installed"
    - binding-fritzboxtr0641
  register: oh2_install_extensions


This extension installs a configuration file, which mainly contains connection information for the FRITZ!Box: IP, username, password. It is strongly recommended to create a separate account on the FRITZ!Box.

- name: Update fritzboxtr064.cfg
    dest: /etc/openhab2/services/fritzboxtr064.cfg
    regexp: "{{ item.regexp }}"
    line: "{{ item.line }}"
    state: "{{ item.state }}"
    create: yes
    - { regexp: '^#? *url', line: 'url=http://{{ fritzbox_ip }}:49000', state: present }
    - { regexp: '^#? *user', line: 'user={{ fritzbox_user }}', state: present }
    - { regexp: '^#? *pass', line: 'pass={{ fritzbox_password }}', state: present }


The call monitor on the FRITZ!Box is disabled by default. Without this monitor enabled, all the "callmonitor_*" Items will not work. Unfortunately the plugin will not log any useful information, but rather just log a "connection refused", a Java stack trace, and will keep trying with an increasing timeout.

To enable the call monitor, call #96*5* from any connected DECT telephone. And #96*4* turns the call monitor off again.


Now it's time to add the available Items. That must happen in an .items file, because legacy extensions can't be configured using the web UI. A good place is /etc/openhab2/items/fritzboxtr0641.items:

String		fboxName			"FBox Model [%s]"		{fritzboxtr064="modelName"}
// get wan ip if FritzBox establishes the internet connection (e. g. via DSL)
String		fboxWanIP			"FBox WAN IP [%s]"		{fritzboxtr064="wanip"}
// get wan ip if FritzBox uses internet connection of external router
//String		fboxWanIPExternal		"FBox external WAN IP [%s]"	{fritzboxtr064="externalWanip"}

// only when using call monitor
// #96*5* - enable callmonitor
// #96*4* - disable callmonitor
Switch		fboxRinging			"Phone ringing [%s]"		{fritzboxtr064="callmonitor_ringing" }
Switch		fboxRinging_Out			"Phone ringing [%s]"		{fritzboxtr064="callmonitor_outgoing" }
Call		fboxIncomingCall		"Incoming call: [%1$s to %2$s]"	{fritzboxtr064="callmonitor_ringing" } 
Call		fboxOutgoingCall		"Outgoing call: [%1$s to %2$s]"	{fritzboxtr064="callmonitor_outgoing" }

// resolve numbers to names according phonebook
Call		fboxIncomingCallResolved	"Incoming call: [%1$s to %2$s]"	{fritzboxtr064="callmonitor_ringing:resolveName" } 

//// Telephone answering machine (TAM) items
//// Number after tamSwitch is ID of configured TAM, start with 0
Switch		fboxTAM0Switch			"Answering machine ID 0"	{fritzboxtr064="tamSwitch:0"}
Number		fboxTAM0NewMsg			"New Messages TAM 0 [%s]"	{fritzboxtr064="tamNewMessages:0"}

// Missed calls: specify the number of last days which should be searched for missed calls
Number		fboxMissedCalls			"Missed Calls [%s]"		{fritzboxtr064="missedCallsInDays:5"}


Obviously I don't edit the file on the openHAB server, but locally and copy it to the server:

- name: Copy items files
    src: "{{ playbook_dir }}/openhab/{{ item }}"
    dest: "/etc/openhab2/items/{{ item }}"
    owner: openhab
    group: openhabian
    mode: 0640
    - fritzboxtr0641.items
  register: items_files



ads' corner on : Configure a FRITZ!Box in openHAB, using Ansible

Show preview
A while ago I posted about adding a Fritz!Box to openHAB, using Ansible. Now I had to use the Playbook to install another Raspberry, and found that some parts are missing in my posting. Mostly at the end, when it comes to configuring the Fritz!Box. The Comments ()


Display comments as Linear | Threaded

No comments

Add Comment

Enclosing asterisks marks text as bold (*word*), underscore are made via _word_.
E-Mail addresses will not be displayed and will only be used for E-Mail notifications.
To leave a comment you must approve it via e-mail, which will be sent to your address after submission.
Form options