Individual WiFi SSID Scheduling

I figured I would start off with something relatively simple.  How can you toggle WiFi networks on a schedule.  Now Ubiquiti offers this scheduling function natively, however that doesn’t tie into the rest of your automations and means you have to manually change things up as schedules change.

I imagine you are asking yourself, why would I do this?  Kids are the obvious answer, shut down the WiFi at night and turn it back on in the morning.  This only works if you have a separate SSID that the kids devices connect to.  Though you can get creative with other options too which I will detail in a second post.

Alright, enough into, how does one implement this?  I’ll be using Ubiquiti hardware and Home Assistant for this example but any hub that can call a script and any WiFi system that has an API should work.

Start by setting up multiple SSIDs for your network.  VLANs are best if you can do that, but if not just different SSIDs is fine for our purposes:

Now that we have that out-of-the-way, let’s get to the fun stuff!  You will need a few key pieces of information to connect to the UniFi API:

  • Server URL
  • Site ID (In the URL when you are logged in it’s here /manage/site/xxxxxxxx/)
  • Admin user
  • Admin pass
  • UniFi version (Don’t think this really matters)

You also need the API wrapped found here: https://github.com/Art-of-WiFi/UniFi-API-client

After that it’s pretty straight-forward.  Grab my example files from here.  Put those and the client.php linked above in the same directory then edit the config.php file with your credentials and server IP address.

And you are done!  Call the script like so: /path/to/directory/toggle_network.php SSID true|false

You can then easily integrate this into whatever system you are using to schedule, change based on school closings/summer, create override switches, etc.

Happy automating!

-Dan

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.