UPDATED: Automating Unifi WiFi SSID password changes and QR code generation

For me its 50/50, I’m learning and having fun and at the same time users benefit and feedback.

got it. thanks for the info i’ll mess around with it and see how it goes! your code is still essential for the automating of changing the guest password so it’s much appreciated.

@Robban is there a way to access the png(or jpg) of the qr from the integration so it can be displayed however we want?

1 Like

I can’t get this custom component to work. I get error in log and don’t know how to find out what is wrong.

Logger: custom_components.unifi_wifi.coordinator
Source: helpers/update_coordinator.py:353
Integration: Unifi Wifi (documentation, issues)
First occurred: 10:52:00 (1 occurrences)
Last logged: 10:52:00

Authentication failed while fetching klubben319 data: {'meta': {'rc': 'error', 'msg': 'api.err.LoginRequired'}, 'data': []}

Posted here as well:

No idea what that is, but it’s not related at all to the topic of this thread.

Please do. I was digging through your integration for this kind of functionality when I came upon this.

EDIT: I did more reading, found out that the Home Assistant user for Unifi must have admin privileges to enable the QR code - not set as view only. That was the modification I had to make to my system to get it to show up.


Can anyone point me in the direction of how to implement this in the Unifi network integration? I can’t seem to find and documentation that really covers implementing the QR code, nor form looking around through the integration either.

If you mean the QR Code for the Wifi Password it’s a disabled image entity, which you first need to enable in the Unifi Integration menu.

Has anybody figured out an easy way to get the password from that QR Code and display it in a helper entity?

What i want to achive is a Wifi Guest Card on my Dashboard displaying the QR Code (-> image entity) + in clear text the wifi password if the QR Code is not working.

Currently i’m doing this with a shell_command, which is triggered after the last Guest is disconnecting and the regenerate password flow is initiated.
But i don’t know if there is an easier approach

shell_command:

#!/bin/sh
TOKEN=
SAVEDIR=/config/www/pictures/camera
FILENAME=guest-qr.jpg
PW=guest-pw.txt


# GET QR Code as JPG
curl -X GET https://hass.local/api/image_proxy/image.qr_code -H "Authorization: Bearer $TOKEN" --output $SAVEDIR/$FILENAME
sleep 2
# Decode QR Code and extract PW
zbarimg $SAVEDIR/$FILENAME | awk -F ":" '{print $6}' | sed 's/;//g' >> $SAVEDIR/$PW
WIFIPW=$(cat $SAVEDIR/$PW)

generate_post_data()
{
        cat <<EOF
{
        "entity_id": "input_text.guest_password",
        "value": "$WIFIPW"
}
EOF
}
# POST to push PW to HASS Service
curl -X POST https://hass.local/api/services/input_text/set_value -H "Authorization: Bearer $TOKEN" -H "Content-Type: application/json" -d "$(generate_post_data)"

# CleanUp
rm -rf $SAVEDIR/$FILENAME
rm -rf $SAVEDIR/$PW

Automation:

alias: Refresh Wifi Guest Password
description: ""
trigger:
  - platform: numeric_state
    entity_id:
      - sensor.gast
    for:
      hours: 0
      minutes: 15
      seconds: 0
    below: 1
condition: []
action:
  - service: button.press
    target:
      entity_id: button.gast_regenerate_password
    data: {}
  - delay:
      hours: 0
      minutes: 0
      seconds: 30
      milliseconds: 0
  - service: shell_command.guest_qr_decode
    data: {}
mode: single