Code Monkey home page Code Monkey logo

ubios-poe_switch's Introduction

UniFi switches on UDM (Pro): Turn PoE on or off via REST-API

A small python script to switch PoE power of an UniFi switch, controlled by a UDM (Pro), on or off.

Handy if you want automate the (de-)activation of cameras or WLAN Access Points. Can easily be integrated in projects like openHAB or Home Assistant, including control by Apple HomeKit or Google Alexa.

Usage

usage: poe_switch.py [-h] [-v] controller username password mac ports state

Change the PoE Mode of UniFi switches controlled by a UDM (Pro).

positional arguments:
  controller     hostname or IP address of UniFi Controller
  username       username with admin rights on UniFi Controller
  password       corresponding password for admin user
  mac            MAC address (with or without colons) of switch
  ports          port numbers to acquire new state (list separated by comma,
                 e.g., '5,6,7')
  state          desired state of PoE ports, e.g., 'auto' or 'off'

optional arguments:
  -h, --help     show this help message and exit
  -v, --verbose  increase output verbosity

python3 poe_switch.py udm.example.org IamAdmin P4ssword fcec12345678 6,7 auto will turn on the PoE (in mode auto) for ports 6 and 7 of the UniFi PoE switch with MAC address fc:ec:12:34:56:78.

Main challenge

Getting the authentication right: TOKENfrom a cookie plus a X-CSRF-Tokenfrom the header

Tested on

Firmware 1.10.0, 1.12.22 Network 6.2.26, 7.2.92

References

Thanks for the inspiration and potential sources for other people who want to go down this rabbit hole:

ubios-poe_switch's People

Contributors

alxwolf avatar oh2th avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.