Coder Social home page Coder Social logo

ufozone / ha-unifi-voucher Goto Github PK

View Code? Open in Web Editor NEW
12.0 1.0 0.0 393 KB

UniFi Hotspot Manager Integration

License: MIT License

Python 100.00%
hacs hacs-integration home-assistant homeassistant ubiquiti ubiquiti-unifi-controller unifi unifi-controller

ha-unifi-voucher's Introduction

UniFi Hotspot Manager

License Project Maintenance GitHub Activity

hacs Discord Community Forum

GitHub Release issues release-badge validate-badge lint-badge

UniFi Hotspot Manager as a Custom Component for Home Assistant.

This integration facilitates user-friendly management of guest Wi-Fi vouchers. By integrating with Home Assistant, users can swiftly and easily generate and display personalized access codes. These vouchers can then be shared with guests, granting temporary access to the Wi-Fi network.

Key features of the integration include:

  • Voucher Creation: Users can effortlessly generate new access codes, with various configuration options such as validity period and available data volume.
  • Display of Voucher: The last created voucher is presented in the Home Assistant interface. As soon as the voucher has been used, the next one will be displayed.
  • QR Code Display: The integration enables the display of a QR code for the guest Wi-Fi, facilitating quick connectivity for guests.
  • Automation: The integration can be integrated into existing automations and allows, for example, the time-controlled creation of vouchers.
  • User-Friendliness: The integration is designed to offer an intuitive user experience, utilizing the Home Assistant interface as a central control center for guest Wi-Fi management.

The UniFi Hotspot Manager Integration provides a practical solution for the temporary provision of Wi-Fi access, seamlessly integrating into the Home Assistant environment for intuitive use.

The most UniFi Network Controller by Ubiquiti Networks, inc., e.g. Cloud Key 2, UDM, UDM Pro are supported.

Example of use

The voucher can be presented together with the QR code on a lovelace card:

Lovelace Card

Blueprint of the example The example shown can be implemented as follows. The image file for the background must be stored in the `/config/www/` folder.
type: picture-elements
image: /local/hotspot-bg.jpg
elements:
  - type: state-label
    entity: image.123456789073fdb051c706194_qr_code
    attribute: wlan_name
    style:
      top: 15%
      left: 50%
      color: white
      font-size: 200%
      font-weight: bold
      cursor: default
    tap_action:
      action: none
    hold_action:
      action: none
  - type: image
    entity: image.123456789073fdb051c706194_qr_code
    style:
      top: 53%
      left: 20%
      width: 30%
      cursor: default
  - type: state-label
    entity: sensor.123456789073fdb051c706194_voucher
    style:
      top: 53%
      left: 67%
      background: rgba(11, 11, 11, 70%)
      padding: 10px
      height: 60px
      color: white
      border-radius: 12px
      font-size: 275%
      font-weight: bold
      cursor: default
    tap_action:
      action: none
    hold_action:
      action: none
  - type: state-label
    entity: sensor.123456789073fdb051c706194_voucher
    attribute: duration
    prefix: 'Duration: '
    style:
      top: 61%
      left: 67%
      color: white
      cursor: default
    tap_action:
      action: none
    hold_action:
      action: none
  - type: service-button
    title: Refresh
    style:
      transform: none
      bottom: 5%
      left: 5%
    service: button.press
    service_data:
      entity_id: button.123456789073fdb051c706194_update
  - type: service-button
    title: Create
    style:
      transform: none
      bottom: 5%
      right: 5%
    service: button.press
    service_data:
      entity_id: button.123456789073fdb051c706194_create

Installation

Important

Requires Home Assistant 2024.8.0 or newer.

Installation through HACS

Installation using Home Assistant Community Store (HACS) is recommended.

  1. If HACS is not installed, follow HACS installation and configuration at https://hacs.xyz/.

  2. Click the button below or visit the HACS Integrations pane and add https://github.com/ufozone/ha-unifi-voucher.git as an Integration by following these instructions.

    Open your Home Assistant instance and open a repository inside the Home Assistant Community Store.

  3. Install the integration.

  4. Restart Home Assistant!

  5. Make sure that you refresh your browser window too.

