Control FRITZ!Box guest wifi and trigger internet reconnects

I created a custom component called FRITZ!Box Tools

Current features:

  • Turn on/off guest wifi
  • Reconnect your fritzbox to your ISPs connection to (hopefully) get a new IP
  • Manage port forwardings for your HomeAssistant device
  • Sensor for internet connectivity (with external IP and uptime attributes)
  • More fritzbox related features might come :blush:

Installation can be done via HACS or manually (check out the repo for more information)

image

Example automation with high WAF (wife acceptance factor):

automation:
  - alias: "Guests Wifi Turned On -> Send Password To Phone
    trigger:
      platform: state
      entity_id: switch.fritz_box_guest_wifi
      to: 'on'
    action:
      - service: notify.pushbullet_max
        data:
          title: "Guest wifi is enabled"
          message: "Password: ..."

Pro tip: Expose the switch to your Alexa/Google Assistant for even higher WAF.

Note: I created the component back in 2017 and shared it with you, but now did a complete overhaul.

7 Likes

thanks for this component! Really useful!

Is it also possible to create a switch for a device ā€œprofileā€?
I have a internet profil for my kids phone that turns the wifi off in the night on weekdays - but want to leave it on if the weekday is a bank holiday (will be checked from a google calender) and other automations

This is awesome! I was thinking about creating such a component myself. But right now Iā€™m still occupied with getting my HA installation into a basic working state.

Is it possible to install this component using the official HA docker image? I guess one could install it into the image. But if I understand it correctly the component would not survice a docker image upgrade, would it?

Also Iā€™m curious. How do you actually communicate with the Fritz!Box? Did you use the TR-064 API or something different?

AVM TR-064

Currently not, but if itā€™s something that the underlying python library provides, it could get added.

There are two ways to install it. Either use HACS (preferred way; also provides an easy way for upgrading it in the future) or drop it manually into your config folder: YOUR_CONFIG_DIRECTORY/custom_components/fritzbox_tools/.
Iā€™m not running a docker environment myself, but I guess youā€™re mounting your config directory as a docker volume, so as long as your HA config stays when you rebuild the images, the component does as well :wink:

Communication is done via the package fritzconnection

Thanks for the details. I havenā€™t looked into extending HA and wasnā€™t aware itā€™s so easy. You are right, the config folder is usually persisted between reboots and after upgrades. Therefore it should be easy to just install it manually. As far as I understand it, hacs uses the same folder.

Just one more question. If I decide to install it manually, do I have to install the fritzconnection dependency manually into the docker container or will home assistant do it for me?

Not 100% sure, but I think HA should install the dependency automatically. Feel free to comment if that was not the case.

Very cool. Thanks for updating!

Iā€™ve been using the old component since it came out. Had it on an old HA instance until last week but installed it on the latest hassio on Sunday and it still worked.

Did you manage to determine the current state of the guest wifi in the new version?

1 Like

Sadly the protocol of the FRITZ!Box seems to not support this (see https://github.com/mammuth/ha-fritzbox-tools/issues/6 for more information).

Super glad it still works out for you!

On the roadmap! :tada: https://github.com/mammuth/ha-fritzbox-tools/issues/2

Iā€™ve tested the latest version now and the switch / sensor for guest wifi work fine. :+1:

One thing that is irritating is that the switch turns back ā€˜offā€™ after activating because the fritzbox call apparently takes longer than HAā€™s timeout / grace period. After a couple more seconds, it will be consistent again. Iā€™m normally using a picture entity card to toggle the state so it will seemingly not react for 10s because it is not as optimistic as the switch control.

In case youā€™re looking for new features I have two suggestions:

  1. Allow to create/delete or alternatively enable/disable port forwardings in the fritzbox. My use case, for example, is that I only turn on port forwarding on port 80 when I run the letsencrypt addon to refresh my SSL cert. So right now this is a manual step every ~90 days. Iā€™ve looked into a shell script that was supposed to do that, but for some reason the fritzbox did not like the requestā€¦
    There is an API for that (AddPortMappingā€™, ā€˜DeletePortMappingā€™) but there was some issue with IPv6 being present recently even though only a IPv4 portmapping was requested.

  2. Trigger phone calls
    For my ā€œalarm systemā€ I used to have a script that would trigger an outgoing call to my cell phone when the alarm would go off. So when I received a call from a dedicated number Iā€™d know that Home assistant called. The script stopped working after a while unfortunatelyā€¦ IIRC it used the ā€œWƤhlhilfeā€ feature via ā€œ/fon_num/dial_foncalls.luaā€

Yup, thatā€™s tracked over here: https://github.com/mammuth/ha-fritzbox-tools/issues/8

+1 for enabling/disabling ports. That would be very neat indeed.

Another neat feature would be a way to show the guest wifi password, possibly as with a qr code.

Thank you so much for creating this useful component. I would love to contribute, just donā€™t have the skills (yet).

1 Like

Thanks to AaronDavidSchneider and @jo-me port forwardings can now be controlled via fritzbox_tools version 1.2.0! :tada:

Note: it only works with port forwardings for the device which is running the component. Check out the readme for setup instructions.

Works great! Thanks AaronDavidSchneider :slight_smile:

Now that we can enable/disable the port forwarding for letsencrypt it would be possible to automatically trigger the hassio addon to renew the certificate.

One step is missing though: the new cert needs to be converted in the correct format and then uploaded to the fritzbox.

I did these things manually until I found this upload script:


It adds the different cert files along with some header infos into one temp file and then creates a post request to a certain endpoint.

In order to automate that weā€™d need access to the hassio/ssl folder where the addon puts the cert files, though.

Is there a reason you terminate the SSL connection on the router?
Alternatives would be letting HA handle the ssl connection or using eg. nginx as a reverse proxy in front of your HA (there are hassio add-ons for this; thatā€™s the way I do it).

I terminate SSL at the edge mainly because I expose the Fritz!Nas sometimes and by default the browsers show only security warnings due to the baked in default self-signed certificate.

Also, it has the benefit that other devices in the LAN do not have to deal with SSL at all.

I agree that it could be set up with Nginx Proxy manager (maybe), but I found that it is not as easy to setup as it sounds. I could not get many web apps to work properly through nginx proxy manager (I used the hassio addon). A simple & straight forward web app may work like described but when it comes to more complex ones like grafana, deconz, nextcloud and the like, it does not work out of the box.

Hey @dromobar, Iā€™ve got good news for you! :slight_smile:
We implemented profile switches for every device on your network!

You can try this in the newest version 1.3.0 (available via HACS).
Implementation was mainly done by AaronDavidSchneider.

Looking forward to your feedback!

For some reason Iā€™m constantly getting an Invalid Config notification for this, even though I have the correct host ip, username & password.

Iā€™ve even checked that the Fritz!connect dependencies are installed with pip.