Control FRITZ!Box guest wifi and trigger internet reconnects

Hi @mammuth
Yes, I use the app and zones for this…
Ok great, thank you :beers:

Hi @mammuth

I have a Fritzbox 7490. I created a new User with sufficent permissions and changed the logon method to username and password.

Afterwards I tried to set up the integration.

fritzbox:
  devices:
    - host: 192.168.178.1
      username: Pete
      password: !secret fritzbox

After reboot of homeassistant I do not see anything fritzbox related (no service, no entities…).

What am I missing?

You’re mixing two components. :slight_smile:

One is fritzbox (that’s the one you use). It is to integrate switches and other things from AVM.

What you want to use is the component from this thread, fritzbox_tools. See here:

Check the docs for configuration of fritzbox_tools again… :wink:

Aaaaaah I see!

Thank you, I’ll have a look over there :beers:

So I set up HACS and Fritzbox-Tools successfuly.

I see the Call forward as a Toggle switch and I renamed the entity to a more readable value.

If I enable the call forward in fritzbox, the button state change.

When I want to do it from homeassistant (either with Toggle switch or service call) I get the following error:

Logger: custom_components.fritzbox_tools.switch
Source: custom_components/fritzbox_tools/switch.py:400
First occurred: 14:37:46 (3 occurrences)
Last logged: 14:39:49

An error occurred while turning on fritzbox_tools Guest wifi switch.
Logger: custom_components.fritzbox_tools.switch
Source: custom_components/fritzbox_tools/switch.py:421
First occurred: 14:37:46 (1 occurrences)
Last logged: 14:37:46

Home Assistant cannot call the wished service on the FRITZ!Box.
Traceback (most recent call last):
  File "/config/custom_components/fritzbox_tools/switch.py", line 421, in _async_handle_deflection_switch_on_off
    "X_AVM-DE_OnTel:1","SetDeflectionEnable", NewEnable=new_state, NewDeflectionId=self.id
  File "/usr/local/lib/python3.7/site-packages/fritzconnection/core/fritzconnection.py", line 207, in call_action
    return self.soaper.execute(service, action_name, arguments)
  File "/usr/local/lib/python3.7/site-packages/fritzconnection/core/soaper.py", line 170, in execute
    return handle_response(response)
  File "/usr/local/lib/python3.7/site-packages/fritzconnection/core/soaper.py", line 153, in handle_response
    raise_fritzconnection_error(response)
  File "/usr/local/lib/python3.7/site-packages/fritzconnection/core/soaper.py", line 82, in raise_fritzconnection_error
    raise exception(message)
fritzconnection.core.exceptions.FritzArgumentError: UPnPError: 
errorCode: 402
errorDescription: Invalid Args

As I have not selected Wifi switches in the setup of the configuration, I assume that the error is a copy and paste-thingy from within the component…

Okay I got it working:

  • There in fact is a copy past error in switch.py for the Deflection switch error message

  • The arguments for the deflection toggle must be switched in order, its a bug in the firmware according to https://forum.fhem.de/index.php?topic=92247.0

this is working for me:

           self.fritzbox_tools.connection.call_action(
                "X_AVM-DE_OnTel:1","SetDeflectionEnable", NewDeflectionId=self.id, NewEnable=new_state
            )
2 Likes

Hello,
I am using this extension through HACS since some time, but since one of the latest updates I have seen that the Guest WiFi switch is not working properly. The rest is perfect.
This switch always shows an off status, even when the Guest WiFi is activated from the router. If I try to switch it on, nothing happens.
Any clue about the possible problem? Thanks.

It would be great if the wifi switches would have the SSID as an attribute. The library already has this information when “GetInfo” is called.

I have a TTS notification when the guest wifi is enabled and it would be great if alexa could tell by guests the name of the wifi.

For the password I use an input text since this information seems to be not available in fritzconnection. But since the wifi name is already available it could be added to the sensors as an attribute.

Hello,

is there a way to make a call with dial helper with this tool?