Manual installation

  1. Download the unifi_voucher.zip file from the repository release section.

    Do not download directly from the main branch.

  2. Extract and copy the content into the path /config/custom_components/unifi_voucher of your HA installation.

  3. Restart Home Assistant!

  4. Make sure that you refresh your browser window too.

Setup integration

Start setup:

  • Click this button:

    Open your Home Assistant instance and start setting up a new integration.

  • Or use the "Add Integration" in Home Assistant, Settings, Devices & Services and select "UniFi Hotspot Manager".

Configuration

  • All configuration options are offered from the front end.
  • For UniFi OS a local-only user needs to be created. A user who uses the Ubiquiti cloud will not work.
  • The user needs super admin, site admin or hotspot privileges in order to manage guest vouchers.

Available components

Buttons

  • create

    Attributes:

    last_poll
    
  • delete

    Attributes:

    last_poll
    
  • update

    Attributes:

    last_poll
    

Images

This entity is disabled by default. You have to activate it if you want to use it.

  • qr_code

    Attributes:

    wlan_name, last_poll
    

Numbers

These entities are disabled by default. You have to activate it if you want to use it.

  • voucher_quota

    Attributes:

    last_poll
    
  • voucher_duration

    Attributes:

    last_poll
    
  • voucher_usage_quota

    Attributes:

    last_poll
    
  • voucher_rate_max_up

    Attributes:

    last_poll
    
  • voucher_rate_max_down

    Attributes:

    last_poll
    

Sensors

  • voucher

    Attributes:

    wlan_name, id, quota, used, duration, status, create_time, start_time, end_time, status_expires, usage_quota, rate_max_up, rate_max_down, last_poll
    

Services

  • unifi_voucher.list:

    Get a list of all valid vouchers.

  • unifi_voucher.create:

    Create a new voucher with your own parameters or the default settings of the integration.

  • unifi_voucher.delete:

    Delete a special voucher or the last created voucher.

  • unifi_voucher.update:

    Fetch data from UniFi Controller immediately.

Debugging

To enable debug logging for this integration you can control this in your Home Assistant configuration.yaml file.

Set the logging to debug with the following settings in case of problems:

logger:
  default: warn
  logs:
    aiounifi: debug
    custom_components.unifi_voucher: debug

After a restart detailed log entries will appear in /config/home-assistant.log.


ha-unifi-voucher's People

Contributors

dependabot[bot] avatar ufozone avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

ha-unifi-voucher's Issues

Error connecting to Unifi network application

Tried everything I could think of here and I still cant get the hotspot integration to connect to my network controller

Facts:

  • I have a UDM-SE and the wifi service account has full permissions on the unifi application. (Figure 1)
  • The host is reachable, and no firewall fules are blocking access to the UDM from my trusted server network. I can tell this because unifi shows the last login date as 1 minute ago. (Figure 2)
  • I am running the latest version 1.2.1.
  • I am running these versions of hass and hass OS
  • I am running hass behind Nginx Proxy Manager but have tried this without using NPM
Core 2024.5.4
Supervisor 2024.05.1
Operating System 12.3.rc2
Frontend 20240501.1
  • I get the following error on my screen and the following text in the logs:
    image
