Navigation

    Logo
    • Register
    • Login
    • Search
    • Recent
    • Tags
    • Unread
    • Categories
    • Unreplied
    • Popular
    • GitHub
    • Docu
    • Hilfe
    1. Home
    2. Deutsch
    3. ioBroker Allgemein
    4. Adapter: ioBroker.unifi

    NEWS

    • ioBroker@Smart Living Forum Solingen, 14.06. - Agenda added

    • ioBroker goes Matter ... Matter Adapter in Stable

    • Monatsrückblick - April 2025

    Adapter: ioBroker.unifi

    This topic has been deleted. Only users with topic management privileges can see it.
    • liv-in-sky
      liv-in-sky @dslraser last edited by

      @dslraser
      mir ist der umfang der daten auch zu groß - teste gerade nodered unifi node - dort gibt es DisableWlan als befehl - getestet habe ich das noch nicht

      Image 7.png

      1 Reply Last reply Reply Quote 1
      • liv-in-sky
        liv-in-sky @dslraser last edited by

        @dslraser

        hab noch was gefunden und positiv getestet - ist ein linux-bash-script

        https://community.openhab.org/t/solved-exec-commandline-bash-script-unifi-via-rule/66136/7

        #!/bin/bash
        
        unifi_username=user
        unifi_password='pass'
        unifi_controller=https://192.168.x.xx:xxxx
        wifi_id=dsa4fsda6g46fdsg984
        cookie=/tmp/cookie
        
        #site_id=""             // deprecated
        
        curl_cmd="curl -s -S --cookie ${cookie} --cookie-jar ${cookie} --insecure "
        
        unifi_login() {
         # authenticate against unifi controller
         # Mute response by adding > /dev/null
         ${curl_cmd} -H "Content-Type: application/json" -X POST -d "{\"password\":\"$unifi_password\",\"username\":\"$unifi_username\"}" $unifi_controller/api/login #> /dev/null
        }
        
        unifi_logout() {
         # logout
         ${curl_cmd} $unifi_controller/logout
        }
        
        enable_wifi() {
         # enables guest wifi network
         # Mute response by adding > /dev/null
         ${curl_cmd} "$unifi_controller"'/api/s/default/rest/wlanconf/'"$wifi_id" -X PUT --data-binary '{"_id":"'$site_id'","enabled":true}' --compressed #> /dev/null
        }
        
        disable_wifi() {
         # enables guest wifi network
         # Mute response by adding > /dev/null
         ${curl_cmd} "$unifi_controller"'/api/s/default/rest/wlanconf/'"$wifi_id" -X PUT --data-binary '{"_id":"'$site_id'","enabled":false}' --compressed #> /dev/null
        }
        
        check_status() {
         # checks wifi network status
         # Mute response by adding > /dev/null
         response=$(${curl_cmd} "$unifi_controller"'/api/s/default/rest/wlanconf/'"$wifi_id" --compressed)
         status=$(echo $response | jq ".data[0].enabled")
         if [ "$status" == "true" ]; then
         exit 0
         elif [ "$status" == "false" ]; then
         exit 1
         else
         echo exit -1
         fi
        }
        
        unifi_login
        if [ "$1" == "enable" ]; then
         echo "Enabling WiFi."
         enable_wifi
        elif [ "$1" == "disable" ]; then
         echo "Disabling WiFi."
         disable_wifi
        elif [ "$1" == "status" ]; then
         check_status
        else
         echo "Must include command line parameter [enable|disable|status]."
        fi
        unifi_logout
        rm $cookie
        
        

        mit diesem script kann ich mein wlan ein und ausschalten ode den status abfragen

        • es muss "apt-get install jq" ausgeführt werden (nur nötig, wenn man status will) (damit es bei mir funktionierte, mußte ich den jq pfad im script bei dem jq befehle angeben (unter bereich status)) - die wifi_id findet man so:

        Getting your wifi_id:
        Navigate to your controller and sign in.
        Navigate to Settings > Wifi Networks.
        Click Edit next to the SSID you’d like to control.
        Copy the ID from the end of the URL.
        In the following example, the ID is ( 000d00c0e0b0e00d00000000 😞
        url://example:8443/manage/site/default/settings/wlans/00bd00a6e0000e9da2cde10c/edit/000d00c0e0b0e00d00000000

        dslraser 3 Replies Last reply Reply Quote 1
        • dslraser
          dslraser Forum Testing Most Active @liv-in-sky last edited by

          @liv-in-sky
          Danke Dir.

          1 Reply Last reply Reply Quote 0
          • dslraser
            dslraser Forum Testing Most Active @liv-in-sky last edited by

            @liv-in-sky

            ich habe noch nichts ausprobiert...
            (ich hatte bisher nur angefangen zu suchen und wollte mir von diesem Post was ableiten, ist zwar nicht für unifi aber eben für ssh.)
            Das hier meine ich

            Ich bin sonst fast nur mit Blockly unterwegs, aber vielleicht lässt sich Dein Bash auch in eine Blockly Funktion packen.
            Ich bin noch unterwegs, aber ich schaue es mir später genauer an.

            1 Reply Last reply Reply Quote 0
            • dslraser
              dslraser Forum Testing Most Active @liv-in-sky last edited by

              @liv-in-sky sagte in Adapter: ioBroker.unifi:

              hab noch was gefunden und positiv getestet - ist ein linux-bash-script

              Hi, kann man das auch in ein normal Script oder Blockly umwandeln ?
              Oder wo/wie wendest Du das linux-bash-script an ?

              Ich würde es gern in z.B iQontrol nutzen.

              z.B. Gäste WLAN an oder Gäste WLAN aus

              liv-in-sky 1 Reply Last reply Reply Quote 0
              • liv-in-sky
                liv-in-sky @dslraser last edited by

                @dslraser

                wenn du das linux script erzeugst auf einer console :

                • am besten im /opt/iobroker - ordner - da solltest du die rechte haben
                • nano unifi.sh (dann inhalt reinkopieren) - mit "<ALT>-x speichern unter dem namen unifi.sh
                • dann "chmod +x unifi.sh" - danmit es ausführbar ist

                dann kannst du mit einem blockly und result aktiviert (variable result einfach erstellen) das script aufrufen und das result weiterverarbeiten

                Image 7.png

                Image 6.png

                dslraser 1 Reply Last reply Reply Quote 0
                • dslraser
                  dslraser Forum Testing Most Active @liv-in-sky last edited by

                  @liv-in-sky
                  Danke für Deine Geduld und Mühe.
                  Also muss ich tatsächlich erst dieses Script installieren und dann über Blockly aufrufen.
                  Ich dachte es gäbe eine Möglichkeit dies gleich mit "ioBroker Boardmitteln" zu erledigen ?

                  liv-in-sky 1 Reply Last reply Reply Quote 0
                  • liv-in-sky
                    liv-in-sky @dslraser last edited by

                    @dslraser
                    ja - ich steh auf diese linux scripts - dabei bin ich schneller als in javascript - old school halt!

                    ein richtiger profi könnte das sicher in javascript umwandeln - aber das kann ich leider nicht bieten 😞

                    ansonsten mit nodered - weiß nicht, ob du das magst

                    dslraser 1 Reply Last reply Reply Quote 0
                    • dslraser
                      dslraser Forum Testing Most Active @liv-in-sky last edited by

                      @liv-in-sky sagte in Adapter: ioBroker.unifi:

                      ansonsten mit nodered - weiß nicht, ob du das magst

                      Ich weiß nicht ob ich das mag, habe ich noch nie benutzt 😅

                      thewhobox 1 Reply Last reply Reply Quote 0
                      • thewhobox
                        thewhobox @dslraser last edited by

                        @dslraser Hab ich noch nicht getestet, sollte aber eig funktionieren.

                        const request = require('request');
                        const unifi_username = "user";
                        const unifi_password = "pass";
                        const unifi_controller = "https://192.168.x.xx:xxxx";
                        const wifi_id = "dsa4fsda6g46fdsg984";
                        
                        
                        function login() {
                            request.post({
                                    url: unifi_controller + "/api/login",
                                    body: JSON.stringify({ username: unifi_username, password: unifi_password }),
                                    headers: { 'Content-Type': 'application/json' }
                                }, (err, resp) => {
                                
                                if(!err) {
                                    console.log("Login war erfolgreich!");
                                    getStatus();
                                } else {
                                    console.log("Login Fehler! " + err);
                                }
                            })
                        }
                        
                        function getStatus() {
                            request.get(unifi_controller + "/api/s/default/rest/wlanconf/" + wifi_id, (err, resp) => {
                                if(!err) {
                                    console.log("Status erfolgreich geholt!");
                                    console.log(resp);
                                    let status = JSON.parse(resp);
                                    let wlanOn = status.data[0].enabled;
                                    console.log("WLAN ist: " + (wlanOn ? "an" : "aus"));
                                } else {
                                    console.log("Status konnte nicht geholt werden. " + err);
                                }
                            })
                        }
                        
                        login();
                        
                        dslraser liv-in-sky 3 Replies Last reply Reply Quote 1
                        • dslraser
                          dslraser Forum Testing Most Active @thewhobox last edited by

                          @thewhobox
                          danke Dir, probiere ich heute Abend mal aus. Ich sage hier Bescheid ob es funktioniert.

                          1 Reply Last reply Reply Quote 0
                          • liv-in-sky
                            liv-in-sky @thewhobox last edited by

                            @thewhobox hi,

                            bekomme das zurück

                            unifiWLAN: Login Fehler! Error: self signed certificate
                            
                            thewhobox 1 Reply Last reply Reply Quote 0
                            • dslraser
                              dslraser Forum Testing Most Active @thewhobox last edited by

                              @thewhobox

                              habe es doch schnell probiert, gleicher Fehler wie @liv-in-sky

                              Login Fehler! Error: self signed certificate
                              
                              1 Reply Last reply Reply Quote 0
                              • thewhobox
                                thewhobox @liv-in-sky last edited by thewhobox

                                @liv-in-sky @dslraser dann probiert mal in der ersten zeile

                                const request = require('request').defaults({ rejectUnauthorized: false });
                                
                                dslraser liv-in-sky 4 Replies Last reply Reply Quote 0
                                • dslraser
                                  dslraser Forum Testing Most Active @thewhobox last edited by

                                  @thewhobox sagte in Adapter: ioBroker.unifi:

                                  const request = require('request').defaults({ rejectUnauthorized: false });

                                  18:10:40.222	error	javascript.0 script.js.Heiko.04Telegram.Unifi: SyntaxError: Unexpected token o in JSON at position 1
                                  18:10:40.222	error	javascript.0 at Request.request.get [as _callback] (script.js.Heiko.04Telegram.Unifi:29:31)
                                  
                                  1 Reply Last reply Reply Quote 0
                                  • liv-in-sky
                                    liv-in-sky @thewhobox last edited by

                                    @thewhobox

                                    Image 4.png

                                    1 Reply Last reply Reply Quote 0
                                    • dslraser
                                      dslraser Forum Testing Most Active @thewhobox last edited by

                                      @thewhobox

                                      javascript.0	2019-08-26 18:12:12.553	error	at endReadableNT (_stream_readable.js:1145:12)
                                      javascript.0	2019-08-26 18:12:12.553	error	at IncomingMessage.emit (events.js:203:15)
                                      javascript.0	2019-08-26 18:12:12.553	error	at Object.onceWrapper (events.js:286:20)
                                      javascript.0	2019-08-26 18:12:12.553	error	at IncomingMessage.<anonymous> (/opt/iobroker/node_modules/iobroker.javascript/node_modules/request/request.js:1083:12)
                                      javascript.0	2019-08-26 18:12:12.553	error	at Request.emit (events.js:198:13)
                                      javascript.0	2019-08-26 18:12:12.553	error	at Request.<anonymous> (/opt/iobroker/node_modules/iobroker.javascript/node_modules/request/request.js:1161:10)
                                      javascript.0	2019-08-26 18:12:12.553	error	at Request.emit (events.js:198:13)
                                      javascript.0	2019-08-26 18:12:12.553	error	at Request.self.callback (/opt/iobroker/node_modules/iobroker.javascript/node_modules/request/request.js:185:22)
                                      javascript.0	2019-08-26 18:12:12.553	error	at Request.request.get [as _callback] (script.js.Heiko.04Telegram.Unifi:29:31)
                                      javascript.0	2019-08-26 18:12:12.553	error	at JSON.parse (<anonymous>:null:null)
                                      javascript.0	2019-08-26 18:12:12.552	error	script.js.Heiko.04Telegram.Unifi: SyntaxError: Unexpected token o in JSON at position 1
                                      javascript.0	2019-08-26 18:12:12.552	info	script.js.Heiko.04Telegram.Unifi: {'statusCode':401,'body':'{\'meta\':{\'rc\':\'error\',\'msg\':\'api.err.LoginRequired\'},\'data\':[]}','headers':{'cache-control':'private','expires':'Thu, 01 Jan 19
                                      
                                      1 Reply Last reply Reply Quote 0
                                      • liv-in-sky
                                        liv-in-sky @thewhobox last edited by

                                        @thewhobox
                                        falls nützlich: info vor fehler

                                        javascript.2 script.js.Armin_Schalter.ALLERLEI.UnifiWLAN1: {'statusCode':401,'body':'{\'meta\':{\'rc\':\'error\',\'msg\':\'api.err.LoginRequired\'},\'data\':[]}','headers':{'cache-control':'private','expires':'Thu, 01 Jan 1970 00:00:00 GMT','vary':'Origin','access-control-allow-credentials':'true','access-control-expose-headers':'Access-Control-Allow-Origin,Access-Control-Allow-Credentials','x-frame-options':'DENY','content-type':'application/json;charset=UTF-8','content-length':'63','date':'Mon, 26 Aug 2019 16:15:40 GMT','connection':'close'},'request':{'uri':{'protocol':'https:','slashes':true,'auth':null,'host':'192.168.178.157:8443','port':'8443','hostname':'192.168.178.157','hash':null,'search':null,'query':null,'pathname':'/api/s/default/rest/wlanconf/5cadxxxxxxxxxxxxd7e5381','path':'/api/s/default/rest/wlanconf/5cadxxxxxxxxxxdd7e5381','href':'https://192.168.178.157:8443/api/s/default/rest/wlanconf/5cadca8e3b6a3967dd7e5381'},'method':'GET','headers':{}}}
                                        
                                        dslraser 1 Reply Last reply Reply Quote 0
                                        • dslraser
                                          dslraser Forum Testing Most Active @liv-in-sky last edited by dslraser

                                          @liv-in-sky
                                          @thewhobox
                                          das aus aus dem Log unterm Script

                                          26.8.2019, 18:16:40.833	[info ]: javascript.0 Start javascript script.js.Heiko.Unifi.unifi_wifi
                                          26.8.2019, 18:16:40.833	[info ]: javascript.0 script.js.Heiko.Unifi.unifi_wifi: registered 0 subscriptions and 0 schedules
                                          26.8.2019, 18:16:41.126	[info ]: javascript.0 script.js.Heiko.Unifi.unifi_wifi: Login war erfolgreich!
                                          26.8.2019, 18:16:41.149	[info ]: javascript.0 script.js.Heiko.Unifi.unifi_wifi: Status erfolgreich geholt!
                                          26.8.2019, 18:16:41.149	[info ]: javascript.0 script.js.Heiko.Unifi.unifi_wifi: {'statusCode':401,'body':'{\'meta\':{\'rc\':\'error\',\'msg\':\'api.err.LoginRequired\'},\'data\':[]}','headers':{'cache-control':'private','expires':'Thu, 01 Jan 1970 00:00:00 GMT','vary':'Origin','access-control-allow-credentials':'true','access-control-expose-headers':'Access-Control-Allow-Origin,Access-Control-Allow-Credentials','x-frame-options':'DENY','content-type':'application/json;charset=UTF-8','content-length':'63','date':'Mon, 26 Aug 2019 16:16:41 GMT','connection':'close'},'request':{'uri':{'protocol':'https:','slashes':true,'auth':null,'host':'192.168.180.110:8443','port':'8443','hostname':'192.168.180.110','hash':null,'search':null,'query':null,'pathname':'/api/s/default/rest/wlanconf/5d3c5be0bc96040011365fe5','path':'/api/s/default/rest/wlanconf/5d3c5be0bc96040011365fe5','href':'https://192.168.180.110:8443/api/s/default/rest/wlanconf/5d3c5be0bc96040011365fe5'},'method':'GET','headers':{}}}
                                          26.8.2019, 18:16:41.149	[error]: javascript.0 script.js.Heiko.Unifi.unifi_wifi: SyntaxError: Unexpected token o in JSON at position 1
                                          26.8.2019, 18:16:41.149	[error]: javascript.0     at Request.request.get [as _callback] (script.js.Heiko.Unifi.unifi_wifi:29:31)
                                          
                                          thewhobox 2 Replies Last reply Reply Quote 0
                                          • thewhobox
                                            thewhobox @dslraser last edited by

                                            @dslraser Okay, dann speichert er leider den Login cookie nicht automatisch. Muss ich mir heute Abend nochmal anschauen

                                            1 Reply Last reply Reply Quote 0
                                            • First post
                                              Last post

                                            Support us

                                            ioBroker
                                            Community Adapters
                                            Donate
                                            FAQ Cloud / IOT
                                            HowTo: Node.js-Update
                                            HowTo: Backup/Restore
                                            Downloads
                                            BLOG

                                            509
                                            Online

                                            31.6k
                                            Users

                                            79.6k
                                            Topics

                                            1.3m
                                            Posts

                                            unifi
                                            170
                                            991
                                            283862
                                            Loading More Posts
                                            • Oldest to Newest
                                            • Newest to Oldest
                                            • Most Votes
                                            Reply
                                            • Reply as topic
                                            Log in to reply
                                            Community
                                            Impressum | Datenschutz-Bestimmungen | Nutzungsbedingungen
                                            The ioBroker Community 2014-2023
                                            logo