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)
Description=Home Assistant helper for UniFi
# Enable the following line if you get network-related HA errors during boot
# 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;'
hass-pre.service to your
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
After= and just rely on
EDIT2: For good measure also add -m 5 to curl parameters so it doesn’t wait too long for each response