Navigation

    Logo
    • Register
    • Login
    • Search
    • Recent
    • Tags
    • Unread
    • Categories
    • Unreplied
    • Popular
    • GitHub
    • Docu
    • Hilfe
    1. Home
    2. Deutsch
    3. Skripten / Logik
    4. JavaScript
    5. [Vorlage] Alias per Skript erzeugen

    NEWS

    • ioBroker goes Matter ... Matter Adapter in Stable

    • Monatsrückblick - April 2025

    • Minor js-controller 7.0.7 Update in latest repo

    [Vorlage] Alias per Skript erzeugen

    This topic has been deleted. Only users with topic management privileges can see it.
    • P
      patti72 @paul53 last edited by

      @paul53 leider geht es noch immer nicht. Die selbe Warnung im log.

      paul53 1 Reply Last reply Reply Quote 0
      • paul53
        paul53 @patti72 last edited by paul53

        @patti72 sagte:

        Die selbe Warnung im log.

        Die Warnung ist oben leider nicht vollständig. Bitte nochmal aus dem Reiter "Log" in Code tags posten.

        P 1 Reply Last reply Reply Quote 0
        • P
          patti72 @paul53 last edited by

          @paul53

          Mehr kommt nicht, wenn ich das Script starte.

          2020-01-04 08:17:42.694 - debug: javascript.0 (2420) system.adapter.admin.0: logging false
          2020-01-04 08:17:43.293 - debug: javascript.0 (2420) system.adapter.admin.0: logging true
          2020-01-04 08:17:52.269 - debug: javascript.0 (2420) sendTo "loadTypings" to system.adapter.admin.0 from system.adapter.javascript.0
          2020-01-04 08:20:47.665 - debug: javascript.0 (2420) sendTo "loadTypings" to system.adapter.admin.0 from system.adapter.javascript.0
          2020-01-04 08:20:53.988 - info: javascript.0 (2420) Stop script script.js.common.alias_anlegen
          2020-01-04 08:20:56.554 - info: javascript.0 (2420) Start javascript script.js.common.alias_anlegen
          2020-01-04 08:20:56.569 - info: javascript.0 (2420) script.js.common.alias_anlegen: getObject(id=deconz.0.Lights.2.on, enumName=undefined) => {"type":"state","common":{"name":"Lampe1 on","type":"boolean","role":"switch","read":true,"write":true},"native":{},"from":"system.adapter.deconz.0","user":"system.user.admin","ts":1578087361576,"_id":"deconz.0.Lights.2.on"}
          2020-01-04 08:20:56.571 - warn: javascript.0 (2420) script.js.common.alias_anlegen: setObject(id=alias.0.lampe2, obj={"type":"state","common":{"name":"Lampe1 on","type":"boolean","role":"switch","read":true,"write":true,"alias":{"id":"deconz.0.Lights.2.on"}},"native":{}}) - was not executed, while debug mode is active
          2020-01-04 08:20:56.572 - info: javascript.0 (2420) script.js.common.alias_anlegen: registered 0 subscriptions and 0 schedules
          2020-01-04 08:28:45.983 - debug: javascript.0 (2420) system.adapter.admin.0: logging false
          2020-01-04 08:28:53.754 - info: info.0 (1408) Popup news was read...
          2020-01-04 08:28:55.246 - info: host.iobroker_oben Update repository "default" under "http://download.iobroker.net/sources-dist.json"
          2020-01-04 08:29:48.955 - debug: javascript.0 (2420) system.adapter.admin.0: logging true
          
          paul53 1 Reply Last reply Reply Quote 0
          • paul53
            paul53 @patti72 last edited by

            @patti72 sagte:

            was not executed, while debug mode is active

            Debug-Modus ausschalten !

            P 1 Reply Last reply Reply Quote 0
            • P
              patti72 @paul53 last edited by

              @paul53 von der JS Instanz oder im Script?

              paul53 1 Reply Last reply Reply Quote -1
              • paul53
                paul53 @patti72 last edited by

                @patti72 sagte:

                von der JS Instanz oder im Script?

                Im Zweifel beide.

                1 Reply Last reply Reply Quote 0
                • P
                  patti72 last edited by

                  @paul53 Tausend Dank. Hat geholfen.

                  1 Reply Last reply Reply Quote 0
                  • XxJooO
                    XxJooO @XxJooO last edited by

                    @XxJooO sagte in [Vorlage] Alias per Skript erzeugen:

                    @paul53

                    ja, der Ausgabewert soll bei true offen und bei false geschlossen ausgeben.

                    1 Reply Last reply Reply Quote 0
                    • Garfonso
                      Garfonso Developer @Markus84 last edited by

                      @Markus84 said in [Vorlage] Alias per Skript erzeugen:

                      Wenn ich Name, state oder role ändere, wird diese Änderung jedoch nicht mitsynchronisiert. Ist das normal? Falls dies normal ist, kann ich bedenkenlos diese Daten im Alias ändern (werden dann logischerweise zwar nicht synchronisiert) oder lässt man besser die Finger davon?

                      Es ist ja gerade die Idee von der Alias-Funktion, dass du am Alias-Objekt role, Name, Funktion, Raum usw. "schön" setzt. Die Objekte im Adapternamespace können sich ja beliebig ändern, wenn der Adapter das für richtig hält oder wenn mal ein Gerät ersetzt werden soll.

                      M 1 Reply Last reply Reply Quote 0
                      • M
                        Markus84 @Garfonso last edited by

                        @Garfonso Danke für die Klarstellung! Wenn man einmal verstanden hat, wofür Alias-Objekte sind, ist es natürlich logisch. Es macht bestimmt eine riesen Arbeit die Alias-Objekte einmal einzurichten, aber das ist es auf lange Sicht definitiv Wert.

                        Z 1 Reply Last reply Reply Quote 0
                        • Z
                          zahnheinrich @Markus84 last edited by

                          @paul53
                          Ich möchte für meine Xiaomi Bewegungsmelder einen alias Datenpunkt erstellen.
                          Im Xiaomi ist der Datenpunkt vom Typ number und zeigt die verstrichene Zeit in Sekunden seit der letzten Auslösung an:


                          {
                          "_id": "mihome.0.devices.motion_158d00013f7666.no_motion",
                          "common": {
                          "name": "Last motion",
                          "role": "state",
                          "write": false,
                          "read": true,
                          "type": "number",
                          "unit": "seconds",
                          "desc": "Last motion for at least X seconds"
                          },
                          "type": "state",
                          "native": {},
                          "from": "system.adapter.mihome.0",
                          "ts": 1545432495106,
                          "acl": {
                          "object": 1636,
                          "state": 1636,
                          "owner": "system.user.admin",
                          "ownerGroup": "system.group.administrator"
                          }
                          }

                          Der alias Datenpunkt soll ein boolean sein, der bei (Xiaomi = 0) true und sonst (Xiaomi > 0) false ist.
                          Dein Skript am Fredanfang habe ich so angepasst:

                          // Original-Datenpunkt
                          const idOrigin = 'mihome.0.devices.motion_158d00013f7666.no_motion';

                          // Alias-Datenpunkt
                          const idAlias = 'BWM.Raeumchen.MOTION';
                          var typeAlias, read, write, nameAlias, role, desc, min, max, unit, states;
                          // Folgende kommentieren, wenn keine Änderung der Eigenschaft erforderlich
                          //typeAlias = 'number'; // typeAlias = 'boolean'; // oder 'number'
                          typeAlias = 'boolean';
                          read = "val == '0' ? true : false"; // Erkennung "Aus" --> false erfolgt automatisch
                          //write = "val ? 'Ein' : 'Aus'";
                          nameAlias = 'BWM Räumchen';
                          role = 'sensor.motion';
                          desc = 'per Script erstellt';
                          //min = 0; // nur Zahlen
                          //max = 100; // nur Zahlen
                          unit = ''; // nur für Zahlen
                          //states = {0: 'true', 60: 'false'}; // Zahlen (Multistate) oder Logikwert (z.B. Aus/Ein)


                          Bekomme aber den Datenpunkt so angelegt:
                          screen135.png

                          Was mache ich falsch?
                          Vielen Dank im Voraus!
                          Ulrich

                          paul53 1 Reply Last reply Reply Quote 0
                          • paul53
                            paul53 @zahnheinrich last edited by

                            @zahnheinrich sagte:

                            Bekomme aber den Datenpunkt so angelegt:

                            Wie sieht die RAW-Ansicht des Alias-Objektes aus (bitte in Code tags (</>) posten) ?

                            Z 1 Reply Last reply Reply Quote 0
                            • Z
                              zahnheinrich @paul53 last edited by

                              @paul53
                              Bitteschön:

                              {
                                "type": "state",
                                "common": {
                                  "name": "BWM Räumchen",
                                  "role": "sensor.motion",
                                  "write": false,
                                  "read": true,
                                  "type": "boolean",
                                  "unit": "seconds",
                                  "desc": "per Script erstellt",
                                  "alias": {
                                    "id": "mihome.0.devices.motion_158d00013f7666.no_motion",
                                    "read": "val == '0' ? true : false"
                                  }
                                },
                                "native": {},
                                "from": "system.adapter.javascript.0",
                                "user": "system.user.admin",
                                "ts": 1578589323783,
                                "_id": "alias.0.BWM.Raeumchen.MOTION",
                                "acl": {
                                  "object": 1636,
                                  "state": 1636,
                                  "owner": "system.user.admin",
                                  "ownerGroup": "system.group.administrator"
                                }
                              }
                              
                              paul53 1 Reply Last reply Reply Quote 0
                              • paul53
                                paul53 @zahnheinrich last edited by paul53

                                @zahnheinrich
                                Lösche mal Zeile 9 (unit) raus und ändere "read"

                                      "read": "val == 0 ? true : false"
                                

                                oder

                                      "read": "val ? false : true"
                                

                                oder

                                      "read": "!val"
                                
                                Z 1 Reply Last reply Reply Quote 0
                                • Z
                                  zahnheinrich @paul53 last edited by

                                  @paul53 sagte in [Vorlage] Alias per Skript erzeugen:
                                  Danke!

                                  "read": "!val"

                                  funktioniert.

                                  Bei "unit" hatte ich im script "" eingetragen. Das führte aber nicht zur gewünschten Unterdrückung jeglicher Einheit im Alias.
                                  Muss ich das dann immer händisch löschen, oder?

                                  Vielen Dank für deine Mühe, hatte stundenlang alle Konbinationen ohne Erfolg durchprobiert!

                                  paul53 1 Reply Last reply Reply Quote 0
                                  • paul53
                                    paul53 @zahnheinrich last edited by

                                    @zahnheinrich sagte:

                                    Bei "unit" hatte ich im script "" eingetragen.

                                    if(unit) liefert bei einem Leerstring false, die Einheit wurde also nicht überschrieben. Ein Leerzeichen " " hätte sie unsichtbar gemacht.

                                    Z 2 Replies Last reply Reply Quote 0
                                    • Z
                                      zahnheinrich @paul53 last edited by

                                      @paul53
                                      Dankeschön, wieder etwas gelernt 🕶

                                      1 Reply Last reply Reply Quote 0
                                      • Z
                                        zahnheinrich @paul53 last edited by

                                        @paul53
                                        Kurioserweise bekomme ich ab jetzt bei einem neuen Datenpunkt ein Infosymbol :

                                        screen137.png

                                        Was sagt mir das?

                                        paul53 crunchip 2 Replies Last reply Reply Quote 0
                                        • paul53
                                          paul53 @zahnheinrich last edited by

                                          @zahnheinrich sagte:

                                          Was sagt mir das?

                                          ?? Habe ich noch nicht gesehen.

                                          Z 1 Reply Last reply Reply Quote 0
                                          • Z
                                            zahnheinrich @paul53 last edited by

                                            @paul53
                                            Da bin ich aber froh 😂
                                            Ich nämlich auch nicht!

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

                                            Support us

                                            ioBroker
                                            Community Adapters
                                            Donate

                                            577
                                            Online

                                            31.6k
                                            Users

                                            79.5k
                                            Topics

                                            1.3m
                                            Posts

                                            38
                                            314
                                            43645
                                            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