Navigation

    Logo
    • Register
    • Login
    • Search
    • Recent
    • Tags
    • Unread
    • Categories
    • Unreplied
    • Popular
    • GitHub
    • Docu
    • Hilfe
    1. Home
    2. Deutsch
    3. Skripten / Logik
    4. JavaScript
    5. Wie nutze ich eine custom class / npm Modul?

    NEWS

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

    • ioBroker goes Matter ... Matter Adapter in Stable

    • Monatsrückblick - April 2025

    Wie nutze ich eine custom class / npm Modul?

    This topic has been deleted. Only users with topic management privileges can see it.
    • D
      disaster123 last edited by

      Hallo,

      ich versuche verzweifelt das Modul https://gitlab.com/wizlighting/wiz-local-control/-/tree/master zum laufen zu bekommen. Im Javascript Adapter habe ich bereits wiz-local-control als npm Modul eingetragen und er hat auch wiz-local-control installiert.

      Aber ich schaffe es nicht das Modul zu benutzen:

      
      var wzl = require('wiz-local-control');
      
      const wizLocalControl = new WiZLocalControl();
          
      

      Fehlermeldung:

      script.js.common.Test: ReferenceError: WiZLocalControl is not defined
      

      Wo ist mein Fehler 😞

      Danke!

      Grüße,
      Stefan

      Jey Cee 1 Reply Last reply Reply Quote 0
      • Jey Cee
        Jey Cee Developer @disaster123 last edited by

        @disaster123

        wzl !== WiZLocalControl
        

        Du weist den Export vom Modul der Variable wzl zu und versuchst ihn dann mit WiZLocalControl auf zu rufen. Das kann nicht funktionieren.

        D 1 Reply Last reply Reply Quote 0
        • D
          disaster123 @Jey Cee last edited by

          @jey-cee
          Danke, das hatte ich auch schon versucht dann ist das Ergebnis so:

          var WiZLocalControl = require('wiz-local-control');
          
          const wizLocalControl = new WiZLocalControl();
              
          
          script.js.common.Test: TypeError: WiZLocalControl is not a constructor
          

          Der Code sagt aber: https://gitlab.com/wizlighting/wiz-local-control/-/blob/master/src/index.ts#L23

          Jey Cee 1 Reply Last reply Reply Quote 0
          • Jey Cee
            Jey Cee Developer @disaster123 last edited by

            var WiZLocalControl = require('wiz-local-control').default;
            

            So sollte das dann klappen. Die Funktion wird als default Exportiert, das muss man dann Explizit angeben.

            D 1 Reply Last reply Reply Quote 0
            • D
              disaster123 @Jey Cee last edited by

              @jey-cee DANKE!!! LÄuft!

              maeb3 1 Reply Last reply Reply Quote 0
              • maeb3
                maeb3 @disaster123 last edited by

                @disaster123 Hi, ich habe auch vor einiger Zeit versucht, meine WIZ Lampe (Brilliant) mit Hilfe von wiz-local-control in iobroker zu integrieren (erst mal nur per Script). Das Auslesen der diversen Status von der WIZ Lampe klappt bei mir soweit ganz gut, aber mit dem Steuern bin ich noch nicht wirklich weitergekommen (hatte zu wenig Zeit). Trotzdem: vielleicht nützt dir ja das ein oder andere aus meinem bisherigen Script:

                ...
                    const DP_State = '0_userdata.0.Licht.WIZ.STATE';
                    const DP_Scene = '0_userdata.0.Licht.WIZ.sceneId';
                    const DP_Dimming = '0_userdata.0.Licht.WIZ.dimming';
                    const DP_MAC = '0_userdata.0.Licht.WIZ.MAC';
                    const DP_Firmware = '0_userdata.0.Licht.WIZ.firmware';
                    const DP_RSSI = '0_userdata.0.Licht.WIZ.rssi';
                    const DP_Available = '0_userdata.0.Licht.WIZ.available';
                    const DP_LastContact = '0_userdata.0.Licht.WIZ.LastContact';
                 ...
                const WiZLocalControl = require("wiz-local-control").default;
                const detectedDevices = new Set();
                const wizLocalControl = new WiZLocalControl({
                    incomingMsgCallback: (msg, ip) => {
                        log("New WiZ message: " + JSON.stringify(msg)); // for debugging only
                        if(msg.method == "syncPilot"){
                            if (!detectedDevices.has(ip)) {
                                detectedDevices.add(ip);
                                if(logging){log("New WiZ Light detected: " + ip);}
                            }
                //            setState(DP_LastContact, msg.timestamp);
                            setState(DP_MAC, msg.params.mac);
                            setState(DP_RSSI, msg.params.rssi);
                            setState(DP_State, msg.params.state);
                            setState(DP_Dimming, msg.params.dimming);
                            setState(DP_Scene, msg.params.sceneId);
                        }
                        if(msg.method == "firstBeat"){
                            setState(DP_Firmware, msg.params.fwVersion);
                        }
                        if(msg.method != "firstBeat" && msg.method != "syncPilot"){log("New method: " + msg.method);}
                    },
                    interfaceName: "eth0"
                });
                
                wizLocalControl.startListening();
                
                // Steuerung: 
                //  wizLocalControl.changeStatus(false, "10.251.10.192"));
                //  wizLocalControl.changeLightMode({type: "scene",sceneId: 1}, "10.251.10.192");
                //  wizLocalControl.changeLightMode({type: "temperature",colorTemperature: 4000}, "10.251.10.192"))
                //  wizLocalControl.changeBrightness(10, "10.251.10.192"));
                //  wizLocalControl.changeStatus(true, "10.251.10.192"));
                //  wizLocalControl.changeSpeed(140, "10.251.10.192"));
                
                
                /*
                6: "Cozy"  (Gemütlich)
                9: "Wake up"  (Aufwachen)
                10: "Bedtime"  (Schlafenszeit)
                11: "Warm White"  (Warmweiss)
                12: "Daylight"  (Tageslicht)
                13: "Cool white"  (Kaltweiss)
                14: "Night light"  (Nachtlicht)
                15: "Focus"  (Fokus)
                16: "Relax"  (Entspannen)
                18: "TV time"
                29: "Candlelight"
                30: "Golden white"
                31: "Pulse"
                32: "Steampunk"
                TW_SCENES = [6, 9, 10, 11, 12, 13, 14, 15, 16, 18, 29, 30, 31, 32]
                */
                ...
                

                Falls du hier zu weiteren Erkenntnissen kommst (oder schon gekommen bist), wäre ich sehr daran interessiert. Vielleicht mache ich mich bei Gelegenheit auch nochmal auf, noch die Steuerung der WIZ Lampe mit in das Script einzubauen.

                Grüße,
                maeb3

                1 Reply Last reply Reply Quote 0
                • D
                  disaster123 last edited by

                  Biete sonst mein Modul ;-):

                  https://github.com/disaster123/ioBroker.wizconnect

                  K 1 Reply Last reply Reply Quote 1
                  • K
                    Kentrath @disaster123 last edited by

                    @disaster123
                    Das hört sich spannend an. Ich warte schon lange auf eine WIZ Lösung für unseren ioBroker. Wie kann ich das ausprobieren? Bei mir liefert npm install iobroker.wizconnect leider eine Fehlermeldung. Kannst Du mir als Newbie ein wenig auf die Sprünge helfen? Vielen Dank

                    Thomas Braun 1 Reply Last reply Reply Quote 0
                    • Thomas Braun
                      Thomas Braun Most Active @Kentrath last edited by

                      @kentrath sagte in Wie nutze ich eine custom class / npm Modul?:

                      leider eine Fehlermeldung

                      Welche?
                      Gitub-Installationen am besten über die 'Octocat' machen und nicht per npm direkt.

                      K 1 Reply Last reply Reply Quote 0
                      • K
                        Kentrath @Thomas Braun last edited by

                        @thomas-braun
                        root@IoBroker:/opt/iobroker# npm install iobroker.wizconnect
                        npm ERR! code E404
                        npm ERR! 404 Not Found - GET https://registry.npmjs.org/iobroker.wizconnect - Not found
                        npm ERR! 404
                        npm ERR! 404 'iobroker.wizconnect@*' is not in this registry.
                        npm ERR! 404
                        npm ERR! 404 Note that you can also install from a
                        npm ERR! 404 tarball, folder, http url, or git url.

                        Thomas Braun 1 Reply Last reply Reply Quote 0
                        • Thomas Braun
                          Thomas Braun Most Active @Kentrath last edited by

                          @kentrath

                          NICHT als root herumhampeln.

                          Das Modul ist offenbar nicht in der npm-Registry eingetragen.
                          Mach es am besten 'über die Katze' und da die URL entsprechend reinkopieren.

                          K 1 Reply Last reply Reply Quote 0
                          • K
                            Kentrath @Thomas Braun last edited by

                            @thomas-braun

                            "Über die Katze" hat es geklappt 🙂
                            Das Thema root steht auf meiner Agenda. Dein Artikel zu Node hatte mir auch schon sehr weiter geholfen. Hast Du vielleicht auch einen guten Guide für das richtige Anwenden von Nutzern. Bisher habe ich mich da nich ran getraut, weil es halt mit root alles funktioniert. Optimal ist das natürlich nicht 😕

                            Thomas Braun 1 Reply Last reply Reply Quote 0
                            • Thomas Braun
                              Thomas Braun Most Active @Kentrath last edited by

                              @kentrath sagte in Wie nutze ich eine custom class / npm Modul?:

                              weil es halt mit root alles funktioniert.

                              Damit funktioniert es besonders gut sein System zu verfummeln, stimmt.
                              Was haste denn da genau am Start?
                              Anlegen von usern ist so ein grundlegender Task, das findet sich in jeder Anleitung zu deinem Betriebssystem.

                              K 1 Reply Last reply Reply Quote 0
                              • K
                                Kentrath last edited by

                                @disaster123
                                Im System konnte ich eine Instanz anlegen, bekomme sie aber nicht "grün".
                                Was muss ich denn in den einzelnen Feldern der Haupteinstellungen einstellen? Bind IP? udp target? Haken bei register devices?
                                Vielen Dank

                                D 1 Reply Last reply Reply Quote 0
                                • K
                                  Kentrath @Thomas Braun last edited by

                                  @thomas-braun
                                  Eine Debian VM in einem Proxmox

                                  Thomas Braun 1 Reply Last reply Reply Quote 0
                                  • Thomas Braun
                                    Thomas Braun Most Active @Kentrath last edited by Thomas Braun

                                    @kentrath

                                    Beim Debian-Installer wird das direkt schon richtig gemacht, wenn man bei der Anlage KEIN Passwort für den root vergibt.

                                    Nachträglich einen user mit passenden Rechten anlegen:

                                    https://phoenixnap.com/kb/create-a-sudo-user-on-debian

                                    Künftig nicht mehr als root einloggen sondern mit dem neuen user herumhüpfen.

                                    1 Reply Last reply Reply Quote 1
                                    • D
                                      disaster123 @Kentrath last edited by

                                      @kentrath sagte in Wie nutze ich eine custom class / npm Modul?:

                                      @disaster123
                                      Im System konnte ich eine Instanz anlegen, bekomme sie aber nicht "grün".
                                      Was muss ich denn in den einzelnen Feldern der Haupteinstellungen einstellen? Bind IP? udp target? Haken bei register devices?
                                      Vielen Dank

                                      Bind IP: die IP an die er sich zum Empfangen der Pakete binden soll - meistens kann man hier einfach 0.0.0.0 nutzen

                                      Bei Docker zum Beispiel braucht man die die UDP Pakete andere target IPs und Macs als iobroker eigentlich hat. Dafür sind die Felder:

                                      • udp target ip for auto update
                                      • udp mac adress for auto update

                                      Wenn man kein Docker nutzt, kommen da einfach die IP und MAC der iobroker Instanz rein.

                                      Bzgl. nicht grün müsstest du mal dein Log posten.

                                      D 1 Reply Last reply Reply Quote 1
                                      • D
                                        disaster123 @disaster123 last edited by

                                        @disaster123 sagte in Wie nutze ich eine custom class / npm Modul?:

                                        @kentrath sagte in Wie nutze ich eine custom class / npm Modul?:

                                        @disaster123
                                        Im System konnte ich eine Instanz anlegen, bekomme sie aber nicht "grün".
                                        Was muss ich denn in den einzelnen Feldern der Haupteinstellungen einstellen? Bind IP? udp target? Haken bei register devices?
                                        Vielen Dank

                                        Bind IP: die IP an die er sich zum Empfangen der Pakete binden soll - meistens kann man hier einfach 0.0.0.0 nutzen

                                        Bei Docker zum Beispiel braucht man die die UDP Pakete andere target IPs und Macs als iobroker eigentlich hat. Dafür sind die Felder:

                                        • udp target ip for auto update
                                        • udp mac adress for auto update

                                        Wenn man kein Docker nutzt, kommen da einfach die IP und MAC der iobroker Instanz rein.

                                        Genau.

                                        Bzgl. nicht grün müsstest du mal dein Log posten.

                                        Log hängt bisher nicht an.

                                        1 Reply Last reply Reply Quote 0
                                        • K
                                          Kentrath last edited by

                                          @disaster123

                                          TypeError: Cannot read properties of undefined (reading '0') at new Wizconnect (/opt/iobroker/node_modules/iobroker.wizconnect/main.js:44:44) at Object.<anonymous> (/opt/iobroker/node_modules/iobroker.wizconnect/main.js:666:2) at Module._compile (node:internal/modules/cjs/loader:1165:14) at Object.Module._extensions..js (node:internal/modules/cjs/loader:1219:10) at Module.load (node:internal/modules/cjs/loader:1043:32) at Function.Module._load (node:internal/modules/cjs/loader:878:12) at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12) at node:internal/main/run_main_module:22:47
                                          
                                          1 Reply Last reply Reply Quote 0
                                          • D
                                            disaster123 last edited by

                                            @kentrath sagte in Wie nutze ich eine custom class / npm Modul?:

                                            @disaster123

                                            TypeError: Cannot read properties of undefined (reading '0') at new Wizconnect (/opt/iobroker/node_modules/iobroker.wizconnect/main.js:44:44) at Object.<anonymous> (/opt/iobroker/node_modules/iobroker.wizconnect/main.js:666:2) at Module._compile (node:internal/modules/cjs/loader:1165:14) at Object.Module._extensions..js (node:internal/modules/cjs/loader:1219:10) at Module.load (node:internal/modules/cjs/loader:1043:32) at Function.Module._load (node:internal/modules/cjs/loader:878:12) at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12) at node:internal/main/run_main_module:22:47
                                            

                                            Ich habe das Modul leider recht Buggy im Netz gefunden und habe es nur angepasst. Das ursprüngliche Modul erwartet eine Netzwerkkarte unter Linux mit dem Namen eth0.

                                            Ich habe das mal ausgebaut. Bitte neu via github / katze installieren.

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

                                            Support us

                                            ioBroker
                                            Community Adapters
                                            Donate

                                            978
                                            Online

                                            31.7k
                                            Users

                                            79.6k
                                            Topics

                                            1.3m
                                            Posts

                                            7
                                            65
                                            3600
                                            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