Thanks a lot!

I have the fritz box integration installed and also installed fritzbox tools drom hacs.
See my yaml setop below

I get no sensors or switches. What am I missing?


fritzbox_tools:
  host: 192.168.2.254
  username: home-assistant
  password: !secret fritzbox
  devices: 
    - iPhonevanChanna
#   profile_on: "Standaard" # Optional. Use if the names of your "Zugangsprofile" are different as the defaults.
#   profile_off: "Kids"  # Optional.
  use_wifi: True # Optional, default True: if False no wifi switches will be exposed
  use_port: True  # Optional, default True: if False no port switches will be exposed
  use_devices: True  # Optional, default True: if False no device switches will be exposed, redundant if devices is not specified
  use_deflections: True # Optional, default True: if False no call deflection switches will be exposed

In the log I only see
[homeassistant.bootstrap] Waiting on integrations to complete setup: fritzbox_tools

You should check your logs for hints what’s going wrong.

Hello @mammuth, and thank you for this amazing integration.
I just installed the integration following the guide, but I see just 4 entities: Connectivity, Guest Wifi, Wifi, and 5Ghz Wifi.
Why can’t I see the switch to reconnect the FRITZ!Box?
Thank you.

I think the reconnect functionality is only a service and no switch entity.
You can try it in the dev tools and then use lovelace cards to call it or you manually create a helper switch.

Hi @mammuth,

Great integration. Unfortunately it is not working for me:


Logger: custom_components.fritzbox_tools.binary_sensor
Source: custom_components/fritzbox_tools/binary_sensor.py:69 
Integration: FRITZ!Box Tools (documentation) 
First occurred: 6:42:46 (1 occurrences) 
Last logged: 6:42:46

Error getting the state from the FRITZ!Box
Traceback (most recent call last):
  File "/config/custom_components/fritzbox_tools/binary_sensor.py", line 69, in _async_fetch_update
    status = self.fritzbox_tools.fritzstatus
AttributeError: 'FritzBoxTools' object has no attribute 'fritzstatus'

Do you have any ideas?

Config:

  • official docker images on RPi4
  • fritzconnection Package is present in docker

@philwilldo did you use the latest version of the integration when you saw this error? Generally, feel free to post issues on GitHub: https://github.com/mammuth/ha-fritzbox-tools

Ooooh this is so great. Saw it on a mates HA setup, immediately had the „I need that too!“ kind a feeling.

So I installed HACS. Unfortunately „FRITZ!Box Tools“ is not shown as repository on the HACS integration view (nothing found at all by searching for „fritz“).

What is the common way of installing this integration?

Update: so sorry… found it in the Custom Repositories section. As mentioned I‘m completely new to HACS.

Would be great to know how the port forwarding is implemented and if it’s possible to achieve using the base (fritzconnect).

What is the common way of installing this integration?

It is now officially possible to integrate without any custom components btw.

Would be great to know how the port forwarding is implemented

you create a Port Forwarding Rule in the Fritzbox and then you get binary Switches to turn them on/off.
So Basically you are able to open/close a port. Very nice if you do not want to expose something 24/7

Yes I know and use it meanwhile. Unfortunately, HA can only enable/disable port forwardings in the FritzBox which are related to the HA host.

Using Home Assistant to enable/disable a port forwarding for another host is still not possible - which seems to be a FritzBox limitation I think.

At least that´s my experience and current knowledge. Please proof me wrong if you can :smiley:

Correct - it’s an API security limitation of the FritzBox that port forwarding can only be controlled for ports that are directed to the device requesting the control. So HA will only be able to switch ports for the device that is hosting it.

Great tool!
Thank you! I really love the ability to switch off our Kids’ internet if needed :wink:

One question though:
The Guest devices in my guest wifi also have this switch to shutdown internet access.
That does not seem to work and AFAIK the FritzBox does not provide the feature to disable the internet for single guest devices.

Or am I missing something?

Thanks for the great contribution!