Control guest WiFi custom component

Iā€™m glad you like it!

Do you see the log message Turning on guest wifi.? Its log level is INFO.
If not, the component isnā€™t even triggered.

Yes - do not see it. So I guess it is not triggered.
That is helpful, thanks.

Will have to investigate more. I do have fritzconnection installed and fritzbox_callmonitor is working fine.

Would be great if this is possible. I have got multiple third party apps witch could do that.
there is a fritz api which could do it:


but would be great to have this in the component

Is there any way of getting this component to work with a Netgear router?

No, the component uses the FRITZ!Box specific API and a corresponding python library.

Great work! Trying to use your custom_component. but getting an error when turn-on or off the input boolean , linked to the custom component.

2018-02-13 22:08:00 ERROR (MainThread) [homeassistant.core] Error executing service <ServiceCall fritzbox_guestwifi.turn_on>
Traceback (most recent call last):
  File "/srv/homeassistant/lib/python3.6/site-packages/homeassistant/core.py", line 1018, in _event_to_service_call
    yield from self._hass.async_add_job(execute_service)
  File "/usr/local/lib/python3.6/asyncio/futures.py", line 327, in __iter__
    yield self  # This tells Task to wait for completion.
  File "/usr/local/lib/python3.6/asyncio/tasks.py", line 250, in _wakeup
    future.result()
  File "/usr/local/lib/python3.6/asyncio/futures.py", line 243, in result
    raise self._exception
  File "/usr/local/lib/python3.6/concurrent/futures/thread.py", line 56, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/srv/homeassistant/lib/python3.6/site-packages/homeassistant/core.py", line 1015, in execute_service
    service_handler.func(service_call)
  File "/home/pi/.homeassistant/custom_components/fritzbox_guestwifi.py", line 44, in turn_on
    self._handle_turn_on_off(True)
  File "/home/pi/.homeassistant/custom_components/fritzbox_guestwifi.py", line 54, in _handle_turn_on_off
    self._connection.call_action('WLANConfiguration:3', 'SetEnable', NewEnable=new_state)
  File "/srv/homeassistant/lib/python3.6/site-packages/fritzconnection/fritzconnection.py", line 406, in call_action
    return action.execute(**kwargs)
  File "/srv/homeassistant/lib/python3.6/site-packages/fritzconnection/fritzconnection.py", line 130, in execute
    result = self.parse_response(response.content)
  File "/srv/homeassistant/lib/python3.6/site-packages/fritzconnection/fritzconnection.py", line 142, in parse_response
    root = etree.fromstring(response)
  File "src/lxml/etree.pyx", line 3230, in lxml.etree.fromstring (src/lxml/etree.c:81070)
  File "src/lxml/parser.pxi", line 1871, in lxml.etree._parseMemoryDocument (src/lxml/etree.c:121250)
  File "src/lxml/parser.pxi", line 1759, in lxml.etree._parseDoc (src/lxml/etree.c:119926)
  File "src/lxml/parser.pxi", line 1125, in lxml.etree._BaseParser._parseDoc (src/lxml/etree.c:114173)
  File "src/lxml/parser.pxi", line 598, in lxml.etree._ParserContext._handleParseResultDoc (src/lxml/etree.c:107738)
  File "src/lxml/parser.pxi", line 709, in lxml.etree._handleParseResult (src/lxml/etree.c:109447)
  File "src/lxml/parser.pxi", line 638, in lxml.etree._raiseParseError (src/lxml/etree.c:108301)
  File "<string>", line 1
lxml.etree.XMLSyntaxError: Opening and ending tag mismatch: HR line 1 and BODY, line 1, column 162

i do have fritzconnection 0.6.5 installed and can use fritz monitor component just fine.
the services are registered fine, also turning on/off the service with the service developer tool in the frontend, gives the same error. Look like there is something wrong in executing the code. Checked 755 rights on the file and just downloaded the complete file from github, without copy past to be sure the exact content is there.

Looks like the error comes from fritzconnection (/or rather the xml parsing lib?) itself when it parses the response of the request to the router. I just checked the version Iā€™m using and itā€™s also 0.6.5, however Iā€™m not facing that issue.

So my guess is, fritzconnection might have troubles with your FRITZ!Box or itā€™s version.
There is a bug report on the fritzconnection repository where the user states that an update of the FRITZ!OS lead to fritzconnection not working the way as intended anymore, which might be related to your issue.

Thanks for the answer.
Strange thing is that i am using the same fritzconnection for the built in component FritzMontior which is working just fine.

for extra info: i have got an 7490 with 6.83 release in english.

thank you very much. this was exactly what I need

Iā€™m using the component with FB 6490 not branded and FritzOS 7.01. It does not seem to work, should it work? where can I see some logs for this custom_component?

