Control guest WiFi custom component

Hi guys,

I would like to share a custom component I just created with you!

It allows us to control the guest WiFi of our FRITZ!Box router via Home Assistant.

You find the custom component (next to my complete configuration) on my GitHub account: Drop a star :star2: if you like it! :slight_smile:
https://github.com/mammuth/home-assistant-configuration/blob/master/custom_components/fritzbox_guestwifi.py

How am I using this custom component?

I’m already using an input boolean which indicates whether we have guests at home or not (see screenshot below) - if that flag gets activated we can now automatically turn on the guest wifi network via this custom component.

The automation also sends a pushbullet notification to our smartphones so we can just read the password to our guests or forward it to them.

The automation which uses the custom component is pretty simple:

- alias: "Guests -> Turn on guest wifi"
  trigger:
    platform: state
    entity_id: input_boolean.guest_mode
    to: 'on'
  action:
    - service: fritzbox_guestwifi.turn_on
    - service: notify.pushbullet_max
      data:
        title: "Guest wifi is enabled"
        message: "Password: ..."

flag

Shout out a message if you have questions or input!

Greetings from Germany
Max

11 Likes

Hi,

im pretty new to HA. Can you give a more detailed instruction on how to implement this component?

Thanks,

Sure, I’m happy you’re interested in it :slight_smile:

In your configuration folder, create a directory named custom_components and copy the fritzbox_guestwifi.py file from my repository into that directory.

Inside your configuration.yml, you then need to set the component up via:

fritzbox_guestwifi:
  password: "yourfritzboxpassword"

The custom component registers two services, called fritzbox_guestwifi.turn_on and fritzbox_guestwifi.turn_off, which you can use in automations as you see in my example in the first post:

automation:
  - alias: "Guests -> Turn on guest wifi"
    trigger:
      platform: state
      entity_id: input_boolean.guest_mode
      to: 'on'
    action:
      - service: fritzbox_guestwifi.turn_on
      - service: notify.pushbullet_max
        data:
          title: "Guest wifi is enabled"
          message: "Password: ..."
2 Likes

Thank you, that works perfectly:) Good work!
How do you determine if any guests are at home?
Do I need some special code for that (input_boolean.guest_mode)?

Just create an input_boolean like this:
configuration.yml:

input_boolean:
  guest_mode:
    name: "Gäste Anwesend"
    icon: mdi:account-alert
    initial: off

Then add it to your groups via its entity id input_boolean.guest_mode

1 Like

Awesome. Now it shows this error in the logs:
ERROR (SyncWorker_9) [custom_components.fritzbox_guestwifi] Home Assistant cannot call the wished service on the FRITZ!Box. Are credentials, address and port correct?

Password should be correct - do i need to change smth else?

HM, the component seems to be not able to invoke the action on the FRITZ!Box to turn on the guest WiFi…

I created a new user on the router and pass its username in the fritzbox_guestwifi configuration (username: x). Maybe you should try that as well.

Sadly that does not work either (same error). I have edited the configuration.yaml with username and password (any specials I might miss here?).
My HA is also reachable from outside (dyndns). Maybe that is the problem?

Can HA talk to the FRITZ!Box via the IP 169.254.1.1? Otherwise you should specify the host in the configuration.yaml. (And the port, which is 49000 by default).

I just tested it with my FRITZ!Box 3390 on FRITZ!OS 06.54 - maybe other device/software combinations don’t provide the wished service to control the guest wifi.

Thanks for the great job. Since yesterday working with my Fritz!Box 7490 :wink:

I just had an issue with the configuration and was wondering why it didn’t work. After setting the host and installing fritzconnection Home Assistant is able to switch on/off the guest wifi.

1 Like

Still not working on my side. Seems like the component is not working without further software. Sadly installing fritzconnection is no option for me :frowning:

Think Ill just check for another solution.

Well, using third party packages where possible is one of the core concepts of HomeAssistant :wink:
You can just install fritzconnection via pip.

I’m glad it worked for you @ikisscarlos!
I’m thinking about extending the functionality to not only control the guest wifi but be able to change a couple of settings. Reconnectingthe fritzbox via HA automations (and thus getting a new IP mostly) might be interesting aswell for example.

Hi @mammuth ,
works great on the 7490.
I had to set host, username and passwort in the config.

2 questions:

  1. Is there a way to detect whether the guest wifi is on or not and show it in HASS?
  2. Is it possible to configure the component twice for two separate fritzboxes?

Thanks
Jochen

Thanks for your feedback Jochen.

  1. Is there a way to detect whether the guest wifi is on or not and show it in HASS?

Not yet. But fritzconnection has a wrapper function for that, so we could add a sensor to HA. I’m not sure whether I will do that since I didn’t need it yet, but if I implement it, I’ll drop a line here!

  1. Is it possible to configure the component twice for two separate fritzboxes

Interesting question. I don’t konw how HA behaves when you register the same component twice, but I doubt it will work as you want it to have :slight_smile:
However, my custom_component could be updated to support multiple fritzboxes.

Hi again,

after giving it some more thought, the last point for separate fritzboxes is probably not necessary. Typically, if there are several boxes, the additional ones will act as repeater (or mesh node nowadays) which allows you to have the guest wifi configuration from the main box be applied automatically to all connected ones.

The first point would be more interesting though, since I typically set the geust wifi to automatically deactivate if no one is using it to reduce attack surface. But in a “guests present” scenario I would want to have it enabled until I say otherwise. So, of course I could log in to the box and set it up there but that is not why we are all here :slight_smile:

Maybe the “FRITZ!Box Net Monitor” component could be extended with the wifi stuff. Does not seem out of place there…

Hi all,

@mammuth, I have been thinking about the possible extension for your component and I agree with @jo-me regarding the possibility to track the state of the guest wifi from Home Assistant. The Fritz!Fon for example has an option to enable/disable the guest wifi from the device itself, so it could be great to have Home Assistant listening for it, so automations to turn off the guest wifi still work.

Of course it is up to you :wink:

@mammuth Great thing you did. Do you consider adding it to the homeassistant main stream repo? So we dont have to go through the unnecessary hassles of a manual installation?

1 Like

I’m glad you enjoy it @tedstriker.

I’m not sure yet how this component suits into the other fritzbox components that are already part of HA.
When I add some more controls and sensors it might be suited as a new component like “FRITZ!Box Control” or something like that.

I’m definitely interested in pushing it upstream once I understand what other features I will add to it :slight_smile:

1 Like

@mammuth
Thank you very much for the custom component.
It is working like a charm so far.

May I add some feature request?
The component itself could already be a switch. This would eliminate the need of automations and input_boolean.
It would also be very cool if the status is polled and the state is updated. I configured my guest network to automatically switch off after 1h after the last guest left. So the input_boolean could show a wrong state.
Furthermore I would alo be awsome, if it would be possible to change the guest wifi password via hass. So it would be possible to change the password with a template (random), slider, input fields or something else.

@mammuth

Hi,

This looks like a great component!
I tried to configure it per your sample configuration, but it doesn’t seem to work.

Clicking on input boolean activates the automation and sends me an email (my choice of notify component), but I do not see anything happening on the fritzbox side.

I made sure to use a fritzbox user which has enough permissions.

Any idea how to troubleshoot? I do not see anything in hass logs…