Hey,
Bit of a late reply but I have a different solution I just came up with today that makes use of oneshot
mechanics and simple curl to check if unifi service is available
Create the following /etc/systemd/system/hass-pre.service
file (or similar)
[Unit]
Description=Home Assistant helper for UniFi
After=network-online.target unifi.service
Wants=unifi.service
[Service]
Type=oneshot
User=%i
# Enable the following line if you get network-related HA errors during boot
#ExecStartPre=/usr/bin/sleep 60
# Use `whereis hass` to determine the path of hass
ExecStart=/bin/bash -c 'while true; do curl -ksI -m 5 https://0:8443/manage/account/login?redirect=%2Fmanage | grep "200 OK" > /dev/null; if [ $$? == 0 ]; then break; fi; sleep 5; done;'
RemainAfterExit=yes
Then add hass-pre.service
to your After=
and Wants=
inside the main homeassistant systemd file.
Oneshot makes this call block dependent services (hass) until it’s done with the script and RemainAfterExit makes it remain active after the script is done.
So the fake “service” will appear as activating as long as the script is in the loop and will be “activated” when it exits.
Adjust values accordingly. That one-liner simply queries a known URL that responds with “200 OK” header every 5s until it gets the correct response. I’ve tested and it works fine 
Let me know!
EDIT: If you’re not running unifi.service
in the same environment, you can remove it from Wants=
and After=
and just rely on curl
result
EDIT2: For good measure also add -m 5 to curl parameters so it doesn’t wait too long for each response