Hi @mammuth,

Iā€™m using your custom component and Iā€™m loving it! Do you have any updates whether you plan an expanding the components abilities (e.g. adding a sensor for the state of the guest wifi) or even releasing it as an official hass component now (some time has gone by)? My programming skills are poor and I canā€™t code my own expansions for setting and receiving the state of the guestwifi. Sorry for digging out this ā€œoldā€ topic but I hope youā€™ve got some news.

Best regards

Fabian

I have a list with some future features, but I havenā€™t touched the component since I posted it here. Iā€™m afraid this trend will probably continue :see_no_evil: :smiley:

Last time I checked the FRITZ! related components werenā€™t really consolidated / each did their own authentication etc.
Before adding more components the existing ones should probably share data which all use and donā€™t reinvent the wheel. Iā€™m not quite sure whether thatā€™s still the case, but I also donā€™t feel capable of doing & testing this.

Hi @mammuth, thanks for contributing this very useful component. Iā€™m really sad that it is not working for me. I followed all your instructions and configured my fritzbox with ip, user & pass. Any ideas? Here is my log:

Mar 18 14:35:32 smarthome hass[16344]: 2019-03-18 14:35:32 INFO (Thread-22)     [custom_components.fritzbox_guestwifi] Turning on guest wifi.
Mar 18 14:35:32 smarthome hass[16344]: 2019-03-18 14:35:32 ERROR (MainThread) [homeassistant.core] Error doing job: Task exception was never retrieved Mar 18 14:35:32 smarthome hass[16344]: Traceback (most recent call last):
Mar 18 14:35:32 smarthome hass[16344]:   File "/usr/lib/python3.5/asyncio/tasks.py", line 241, in _step
Mar 18 14:35:32 smarthome hass[16344]:     result = coro.throw(exc)
Mar 18 14:35:32 smarthome hass[16344]:   File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/helpers/service.py", line 289, in _handle_service_platform_call
Mar 18 14:35:32 smarthome hass[16344]:     await getattr(entity, func)(**data)
Mar 18 14:35:32 smarthome hass[16344]:   File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/components/switch/template.py", line 154, in async_turn_on
Mar 18 14:35:32 smarthome hass[16344]:     await self._on_script.async_run(context=self._context)
Mar 18 14:35:32 smarthome hass[16344]:   File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/helpers/script.py", line 131, in async_run
Mar 18 14:35:32 smarthome hass[16344]:     await self._handle_action(action, variables, context)
Mar 18 14:35:32 smarthome hass[16344]:   File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/helpers/script.py", line 210, in _handle_action
Mar 18 14:35:32 smarthome hass[16344]:     action, variables, context)
Mar 18 14:35:32 smarthome hass[16344]:   File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/helpers/script.py", line 299, in _async_call_service
Mar 18 14:35:32 smarthome hass[16344]:     context=context
Mar 18 14:35:32 smarthome hass[16344]:   File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/helpers/service.py", line 85, in async_call_from_config
Mar 18 14:35:32 smarthome hass[16344]:     domain, service_name, service_data, blocking=blocking, context=context)
Mar 18 14:35:32 smarthome hass[16344]:   File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/core.py", line 1130, in async_call
Mar 18 14:35:32 smarthome hass[16344]:     self._execute_service(handler, service_call))
Mar 18 14:35:32 smarthome hass[16344]:   File "/usr/lib/python3.5/asyncio/futures.py", line 380, in __iter__
Mar 18 14:35:32 smarthome hass[16344]:     yield self  # This tells Task to wait for completion.
Mar 18 14:35:32 smarthome hass[16344]:   File "/usr/lib/python3.5/asyncio/tasks.py", line 304, in _wakeup
Mar 18 14:35:32 smarthome hass[16344]:     future.result()
Mar 18 14:35:32 smarthome hass[16344]:   File "/usr/lib/python3.5/asyncio/futures.py", line 293, in result
Mar 18 14:35:32 smarthome hass[16344]:     raise self._exception
Mar 18 14:35:32 smarthome hass[16344]:   File "/usr/lib/python3.5/asyncio/tasks.py", line 241, in _step
Mar 18 14:35:32 smarthome hass[16344]:     result = coro.throw(exc)
Mar 18 14:35:32 smarthome hass[16344]:   File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/core.py", line 1154, in _execute_service
Mar 18 14:35:32 smarthome hass[16344]:     await self._hass.async_add_executor_job(handler.func, service_call)
Mar 18 14:35:32 smarthome hass[16344]:   File "/usr/lib/python3.5/asyncio/futures.py", line 380, in __iter__
Mar 18 14:35:32 smarthome hass[16344]:     yield self  # This tells Task to wait for completion.
Mar 18 14:35:32 smarthome hass[16344]:   File "/usr/lib/python3.5/asyncio/tasks.py", line 304, in _wakeup
Mar 18 14:35:32 smarthome hass[16344]:     future.result()
Mar 18 14:35:32 smarthome hass[16344]:   File "/usr/lib/python3.5/asyncio/futures.py", line 293, in result
Mar 18 14:35:32 smarthome hass[16344]:     raise self._exception
Mar 18 14:35:32 smarthome hass[16344]:   File "/usr/lib/python3.5/concurrent/futures/thread.py", line 55, in run
Mar 18 14:35:32 smarthome hass[16344]:     result = self.fn(*self.args, **self.kwargs)
Mar 18 14:35:32 smarthome hass[16344]:   File "/home/homeassistant/.homeassistant/custom_components/fritzbox_guestwifi.py", line 49, in turn_on
Mar 18 14:35:32 smarthome hass[16344]:     self._handle_turn_on_off(True)
Mar 18 14:35:32 smarthome hass[16344]:   File "/home/homeassistant/.homeassistant/custom_components/fritzbox_guestwifi.py", line 59, in _handle_turn_on_off
Mar 18 14:35:32 smarthome hass[16344]:     self._connection.call_action('WLANConfiguration:3', 'SetEnable', NewEnable=new_state)
Mar 18 14:35:32 smarthome hass[16344]:   File "/srv/homeassistant/lib/python3.5/site-packages/fritzconnection/fritzconnection.py", line 406, in call_action
Mar 18 14:35:32 smarthome hass[16344]:     return action.execute(**kwargs)
Mar 18 14:35:32 smarthome hass[16344]:   File "/srv/homeassistant/lib/python3.5/site-packages/fritzconnection/fritzconnection.py", line 130, in execute
Mar 18 14:35:32 smarthome hass[16344]:     result = self.parse_response(response.content)
Mar 18 14:35:32 smarthome hass[16344]:   File "/srv/homeassistant/lib/python3.5/site-packages/fritzconnection/fritzconnection.py", line 142, in parse_response
Mar 18 14:35:32 smarthome hass[16344]:     root = etree.fromstring(response)
Mar 18 14:35:32 smarthome hass[16344]:   File "src/lxml/etree.pyx", line 3211, in lxml.etree.fromstring
Mar 18 14:35:32 smarthome hass[16344]:   File "src/lxml/parser.pxi", line 1877, in lxml.etree._parseMemoryDocument
Mar 18 14:35:32 smarthome hass[16344]:   File "src/lxml/parser.pxi", line 1765, in lxml.etree._parseDoc
Mar 18 14:35:32 smarthome hass[16344]:   File "src/lxml/parser.pxi", line 1127, in lxml.etree._BaseParser._parseDoc
Mar 18 14:35:32 smarthome hass[16344]:   File "src/lxml/parser.pxi", line 601, in lxml.etree._ParserContext._handleParseResultDoc
Mar 18 14:35:32 smarthome hass[16344]:   File "src/lxml/parser.pxi", line 711, in lxml.etree._handleParseResult
Mar 18 14:35:32 smarthome hass[16344]:   File "src/lxml/parser.pxi", line 640, in lxml.etree._raiseParseError
Mar 18 14:35:32 smarthome hass[16344]:   File "<string>", line 1
Mar 18 14:35:32 smarthome hass[16344]: lxml.etree.XMLSyntaxError: Opening and ending tag mismatch: HR line 1 and BODY, line 1, column 162

