Skip to content
  • Recent
  • Tags
  • 0 Unread 0
  • Categories
  • Unreplied
  • Popular
  • GitHub
  • Docu
  • Hilfe
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Logo
  1. ioBroker Community Home
  2. Deutsch
  3. Skripten / Logik
  4. Einfügen von JS-Klassen aus eigenem NPM-Modul

NEWS

  • UPDATE 31.10.: Amazon Alexa - ioBroker Skill läuft aus ?
    apollon77A
    apollon77
    48
    3
    8.0k

  • Monatsrückblick – September 2025
    BluefoxB
    Bluefox
    13
    1
    1.8k

  • Neues Video "KI im Smart Home" - ioBroker plus n8n
    BluefoxB
    Bluefox
    15
    1
    2.0k

Einfügen von JS-Klassen aus eigenem NPM-Modul

Einfügen von JS-Klassen aus eigenem NPM-Modul

Scheduled Pinned Locked Moved Skripten / Logik
51 Posts 4 Posters 5.4k Views 3 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • U uwe72

    @fastfoot

    Noch eine Nachfrage für ein blödes Beispiel:

    Möchte besipielsweise so was verwenden in meinen Scripten:

    sendTo('telegram.0', "TEST");
    

    /home/uwe72/clement/docker/my-datas/iobroker/iobrokerdata/my_scripts/buch.ts

    class Buch  {
    
        public getCurrentWeekdayAsString() : string {
            var now = new Date();
            let weekday = now.getDay();
            sendTo('telegram.0', "TEST"); // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
            return this.getWeekdayAsString(weekday);
        }
    
        private getWeekdayAsString(weekday: number) : string {
            let weekdayAsString;
            if (weekday == 1) {
                weekdayAsString = "Montag";
            } else if (weekday == 2) {
                weekdayAsString = "Dienstag";
            } else if (weekday == 3) {
                weekdayAsString = "Mittwoch";
            } else if (weekday == 4) {
                weekdayAsString = "Donnerstag";
            } else if (weekday == 5) {
                weekdayAsString = "Freitag";
            } else if (weekday == 6) {
                weekdayAsString = "Samstag";
            } else if (weekday == 7) {
                weekdayAsString = "Sonntag";
            } else if (weekday == 0) {
                weekdayAsString = "Sonntag";
            }
            return weekdayAsString;
        }  
    }
    
    module.exports = { Buch};
    

    Transpilieren:

    npx tsc buch.ts
    

    Fehlermeldung:

    root@iobroker:/opt/iobroker/my_scripts# npx tsc buch.ts
    buch.ts:2:5 - error TS2304: Cannot find name 'sendTo'.
    
          sendTo('telegram.0', "TEST");
          ~~~~~~
    
    
    Found 1 error in buch.ts
    

    Vermutlich fehlt hier ein "Import-Statement" von den ganzen "Allgemeinen-Sachen"?

    T Do not disturb
    T Do not disturb
    ticaki
    wrote on last edited by ticaki
    #32

    @uwe72

    https://github.com/ioBroker/ioBroker.javascript/blob/master/lib/javascript.d.ts

    tsconfig.json

    {
      "compileOnSave": true,
      "compilerOptions": {
        "noEmit": true,
        "allowJs": true,
        "checkJs": true,
        "module": "commonjs",
        "moduleResolution": "node",
        "esModuleInterop": true,
        "resolveJsonModule": true,
        "strict": true,
        "noImplicitAny": false,
        "target": "es2018",
        "typeRoots": [
          ".iobroker/types",
          "node_modules/@types"
        ]
      },
      "include": [
        "**/*.js",
        "**/*.ts",
        ".iobroker/types/javascript.d.ts"
      ],
      "exclude": [
        "node_modules/**"
      ]
    }
    

    Wenn du VS Code benutzt kannst du dir mit der iobrokererweiterungen, das auch angucken wie das da gelöst ist, weiß aber natürlich nicht ob das compilieren geht. Wird in vs dann aber nicht als Fehler angezeigt.

    Weather-Warnings Espresense NSPanel-Lovelace-ui Tagesschau

    Spenden

    U 1 Reply Last reply
    1
    • T ticaki

      @uwe72

      https://github.com/ioBroker/ioBroker.javascript/blob/master/lib/javascript.d.ts

      tsconfig.json

      {
        "compileOnSave": true,
        "compilerOptions": {
          "noEmit": true,
          "allowJs": true,
          "checkJs": true,
          "module": "commonjs",
          "moduleResolution": "node",
          "esModuleInterop": true,
          "resolveJsonModule": true,
          "strict": true,
          "noImplicitAny": false,
          "target": "es2018",
          "typeRoots": [
            ".iobroker/types",
            "node_modules/@types"
          ]
        },
        "include": [
          "**/*.js",
          "**/*.ts",
          ".iobroker/types/javascript.d.ts"
        ],
        "exclude": [
          "node_modules/**"
        ]
      }
      

      Wenn du VS Code benutzt kannst du dir mit der iobrokererweiterungen, das auch angucken wie das da gelöst ist, weiß aber natürlich nicht ob das compilieren geht. Wird in vs dann aber nicht als Fehler angezeigt.

      U Offline
      U Offline
      uwe72
      wrote on last edited by uwe72
      #33

      @ticaki Nun bin ich zu müde. Komme da nicht weiter, habe keine Ahnung und leider fehlen mir hier (Grund-) kenntnisse.

      {
        "compileOnSave": true,
        "compilerOptions": {
          "noEmit": true,
          "allowJs": true,
          "checkJs": true,
          "module": "commonjs",
          "moduleResolution": "node",
          "esModuleInterop": true,
          "resolveJsonModule": true,
          "strict": true,
          "noImplicitAny": false,
          "target": "es2018",
          "typeRoots": [
            ".iobroker/types",
            "node_modules/@types"
          ]
        },
        "include": [
          "buch.ts",
          "/opt/iobroker/node_modules/iobroker.javascript/lib/javascript.d.ts"
        ],
        "exclude": [
        ]
      }
      

      Habe ein tsconfig.json File und transpiliere dies

      npx tsc --build tsconfig.json
      

      --> Nur Fehlermeldungen. Habe keine Ahnung wie ich "javascript.d.ts" einbinde

      b606e419-3efa-4001-a6cd-66ddb90c04d6-image.png

      T 1 Reply Last reply
      0
      • U uwe72

        @ticaki Nun bin ich zu müde. Komme da nicht weiter, habe keine Ahnung und leider fehlen mir hier (Grund-) kenntnisse.

        {
          "compileOnSave": true,
          "compilerOptions": {
            "noEmit": true,
            "allowJs": true,
            "checkJs": true,
            "module": "commonjs",
            "moduleResolution": "node",
            "esModuleInterop": true,
            "resolveJsonModule": true,
            "strict": true,
            "noImplicitAny": false,
            "target": "es2018",
            "typeRoots": [
              ".iobroker/types",
              "node_modules/@types"
            ]
          },
          "include": [
            "buch.ts",
            "/opt/iobroker/node_modules/iobroker.javascript/lib/javascript.d.ts"
          ],
          "exclude": [
          ]
        }
        

        Habe ein tsconfig.json File und transpiliere dies

        npx tsc --build tsconfig.json
        

        --> Nur Fehlermeldungen. Habe keine Ahnung wie ich "javascript.d.ts" einbinde

        b606e419-3efa-4001-a6cd-66ddb90c04d6-image.png

        T Do not disturb
        T Do not disturb
        ticaki
        wrote on last edited by
        #34

        @uwe72
        Morgen kann ich das mal ausprobieren, aber ich bin schon vor 2h müde gewesen. 🙂

        Weather-Warnings Espresense NSPanel-Lovelace-ui Tagesschau

        Spenden

        U 2 Replies Last reply
        0
        • T ticaki

          @uwe72
          Morgen kann ich das mal ausprobieren, aber ich bin schon vor 2h müde gewesen. 🙂

          U Offline
          U Offline
          uwe72
          wrote on last edited by
          #35

          @ticaki Danke dir!! 🙂

          1 Reply Last reply
          0
          • T ticaki

            @uwe72
            Morgen kann ich das mal ausprobieren, aber ich bin schon vor 2h müde gewesen. 🙂

            U Offline
            U Offline
            uwe72
            wrote on last edited by
            #36

            @ticaki @fastfoot

            Anbei nochmals das nicht funktionierende Beispiel und den aktuellen Stand in übersichtlicher Form:

            Hier mein externes TS-File.

            class Buch  {
            
                public getCurrentWeekdayAsString() : string {
                    var now = new Date();
                    let weekday = now.getDay();
            
                                sendTo("email.0", {
                                    from:    "uwe.clement@gmail.com",                                                                
                                    to:      "uwe.clement@gmail.com",
                                    subject: "Test1",
                                    html: "test2"
                                });	
            
            
                    return this.getWeekdayAsString(weekday);
                }
            
                public getWeekdayAsString(weekday: number) : string {
                    let weekdayAsString;
                    if (weekday == 1) {
                        weekdayAsString = "Montag";
                    } else if (weekday == 2) {
                        weekdayAsString = "Dienstag";
                    } else if (weekday == 3) {
                        weekdayAsString = "Mittwoch";
                    } else if (weekday == 4) {
                        weekdayAsString = "Donnerstag";
                    } else if (weekday == 5) {
                        weekdayAsString = "Freitag";
                    } else if (weekday == 6) {
                        weekdayAsString = "Samstag";
                    } else if (weekday == 7) {
                        weekdayAsString = "Sonntag";
                    } else if (weekday == 0) {
                        weekdayAsString = "Sonntag";
                    }
                    return weekdayAsString;
                }  
            
            }
            
            module.exports = { Buch};
            

            Ohne das "sendTo" funktionierte es. Mit eben nicht.

            Habe im gleichen Verzeichnis diese Datei tsconfig.json:

            {
              "compileOnSave": true,
              "compilerOptions": {
                "noEmit": true,
                "allowJs": true,
                "checkJs": true,
                "module": "commonjs",
                "moduleResolution": "node",
                "esModuleInterop": true,
                "resolveJsonModule": true,
                "strict": true,
                "noImplicitAny": false,
                "target": "es2018",
                "typeRoots": [
                  ".iobroker/types",
                  "node_modules/@types"
                ]
              },
              "include": [
                "**/*.js",
                "**/*.ts",
                ".iobroker/types/javascript.d.ts"
              ],
              "exclude": [
                "node_modules/**"
              ]
            }
            

            Auf der Konsole gebe ich folgendes ein:

            npx tsc --build tsconfig.json
            

            Führt zu diesen Fehlern:

            buch.ts:7:21 - error TS2304: Cannot find name 'sendTo'.
            
            7                     sendTo("email.0", {
                                  ~~~~~~
            
            buch.ts:42:1 - error TS2580: Cannot find name 'module'. Do you need to install type definitions for node? Try `npm i --save-dev @types/node`.
            
            42 module.exports = { Buch};
               ~~~~~~
            
            
            Found 2 errors.
            

            Beide Dateien liegen im gleichen Verzeichnis, in dem ich auch den Befehl "npx tsc --build tsconfig.json" eingebe:
            4ccda497-e58f-4019-8f71-ac27a25da5e7-image.png

            T 2 Replies Last reply
            0
            • U uwe72

              @ticaki @fastfoot

              Anbei nochmals das nicht funktionierende Beispiel und den aktuellen Stand in übersichtlicher Form:

              Hier mein externes TS-File.

              class Buch  {
              
                  public getCurrentWeekdayAsString() : string {
                      var now = new Date();
                      let weekday = now.getDay();
              
                                  sendTo("email.0", {
                                      from:    "uwe.clement@gmail.com",                                                                
                                      to:      "uwe.clement@gmail.com",
                                      subject: "Test1",
                                      html: "test2"
                                  });	
              
              
                      return this.getWeekdayAsString(weekday);
                  }
              
                  public getWeekdayAsString(weekday: number) : string {
                      let weekdayAsString;
                      if (weekday == 1) {
                          weekdayAsString = "Montag";
                      } else if (weekday == 2) {
                          weekdayAsString = "Dienstag";
                      } else if (weekday == 3) {
                          weekdayAsString = "Mittwoch";
                      } else if (weekday == 4) {
                          weekdayAsString = "Donnerstag";
                      } else if (weekday == 5) {
                          weekdayAsString = "Freitag";
                      } else if (weekday == 6) {
                          weekdayAsString = "Samstag";
                      } else if (weekday == 7) {
                          weekdayAsString = "Sonntag";
                      } else if (weekday == 0) {
                          weekdayAsString = "Sonntag";
                      }
                      return weekdayAsString;
                  }  
              
              }
              
              module.exports = { Buch};
              

              Ohne das "sendTo" funktionierte es. Mit eben nicht.

              Habe im gleichen Verzeichnis diese Datei tsconfig.json:

              {
                "compileOnSave": true,
                "compilerOptions": {
                  "noEmit": true,
                  "allowJs": true,
                  "checkJs": true,
                  "module": "commonjs",
                  "moduleResolution": "node",
                  "esModuleInterop": true,
                  "resolveJsonModule": true,
                  "strict": true,
                  "noImplicitAny": false,
                  "target": "es2018",
                  "typeRoots": [
                    ".iobroker/types",
                    "node_modules/@types"
                  ]
                },
                "include": [
                  "**/*.js",
                  "**/*.ts",
                  ".iobroker/types/javascript.d.ts"
                ],
                "exclude": [
                  "node_modules/**"
                ]
              }
              

              Auf der Konsole gebe ich folgendes ein:

              npx tsc --build tsconfig.json
              

              Führt zu diesen Fehlern:

              buch.ts:7:21 - error TS2304: Cannot find name 'sendTo'.
              
              7                     sendTo("email.0", {
                                    ~~~~~~
              
              buch.ts:42:1 - error TS2580: Cannot find name 'module'. Do you need to install type definitions for node? Try `npm i --save-dev @types/node`.
              
              42 module.exports = { Buch};
                 ~~~~~~
              
              
              Found 2 errors.
              

              Beide Dateien liegen im gleichen Verzeichnis, in dem ich auch den Befehl "npx tsc --build tsconfig.json" eingebe:
              4ccda497-e58f-4019-8f71-ac27a25da5e7-image.png

              T Do not disturb
              T Do not disturb
              ticaki
              wrote on last edited by ticaki
              #37

              @uwe72

              "include": [
                  "**/*.js",
                  "**/*.ts",
                  ".iobroker/types/javascript.d.ts"
                ],
              

              da muß die javascript.d.ts datei sein. Kannst das natürlich anpassen.

              Weather-Warnings Espresense NSPanel-Lovelace-ui Tagesschau

              Spenden

              1 Reply Last reply
              0
              • U uwe72

                @ticaki @fastfoot

                Anbei nochmals das nicht funktionierende Beispiel und den aktuellen Stand in übersichtlicher Form:

                Hier mein externes TS-File.

                class Buch  {
                
                    public getCurrentWeekdayAsString() : string {
                        var now = new Date();
                        let weekday = now.getDay();
                
                                    sendTo("email.0", {
                                        from:    "uwe.clement@gmail.com",                                                                
                                        to:      "uwe.clement@gmail.com",
                                        subject: "Test1",
                                        html: "test2"
                                    });	
                
                
                        return this.getWeekdayAsString(weekday);
                    }
                
                    public getWeekdayAsString(weekday: number) : string {
                        let weekdayAsString;
                        if (weekday == 1) {
                            weekdayAsString = "Montag";
                        } else if (weekday == 2) {
                            weekdayAsString = "Dienstag";
                        } else if (weekday == 3) {
                            weekdayAsString = "Mittwoch";
                        } else if (weekday == 4) {
                            weekdayAsString = "Donnerstag";
                        } else if (weekday == 5) {
                            weekdayAsString = "Freitag";
                        } else if (weekday == 6) {
                            weekdayAsString = "Samstag";
                        } else if (weekday == 7) {
                            weekdayAsString = "Sonntag";
                        } else if (weekday == 0) {
                            weekdayAsString = "Sonntag";
                        }
                        return weekdayAsString;
                    }  
                
                }
                
                module.exports = { Buch};
                

                Ohne das "sendTo" funktionierte es. Mit eben nicht.

                Habe im gleichen Verzeichnis diese Datei tsconfig.json:

                {
                  "compileOnSave": true,
                  "compilerOptions": {
                    "noEmit": true,
                    "allowJs": true,
                    "checkJs": true,
                    "module": "commonjs",
                    "moduleResolution": "node",
                    "esModuleInterop": true,
                    "resolveJsonModule": true,
                    "strict": true,
                    "noImplicitAny": false,
                    "target": "es2018",
                    "typeRoots": [
                      ".iobroker/types",
                      "node_modules/@types"
                    ]
                  },
                  "include": [
                    "**/*.js",
                    "**/*.ts",
                    ".iobroker/types/javascript.d.ts"
                  ],
                  "exclude": [
                    "node_modules/**"
                  ]
                }
                

                Auf der Konsole gebe ich folgendes ein:

                npx tsc --build tsconfig.json
                

                Führt zu diesen Fehlern:

                buch.ts:7:21 - error TS2304: Cannot find name 'sendTo'.
                
                7                     sendTo("email.0", {
                                      ~~~~~~
                
                buch.ts:42:1 - error TS2580: Cannot find name 'module'. Do you need to install type definitions for node? Try `npm i --save-dev @types/node`.
                
                42 module.exports = { Buch};
                   ~~~~~~
                
                
                Found 2 errors.
                

                Beide Dateien liegen im gleichen Verzeichnis, in dem ich auch den Befehl "npx tsc --build tsconfig.json" eingebe:
                4ccda497-e58f-4019-8f71-ac27a25da5e7-image.png

                T Do not disturb
                T Do not disturb
                ticaki
                wrote on last edited by ticaki
                #38

                @uwe72

                https://github.com/ticaki/script-library-example

                Hab noch nicht versucht, das im iobroker einzubinden, das complilieren geht schon mal. Hab console und name aus der javascript-d.ts raus werfen müssen.

                Im Arbeitsverzeichnis npx tsc eingeben.

                Ne geht doch noch nicht. 🙂

                Weather-Warnings Espresense NSPanel-Lovelace-ui Tagesschau

                Spenden

                U 1 Reply Last reply
                0
                • T ticaki

                  @uwe72

                  https://github.com/ticaki/script-library-example

                  Hab noch nicht versucht, das im iobroker einzubinden, das complilieren geht schon mal. Hab console und name aus der javascript-d.ts raus werfen müssen.

                  Im Arbeitsverzeichnis npx tsc eingeben.

                  Ne geht doch noch nicht. 🙂

                  U Offline
                  U Offline
                  uwe72
                  wrote on last edited by uwe72
                  #39

                  Update: Habe das aus Github 1:1 reinkopiert und scheint zu funktionieren über "npx tsc"

                  T 1 Reply Last reply
                  0
                  • U uwe72

                    Update: Habe das aus Github 1:1 reinkopiert und scheint zu funktionieren über "npx tsc"

                    T Do not disturb
                    T Do not disturb
                    ticaki
                    wrote on last edited by
                    #40

                    @uwe72
                    Hm im log steht doch alles? Es geht trotzdem noch nicht.

                    Weather-Warnings Espresense NSPanel-Lovelace-ui Tagesschau

                    Spenden

                    U 1 Reply Last reply
                    1
                    • T ticaki

                      @uwe72
                      Hm im log steht doch alles? Es geht trotzdem noch nicht.

                      U Offline
                      U Offline
                      uwe72
                      wrote on last edited by
                      #41

                      @ticaki Ja, es kommt nun keine Fehlermeldung mehr. Die lib.js wird leider nicht erstellt

                      T 1 Reply Last reply
                      0
                      • U uwe72

                        @ticaki Ja, es kommt nun keine Fehlermeldung mehr. Die lib.js wird leider nicht erstellt

                        T Do not disturb
                        T Do not disturb
                        ticaki
                        wrote on last edited by
                        #42

                        @uwe72 sagte in Einfügen von JS-Klassen aus eigenem NPM-Modul:

                        @ticaki Ja, es kommt nun keine Fehlermeldung mehr. Die lib.js wird leider nicht erstellt

                        Jo, das hab ich jetzt alles hinbekommen. Aber der Javascript-Adapter kennt die iobroker eigenen Skriptbefehle nicht, wenn sie in einer externen Datei stecken. Nachvollziehbar.

                        Kann man zwar lösen in dem man beim Erzeugen der Klasse die Funktionen übergibt. Das ist aber nicht schön.

                        Weather-Warnings Espresense NSPanel-Lovelace-ui Tagesschau

                        Spenden

                        U 1 Reply Last reply
                        0
                        • T ticaki

                          @uwe72 sagte in Einfügen von JS-Klassen aus eigenem NPM-Modul:

                          @ticaki Ja, es kommt nun keine Fehlermeldung mehr. Die lib.js wird leider nicht erstellt

                          Jo, das hab ich jetzt alles hinbekommen. Aber der Javascript-Adapter kennt die iobroker eigenen Skriptbefehle nicht, wenn sie in einer externen Datei stecken. Nachvollziehbar.

                          Kann man zwar lösen in dem man beim Erzeugen der Klasse die Funktionen übergibt. Das ist aber nicht schön.

                          U Offline
                          U Offline
                          uwe72
                          wrote on last edited by
                          #43

                          @ticaki said in Einfügen von JS-Klassen aus eigenem NPM-Modul:

                          Jo, das hab ich jetzt alles hinbekommen.

                          Was hast Du noch geändert im Vergleich zu zuvor?

                          T 1 Reply Last reply
                          0
                          • U uwe72

                            @ticaki said in Einfügen von JS-Klassen aus eigenem NPM-Modul:

                            Jo, das hab ich jetzt alles hinbekommen.

                            Was hast Du noch geändert im Vergleich zu zuvor?

                            T Do not disturb
                            T Do not disturb
                            ticaki
                            wrote on last edited by ticaki
                            #44

                            @uwe72
                            Habs auf Github aktualisiert, aber die Verwendung von iobroker eigenen Befehlen endet in undefined oder error. Dafür müsste ich mich wohl durch den Javascript-Adapter arbeiten um zu verstehen wie das genau verarbeitet wird... Em nö 🙂

                            EDIT: Ach und eine Änderung am Importfile verlangt nach einem Restart der Javascriptinstanze.

                            Weather-Warnings Espresense NSPanel-Lovelace-ui Tagesschau

                            Spenden

                            U 2 Replies Last reply
                            0
                            • T ticaki

                              @uwe72
                              Habs auf Github aktualisiert, aber die Verwendung von iobroker eigenen Befehlen endet in undefined oder error. Dafür müsste ich mich wohl durch den Javascript-Adapter arbeiten um zu verstehen wie das genau verarbeitet wird... Em nö 🙂

                              EDIT: Ach und eine Änderung am Importfile verlangt nach einem Restart der Javascriptinstanze.

                              U Offline
                              U Offline
                              uwe72
                              wrote on last edited by
                              #45

                              @ticaki Danke! Ja, lib.js wird nun erstellt. Für alles weitere habe ich heute keine Zeit mehr.

                              Grüße!

                              1 Reply Last reply
                              0
                              • T ticaki

                                @uwe72
                                Habs auf Github aktualisiert, aber die Verwendung von iobroker eigenen Befehlen endet in undefined oder error. Dafür müsste ich mich wohl durch den Javascript-Adapter arbeiten um zu verstehen wie das genau verarbeitet wird... Em nö 🙂

                                EDIT: Ach und eine Änderung am Importfile verlangt nach einem Restart der Javascriptinstanze.

                                U Offline
                                U Offline
                                uwe72
                                wrote on last edited by
                                #46

                                @ticaki Ja, ist bei mir auch so. sendTo() beispielsweise wird dann im iobroker Script nicht erkannt.

                                lib.ts:

                                class Person {
                                    private nachname: string;
                                    private vorname: string;
                                    private alter: string;
                                    constructor(vorname, nachname, alter) {
                                      this.vorname = vorname;
                                      this.nachname = nachname;
                                      this.alter = alter;
                                    }
                                  
                                    information(): string {
                                
                                                    sendTo("email.0", {
                                                        from:    "uwe.clement@gmail.com",                                                                
                                                        to:      "uwe.clement@gmail.com",
                                                        subject: "Test1",
                                                        html: "test2"
                                                    });	
                                
                                      return (`Mein Name ist ${this.vorname} ${this.nachname} und ich bin ${this.alter} Jahre alt!!!!1`);
                                    }
                                    log(): void {
                                        log(this.information());
                                    }
                                  }
                                 
                                module.exports = { Person};
                                

                                ioBroker:

                                const { Person } = require('/opt/iobroker/my_scripts/lib.js');
                                const myPerson = new Person();
                                log(myPerson.information());
                                

                                Fehlermeldung:

                                javascript.1
                                2023-11-12 12:45:31.652	error	at Script.runInContext (node:vm:135:12)
                                
                                javascript.1
                                2023-11-12 12:45:31.652	error	at script.js.common.TEST_IMPORT_TS:8:14
                                
                                javascript.1
                                2023-11-12 12:45:31.652	error	at Person.information (/opt/iobroker/my_scripts/lib.js:8:9)
                                
                                javascript.1
                                2023-11-12 12:45:31.652	error	ReferenceError: sendTo is not defined
                                
                                javascript.1
                                2023-11-12 12:45:31.652	error	^
                                
                                javascript.1
                                2023-11-12 12:45:31.652	error	sendTo("email.0", {
                                
                                javascript.1
                                2023-11-12 12:45:31.652	error	script.js.common.TEST_IMPORT_TS: /opt/iobroker/my_scripts/lib.js:8
                                
                                U 1 Reply Last reply
                                0
                                • U uwe72

                                  @ticaki Ja, ist bei mir auch so. sendTo() beispielsweise wird dann im iobroker Script nicht erkannt.

                                  lib.ts:

                                  class Person {
                                      private nachname: string;
                                      private vorname: string;
                                      private alter: string;
                                      constructor(vorname, nachname, alter) {
                                        this.vorname = vorname;
                                        this.nachname = nachname;
                                        this.alter = alter;
                                      }
                                    
                                      information(): string {
                                  
                                                      sendTo("email.0", {
                                                          from:    "uwe.clement@gmail.com",                                                                
                                                          to:      "uwe.clement@gmail.com",
                                                          subject: "Test1",
                                                          html: "test2"
                                                      });	
                                  
                                        return (`Mein Name ist ${this.vorname} ${this.nachname} und ich bin ${this.alter} Jahre alt!!!!1`);
                                      }
                                      log(): void {
                                          log(this.information());
                                      }
                                    }
                                   
                                  module.exports = { Person};
                                  

                                  ioBroker:

                                  const { Person } = require('/opt/iobroker/my_scripts/lib.js');
                                  const myPerson = new Person();
                                  log(myPerson.information());
                                  

                                  Fehlermeldung:

                                  javascript.1
                                  2023-11-12 12:45:31.652	error	at Script.runInContext (node:vm:135:12)
                                  
                                  javascript.1
                                  2023-11-12 12:45:31.652	error	at script.js.common.TEST_IMPORT_TS:8:14
                                  
                                  javascript.1
                                  2023-11-12 12:45:31.652	error	at Person.information (/opt/iobroker/my_scripts/lib.js:8:9)
                                  
                                  javascript.1
                                  2023-11-12 12:45:31.652	error	ReferenceError: sendTo is not defined
                                  
                                  javascript.1
                                  2023-11-12 12:45:31.652	error	^
                                  
                                  javascript.1
                                  2023-11-12 12:45:31.652	error	sendTo("email.0", {
                                  
                                  javascript.1
                                  2023-11-12 12:45:31.652	error	script.js.common.TEST_IMPORT_TS: /opt/iobroker/my_scripts/lib.js:8
                                  
                                  U Offline
                                  U Offline
                                  uwe72
                                  wrote on last edited by uwe72
                                  #47

                                  @fastfoot Wollte Dich fragen, ob Du eine Idee hast wie man es schafft im externen Script "Dinge" wie sendTo() zu verwenden? Extern lässt es sich fehlerfrei in ein *.js umwandeln. In Iobroker wird der Inhalt des Scriptes angemeckert, da sendTo() unbekannt.

                                  U F 2 Replies Last reply
                                  0
                                  • U uwe72

                                    @fastfoot Wollte Dich fragen, ob Du eine Idee hast wie man es schafft im externen Script "Dinge" wie sendTo() zu verwenden? Extern lässt es sich fehlerfrei in ein *.js umwandeln. In Iobroker wird der Inhalt des Scriptes angemeckert, da sendTo() unbekannt.

                                    U Offline
                                    U Offline
                                    uwe72
                                    wrote on last edited by
                                    #48

                                    Unter https://forum.iobroker.net/topic/69840/erledigt-typescript-viele-common-global-scripte-cpu/34?_=1699802021717
                                    gibt's ganz unten auch noch Informationen zum Thema. Sorry, dass dies nun parallelisiert ist.

                                    1 Reply Last reply
                                    0
                                    • U uwe72

                                      @fastfoot Wollte Dich fragen, ob Du eine Idee hast wie man es schafft im externen Script "Dinge" wie sendTo() zu verwenden? Extern lässt es sich fehlerfrei in ein *.js umwandeln. In Iobroker wird der Inhalt des Scriptes angemeckert, da sendTo() unbekannt.

                                      F Offline
                                      F Offline
                                      fastfoot
                                      wrote on last edited by
                                      #49

                                      @uwe72 nee, keine Idee. Damit Funktionen genutzt werden können müssen Sie halt vorher importiert werden

                                      iobroker läuft unter Docker auf QNAP TS-451+
                                      SkriptRecovery: https://forum.iobroker.net/post/930558

                                      OliverIOO 1 Reply Last reply
                                      0
                                      • F fastfoot

                                        @uwe72 nee, keine Idee. Damit Funktionen genutzt werden können müssen Sie halt vorher importiert werden

                                        OliverIOO Offline
                                        OliverIOO Offline
                                        OliverIO
                                        wrote on last edited by
                                        #50

                                        @fastfoot

                                        zur vollständigkeit, hier die Lösung
                                        https://forum.iobroker.net/topic/69840/erledigt-typescript-viele-common-global-scripte-cpu/36

                                        Meine Adapter und Widgets
                                        TVProgram, SqueezeboxRPC, OpenLiga, RSSFeed, MyTime,, pi-hole2, vis-json-template, skiinfo, vis-mapwidgets, vis-2-widgets-rssfeed
                                        Links im Profil

                                        U 1 Reply Last reply
                                        2
                                        • OliverIOO OliverIO

                                          @fastfoot

                                          zur vollständigkeit, hier die Lösung
                                          https://forum.iobroker.net/topic/69840/erledigt-typescript-viele-common-global-scripte-cpu/36

                                          U Offline
                                          U Offline
                                          uwe72
                                          wrote on last edited by
                                          #51

                                          Habe für mich mal eine funktionierende Lösung in einem neuen Post aufgeschrieben:
                                          https://forum.iobroker.net/topic/78632/info-auslagerung-von-scripte-aus-global-aufs-filesystem

                                          1 Reply Last reply
                                          0
                                          Reply
                                          • Reply as topic
                                          Log in to reply
                                          • Oldest to Newest
                                          • Newest to Oldest
                                          • Most Votes


                                          Support us

                                          ioBroker
                                          Community Adapters
                                          Donate

                                          599

                                          Online

                                          32.4k

                                          Users

                                          81.3k

                                          Topics

                                          1.3m

                                          Posts
                                          Community
                                          Impressum | Datenschutz-Bestimmungen | Nutzungsbedingungen
                                          ioBroker Community 2014-2025
                                          logo
                                          • Login

                                          • Don't have an account? Register

                                          • Login or register to search.
                                          • First post
                                            Last post
                                          0
                                          • Recent
                                          • Tags
                                          • Unread 0
                                          • Categories
                                          • Unreplied
                                          • Popular
                                          • GitHub
                                          • Docu
                                          • Hilfe