Logger: custom_components.unifi_voucher
Source: custom_components/unifi_voucher/api.py:142
integration: unifi_voucher ([documentation](https://github.com/ufozone/ha-unifi-voucher), [issues](https://github.com/ufozone/ha-unifi-voucher/issues))
First occurred: 10:42:25 PM (4 occurrences)
Last logged: 10:45:50 PM

    Error connecting to the UniFi Network at 10.3.1.1:
    Error connecting to the UniFi Network at 10.3.1.1: Error requesting data from https://10.3.1.1:443: Cannot connect to host 10.3.1.1:443 ssl:True [SSLCertVerificationError: (1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self-signed certificate (_ssl.c:1000)')]

In the hass config/home-assistant.log, I am getting 401 errors when trying to access the API path '/proxy/network/sites' after relieving the full correct payload with a token from /API/auth/login and getting a Logged in to UniFi https://someurlhere message in the log file. I also seem to be getting hit with 403 and 429 errors despite only trying this once every 3-10 ish minutes.

I am not sure what else to try, any clarification would be helpful. Will update as I learn more.

Unsupported event key EVT_AD_VoucherCreated

I get the following warnings in the log when using voucher integration:

2024-05-05 21:14:26.557 WARNING (MainThread) [aiounifi.models.event] Unsupported event key EVT_AD_VoucherCreated
2024-05-05 21:14:26.557 WARNING (MainThread) [aiounifi.models.event] Unsupported event {'num': '1', 'use': 'single-use', 'admin': 'Admin[Admin  ]', 'site_id': '5a32aa4ee4b0412345678910', 'is_admin': True, 'key': 'EVT_AD_VoucherCreated', 'subsystem': 'wlan', 'is_negative': False, 'time': 1714936463552, 'datetime': '2024-05-05T19:14:23Z', 'msg': 'Admin[Admin  ] created 1 single-use voucher(s)', '_id': '6637da8ff30c710b60b18251'}
2024-05-05 21:16:11.559 WARNING (MainThread) [aiounifi.models.event] Unsupported event key EVT_AD_VoucherDeleted
2024-05-05 21:16:11.560 WARNING (MainThread) [aiounifi.models.event] Unsupported event {'code': '9668964319', 'admin': 'Admin[Admin  ]', 'site_id': '5a32aa4ee4b0412345678910', 'is_admin': True, 'key': 'EVT_AD_VoucherDeleted', 'subsystem': 'wlan', 'is_negative': False, 'time': 1714936570825, 'datetime': '2024-05-05T19:16:10Z', 'msg': 'Voucher[9668964319] was deleted', '_id': '6637dafaf30c710b60b182b6'}

AttributeError: 'UnifiVoucherButton' object has no attribute 'self'

Hey,
First of all: Thanks for the good work. Its great to have the integration in HA.
Unfortunatly after the last update of HA, I experience the following error:

AttributeError: 'UnifiVoucherButton' object has no attribute 'self'

2024-02-08 09:32:00.756 DEBUG (MainThread) [custom_components.unifi_voucher] Finished fetching unifi_voucher data in 0.036 seconds (success: True) 2024-02-08 09:32:00.762 ERROR (MainThread) [homeassistant.components.button] Error while setting up unifi_voucher platform for button Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 344, in _async_setup_platform await asyncio.shield(task) File "/config/custom_components/unifi_voucher/button.py", line 71, in async_setup_entry UnifiVoucherButton( File "/config/custom_components/unifi_voucher/button.py", line 90, in __init__ super().__init__( File "/config/custom_components/unifi_voucher/entity.py", line 48, in __init__ configuration_url=self.self.coordinator.get_configuration_url(), ^^^^^^^^^ AttributeError: 'UnifiVoucherButton' object has no attribute 'self' 2024-02-08 09:32:00.773 ERROR (MainThread) [homeassistant.components.image] Error while setting up unifi_voucher platform for image Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 344, in _async_setup_platform await asyncio.shield(task) File "/config/custom_components/unifi_voucher/image.py", line 50, in async_setup_entry UnifiVoucherImage( File "/config/custom_components/unifi_voucher/image.py", line 75, in __init__ super().__init__( File "/config/custom_components/unifi_voucher/entity.py", line 48, in __init__ configuration_url=self.self.coordinator.get_configuration_url(), ^^^^^^^^^ AttributeError: 'UnifiVoucherImage' object has no attribute 'self' 2024-02-08 09:32:00.783 ERROR (MainThread) [homeassistant.components.number] Error while setting up unifi_voucher platform for number Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 344, in _async_setup_platform await asyncio.shield(task) File "/config/custom_components/unifi_voucher/number.py", line 56, in async_setup_entry UnifiVoucherNumber( File "/config/custom_components/unifi_voucher/number.py", line 77, in __init__ super().__init__( File "/config/custom_components/unifi_voucher/entity.py", line 48, in __init__ configuration_url=self.self.coordinator.get_configuration_url(), ^^^^^^^^^ AttributeError: 'UnifiVoucherNumber' object has no attribute 'self' 2024-02-08 09:32:00.791 ERROR (MainThread) [homeassistant.components.sensor] Error while setting up unifi_voucher platform for sensor Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 344, in _async_setup_platform await asyncio.shield(task) File "/config/custom_components/unifi_voucher/sensor.py", line 46, in async_setup_entry UnifiVoucherSensor( File "/config/custom_components/unifi_voucher/sensor.py", line 65, in __init__ super().__init__( File "/config/custom_components/unifi_voucher/entity.py", line 48, in __init__ configuration_url=self.self.coordinator.get_configuration_url(), ^^^^^^^^^ AttributeError: 'UnifiVoucherSensor' object has no attribute 'self'

Any Idea?


I'm running a UDM Pro with UniFi OS v3.2.9
and HA Core 2024.2.0
Tried to delete and reintegrate the Hub, but still the same issue.

No issue - QR-Code with logo possible?

I've just today stumbled over your integration and it perfectly fits into my use case at home. I am able to request vouchers via signal message and get one back together with the QR-Code to connect to the WiFi. All together it was a good bit of effort but it is working. It even detects if there are no more vouchers and generatss some new ones first. All in all I am pleased and even more thankful towards you, the mastermind and genius behind this integration.

Thus said, improving the QR-Code entity with an optional logo or image would be small but tremendous improvement.

Cheers from Germany

Dunkelschunkel

AttributeError: 'UnifiVoucherConfigFlow' object has no attribute 'config'

2024-05-22 19:42:51.916 ERROR (MainThread) [aiohttp.server] Error handling request
Traceback (most recent call last):
  File "/usr/local/lib/python3.12/site-packages/aiohttp/web_protocol.py", line 452, in _handle_request
    resp = await request_handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/aiohttp/web_app.py", line 543, in _handle
    resp = await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/aiohttp/web_middlewares.py", line 114, in impl
    return await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/http/security_filter.py", line 92, in security_filter_middleware
    return await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/http/forwarded.py", line 83, in forwarded_middleware
    return await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/http/request_context.py", line 26, in request_context_middleware
    return await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/http/ban.py", line 88, in ban_middleware
    return await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/aiohttp_session/__init__.py", line 199, in factory
    response = await handler(request)
               ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/http/auth.py", line 295, in auth_middleware
    return await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/http/headers.py", line 32, in headers_middleware
    response = await handler(request)
               ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/http.py", line 73, in handle
    result = await handler(request, **request.match_info)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/http/decorators.py", line 71, in with_admin
    return await func(self, request, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/config/config_entries.py", line 222, in post
    return await super().post(request, flow_id)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/http/data_validator.py", line 73, in wrapper
    return await method(view, request, data, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/data_entry_flow.py", line 122, in post
    result = await self._flow_mgr.async_configure(flow_id, data)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 356, in async_configure
    result = await self._async_configure(flow_id, user_input)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 402, in _async_configure
    result = await self._async_handle_step(
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 506, in _async_handle_step
    result: _FlowResultT = await getattr(flow, method)(user_input)
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/unifi_voucher/config_flow.py", line 128, in async_step_user
    return await self.async_step_site()
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/unifi_voucher/config_flow.py", line 231, in async_step_site
    return await self.async_step_site(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/unifi_voucher/config_flow.py", line 210, in async_step_site
    config_entry, data=self.config
                       ^^^^^^^^^^^
AttributeError: 'UnifiVoucherConfigFlow' object has no attribute 'config'

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.