Can you please update the custom component instructions to work with hass new naming scheme for custom components? You can no longer place fritzbox_guestwifi.py in the custom_components folder. What would be the correct way to load this custom component?

1 Like

Yeah, I think the custom component would need some love in order to work again. If someone want to tackle it, feel free to open a PR! Iā€™m not sure when I get to it.

Iā€™ve actually tried like the instructions you provided and it still works but thatā€™s probably not that future proof. But anyway thats a very nice component. I also like your idea with the notifier to push the guest wifi password. great job!

Alrighty, I just updated the component and made it a lot cooler and easier!

New repo: GitHub - mammuth/ha-fritzbox-tools: [merged into HA core] Control guest wifi, port forwardings, device profiles, ... all from within Home Assistant! šŸ¤–āœØ

TL;DR:

  • Works again :tada:
  • Automatically registers a switch to turn on/off guest wifi
  • You can issue ā€œreconnect internetā€ commands (eg. if you want to get a new IP)
  • Installable via HACS

image

Thanks! This also has a high WAF (wife acceptance factor) since she can just say ā€œAlexa, turn on guest wifiā€ and gets the password on her phone which she then can give her friends.

4 Likes

Itā€™s already in HACS!
Just hit the reload button in HACS to manually update all repositories (this also happens automatically periodically)

Awesome! Will try it right now.