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

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
1 Like