Skip to content
  • Home
  • Aktuell
  • Tags
  • 0 Ungelesen 0
  • Kategorien
  • Unreplied
  • Beliebt
  • 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

  • Standard: (Kein Skin)
  • Kein Skin
Einklappen
ioBroker Logo

Community Forum

donate donate
  1. ioBroker Community Home
  2. Deutsch
  3. Skripten / Logik
  4. JavaScript
  5. Omlet Hühnerstall webhook API

NEWS

  • Monatsrückblick Januar/Februar 2026 ist online!
    BluefoxB
    Bluefox
    16
    1
    247

  • Jahresrückblick 2025 – unser neuer Blogbeitrag ist online! ✨
    BluefoxB
    Bluefox
    17
    1
    4.6k

  • Neuer Blogbeitrag: Monatsrückblick - Dezember 2025 🎄
    BluefoxB
    Bluefox
    13
    1
    1.3k

Omlet Hühnerstall webhook API

Geplant Angeheftet Gesperrt Verschoben JavaScript
34 Beiträge 3 Kommentatoren 222 Aufrufe 2 Watching
  • Älteste zuerst
  • Neuste zuerst
  • Meiste Stimmen
Antworten
  • In einem neuen Thema antworten
Anmelden zum Antworten
Dieses Thema wurde gelöscht. Nur Nutzer mit entsprechenden Rechten können es sehen.
  • J Offline
    J Offline
    jwerlsdf
    schrieb am zuletzt editiert von
    #14

    Screenshot 2026-03-08 210839.png

    Auch mit dem erweiterten Skript von dir funktioniert es leider nicht:

    
    javascript.0
    2026-03-08 21:07:59.264	error	TypeError: Cannot read properties of undefined (reading 'state') at createOmletType (/opt/iobroker/node_modules/@iobroker-javascript.0/smartcoop-sdk/dist/factories/type.factory.js:129:29) at createOmletType (/opt/iobroker/node_modules/@iobroker-javascript.0/smartcoop-sdk/dist/factories/type.factory.js:96:25) at createOmletType (/opt/iobroker/node_modules/@iobroker-javascript.0/smartcoop-sdk/dist/factories/type.factory.js:148:24) at /opt/iobroker/node_modules/@iobroker-javascript.0/smartcoop-sdk/dist/omlet.js:24:136 at Array.map (<anonymous>) at Object.<anonymous> (/opt/iobroker/node_modules/@iobroker-javascript.0/smartcoop-sdk/dist/omlet.js:24:34) at Generator.next (<anonymous>) at fulfilled (/opt/iobroker/node_modules/@iobroker-javascript.0/smartcoop-sdk/dist/omlet.js:5:58) at process.processTicksAndRejections (node:internal/process/task_queues:103:5)
    
    javascript.0
    2026-03-08 21:07:59.264	error	Error: Cannot read properties of undefined (reading 'state')
    
    javascript.0
    2026-03-08 21:07:59.264	error	An error happened which is most likely from one of your scripts, but the originating script could not be detected.
    
    OliverIOO 1 Antwort Letzte Antwort
    0
    • J jwerlsdf

      Screenshot 2026-03-08 210839.png

      Auch mit dem erweiterten Skript von dir funktioniert es leider nicht:

      
      javascript.0
      2026-03-08 21:07:59.264	error	TypeError: Cannot read properties of undefined (reading 'state') at createOmletType (/opt/iobroker/node_modules/@iobroker-javascript.0/smartcoop-sdk/dist/factories/type.factory.js:129:29) at createOmletType (/opt/iobroker/node_modules/@iobroker-javascript.0/smartcoop-sdk/dist/factories/type.factory.js:96:25) at createOmletType (/opt/iobroker/node_modules/@iobroker-javascript.0/smartcoop-sdk/dist/factories/type.factory.js:148:24) at /opt/iobroker/node_modules/@iobroker-javascript.0/smartcoop-sdk/dist/omlet.js:24:136 at Array.map (<anonymous>) at Object.<anonymous> (/opt/iobroker/node_modules/@iobroker-javascript.0/smartcoop-sdk/dist/omlet.js:24:34) at Generator.next (<anonymous>) at fulfilled (/opt/iobroker/node_modules/@iobroker-javascript.0/smartcoop-sdk/dist/omlet.js:5:58) at process.processTicksAndRejections (node:internal/process/task_queues:103:5)
      
      javascript.0
      2026-03-08 21:07:59.264	error	Error: Cannot read properties of undefined (reading 'state')
      
      javascript.0
      2026-03-08 21:07:59.264	error	An error happened which is most likely from one of your scripts, but the originating script could not be detected.
      
      OliverIOO Offline
      OliverIOO Offline
      OliverIO
      schrieb am zuletzt editiert von OliverIO
      #15

      @jwerlsdf

      Aber wo sind den die Ausgaben?
      Zumindest die ersten paar Inhalte von console.log sollten dort auftauchen.
      Wie schon geschrieben. Der Fehler wäre erklärbar. Aber wir brauchen die Ausgaben.

      hier die logausgabe im scriptfenster.
      aus irgendeinem grund kommt der fehler nicht wie früher auch in diesem fenster, sondern im iobroker log

      so sieht das bei mir im script fenster aus
      cc39ef97-9a23-4ebf-b7f0-6da07599840c-image.png

      du siehst die beiden zeilen
      start main und
      get devices
      und das was theoretisch bei dir nach
      Devices:
      kommt benötigen wir

      so sieht das bei mir im iobroker log aus
      1cbbc7bf-8732-47b2-bda8-6c9796a579b2-image.png

      bei mir kommt der fehler 401, was schlich Not Authorized bedeutet, da ich ja keinen api key habe
      evtl stellst du mal den log level des javascript adapters auf debug. evtl werden deswegen die ausgaben ausgefiltert

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

      1 Antwort Letzte Antwort
      1
      • J Offline
        J Offline
        jwerlsdf
        schrieb am zuletzt editiert von
        #16

        ich bekomme leider keine LOG ausgabe:

        image.png

        image.png

        Mehr gibt es leider nicht.

        OliverIOO 1 Antwort Letzte Antwort
        0
        • J jwerlsdf

          ich bekomme leider keine LOG ausgabe:

          image.png

          image.png

          Mehr gibt es leider nicht.

          OliverIOO Offline
          OliverIOO Offline
          OliverIO
          schrieb am zuletzt editiert von
          #17

          @jwerlsdf

          gut dann scheitert das schon bei getdevices.
          dann kann es nur am api key liegen
          evtl fragst du da mal beim support nach

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

          1 Antwort Letzte Antwort
          0
          • J Offline
            J Offline
            jwerlsdf
            schrieb am zuletzt editiert von
            #18

            Ok mach ich. Dann melde ich mich, wenn ich was neues erfahren habe. Danke schon mal für deine Hilfe.

            1 Antwort Letzte Antwort
            0
            • OliverIOO OliverIO

              @jwerlsdf

              hast du alles kopiert?
              Das ist eine Fehlermeldung die beim ersten Lauf auch zu erwarten wäre, da wir ja die konkrete Device ID noch nicht wissen.
              Davor hätte es eigentlich eine Liste der vorhandenen Devices (door, light) ausgeben müssen. Habe ich aber eigentlich oben schon geschrieben

              hier mal das gleiche Skript ergänzt mit ein paar logausgaben, das man sieht wie weit das skript gekommen ist

              const { createOmlet } = require('smartcoop-sdk');
              
              async function main() {
                  console.log("start main");
                  const omlet = await createOmlet('apitoken');
                  console.log("get devices");
                  const devices = await omlet.getDevices();
                  console.log("Devices:");
                  console.log(devices);
                  const device = await omlet.getDeviceById('deviceid123456');
                  console.log("get actions");
                  const openAction = device.getActions().find((action) => action.name === 'open');
                  console.log("check action");
                  if (openAction) {
                      console.log("do action");
                      await device.action(openAction)
                  }
              }
              main();
              
              
              

              und nur nochmal zur Sicherheit weil ich hatte im vorletzten Post nach der API gefragt und du hast mir ein bild der bibliothek im javascript adapter gezeigt.

              Du musst dir im omlet portal einen api token generieren.
              diesen token entspricht sozusagen deinem userid/passwort. damit weiß omelt um welches konto es sich handelt.
              in der dokumentation ist das unter Javascript SDK beschrieben
              https://smart.omlet.de/developers/js-sdk

              7d048462-529e-4490-980c-7ec790b091a0-image.png

              HomoranH Offline
              HomoranH Offline
              Homoran
              Global Moderator Administrators
              schrieb am zuletzt editiert von
              #19

              @jwerlsdf
              Hast du in Zeile 5

              @OliverIO sagte in Omlet Hühnerstall webhook API:

              const omlet = await createOmlet('apitoken');

              deinen apitoken korrekt eingetragen?

              kein Support per PN! - Fragen im Forum stellen -
              Benutzt das Voting rechts unten im Beitrag wenn er euch geholfen hat.
              Das Forum freut sich über eine Spende. Benutzt dazu den Spendenbutton im Header. Danke!
              der Installationsfixer: curl -fsL https://iobroker.net/fix.sh | bash -

              OliverIOO 1 Antwort Letzte Antwort
              0
              • HomoranH Homoran

                @jwerlsdf
                Hast du in Zeile 5

                @OliverIO sagte in Omlet Hühnerstall webhook API:

                const omlet = await createOmlet('apitoken');

                deinen apitoken korrekt eingetragen?

                OliverIOO Offline
                OliverIOO Offline
                OliverIO
                schrieb am zuletzt editiert von
                #20

                @Homoran sagte in Omlet Hühnerstall webhook API:

                deinen apitoken korrekt eingetragen?

                das habe ich bereits sehr oft gefragt.
                wenn es an dem lag geb ich sowieso auf.
                mein deal ist:
                ich bin sorgfältig
                DU/ER ist sorgfältig.
                wenn es einseitig ist,
                dann macht es kein spass

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

                HomoranH 1 Antwort Letzte Antwort
                1
                • OliverIOO OliverIO

                  @Homoran sagte in Omlet Hühnerstall webhook API:

                  deinen apitoken korrekt eingetragen?

                  das habe ich bereits sehr oft gefragt.
                  wenn es an dem lag geb ich sowieso auf.
                  mein deal ist:
                  ich bin sorgfältig
                  DU/ER ist sorgfältig.
                  wenn es einseitig ist,
                  dann macht es kein spass

                  HomoranH Offline
                  HomoranH Offline
                  Homoran
                  Global Moderator Administrators
                  schrieb am zuletzt editiert von Homoran
                  #21

                  @OliverIO ich muss ehrlich sagen, ich wüsste jetzt nicht ob der zwischen die Anführungszeichen kommen müsste, oder ohne, und wenn ja, ob er die richtigen genommen hat. also keine Backticks o.ä.

                  kein Support per PN! - Fragen im Forum stellen -
                  Benutzt das Voting rechts unten im Beitrag wenn er euch geholfen hat.
                  Das Forum freut sich über eine Spende. Benutzt dazu den Spendenbutton im Header. Danke!
                  der Installationsfixer: curl -fsL https://iobroker.net/fix.sh | bash -

                  1 Antwort Letzte Antwort
                  0
                  • J Offline
                    J Offline
                    jwerlsdf
                    schrieb am zuletzt editiert von jwerlsdf
                    #22

                    @homoran
                    natürlich habe ich den token dort zwischen die Anführungszeichen eingetragen. Alternativ würde ich auch den token per pn schicken um definitiv das Problem von meiner Seite auszuschließen. Der Token ist von der Seite 1zu1 kopiert, kann also am "abschreiben" nicht liegen ;)

                    OliverIOO 2 Antworten Letzte Antwort
                    0
                    • J jwerlsdf

                      @homoran
                      natürlich habe ich den token dort zwischen die Anführungszeichen eingetragen. Alternativ würde ich auch den token per pn schicken um definitiv das Problem von meiner Seite auszuschließen. Der Token ist von der Seite 1zu1 kopiert, kann also am "abschreiben" nicht liegen ;)

                      OliverIOO Offline
                      OliverIOO Offline
                      OliverIO
                      schrieb am zuletzt editiert von
                      #23

                      @jwerlsdf

                      ja dann sende ihn bitte per pn.
                      dann probiere ich das script mal unter vscode aus. da hat man mehr debug möglichkeiten

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

                      1 Antwort Letzte Antwort
                      1
                      • J jwerlsdf

                        @homoran
                        natürlich habe ich den token dort zwischen die Anführungszeichen eingetragen. Alternativ würde ich auch den token per pn schicken um definitiv das Problem von meiner Seite auszuschließen. Der Token ist von der Seite 1zu1 kopiert, kann also am "abschreiben" nicht liegen ;)

                        OliverIOO Offline
                        OliverIOO Offline
                        OliverIO
                        schrieb am zuletzt editiert von OliverIO
                        #24

                        @jwerlsdf

                        ok mit vscode kommt bei getdevices der selbe fehler.
                        ich versuche mal noch etwas anderes.


                        ok, keine ahnung ob es nun an der bibliothek liegt oder an etwas anderem.

                        1. per direkter axios kommunikation konnte ich nun die informationen abrufen

                        2. in den statusinformationen gab es diese information

                          lastConnected: "2026-03-07T14:06:16+00:00",
                          nextConnection: "2026-03-07T14:06:16+00:00",
                          overdueConnection: 1,

                        keine Ahnung, ob das jetzt daran liegt, das das gerät irgendwie seit gestern kein kontakt mehr hatte.

                        es gibt genau ein device id
                        dieses hat die folgenden aktionen die ausgeführt werden könnten

                        [
                          "calibrate => Calibrate Door",
                          "close => Close Door",
                          "detect => Detect Coop Light",
                          "factory_reset => Factory Reset",
                          "firmware_update => Check for Firmware Update",
                          "off => Light Off",
                          "on => Light On",
                          "open => Open Door",
                          "restart => Restart",
                          "setup_wifi => Reset Wifi Credentials",
                          "stop => Stop Door",
                        ]
                        

                        welche davon sinnvoll sind weiß ich nicht. such dir mal welche aus, die wir hier umsetzen wollen (erst mal mit den wichtigsten anfangen)

                        darüber hinaus sehe ich den status

                            state: {
                              light: {
                                state: "onpending",
                              },
                              general: {
                                firmwareVersionCurrent: "1.0.54-f3d53670",
                                firmwareLastCheck: "2026-03-07T13:16:27+01:00",
                                batteryLevel: 100,
                                powerSource: "external",
                                displayLine1: "                ",
                                displayLine2: "                ",
                                firmwareVersionPrevious: "1.0.47-6870ee4d",
                                uptime: 6596,
                              },
                              connectivity: {
                                wifiStrength: -70,
                                ssid: "MTL",
                                connected: false,
                              },
                              door: {
                                state: "open",
                                lastOpenTime: "2026-03-07T06:00:12+01:00",
                                lastCloseTime: "2026-03-06T23:16:01+01:00",
                                fault: "none",
                                lightLevel: 100,
                              },
                            },
                        

                        und die configuration

                            configuration: {
                              door: {
                                openMode: "time",
                                openDelay: 0,
                                openTime: "06:00",
                                closeMode: "light",
                                closeDelay: 0,
                                closeLightLevel: 6,
                                closeTime: "20:00",
                                openLightLevel: 27,
                                doorType: "sliding",
                                colour: "green",
                                lightOffset: 3,
                                temperatureUnit: "C",
                              },
                              light: {
                                mode: "auto",
                                minutesBeforeClose: 5,
                                maxOnTime: 3,
                                equipped: 2,
                              },
                              connectivity: {
                                wifiState: "on",
                              },
                              general: {
                                datetime: "2026-03-07T14:56:35+01:00",
                                timezone: "Europe/Berlin",
                                updateFrequency: 86400,
                                language: "de",
                                stayAliveTime: 0,
                                statusUpdatePeriod: 21600,
                                pollFreq: 600,
                                overnightSleepEnable: true,
                                overnightSleepStart: "21:00",
                                overnightSleepEnd: "05:00",
                              },
                            },
                        

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

                        1 Antwort Letzte Antwort
                        0
                        • J Offline
                          J Offline
                          jwerlsdf
                          schrieb am zuletzt editiert von
                          #25

                          Hi, das sieht sehr gut aus. Ja tatsächlich habe ich seit gestern den Stecker von der Tür gezogen. Dadurch habe ich auch keine Infos mehr in der app. Ich werde nachher gerne die Tür an die Steckdose wieder stecken, sobald ich von der Arbeit zurück bin. Da sollten hoffentlich bei dir aktuelle Infos reinkommen.

                          1 Antwort Letzte Antwort
                          0
                          • J Offline
                            J Offline
                            jwerlsdf
                            schrieb am zuletzt editiert von
                            #26

                            Die wichtigsten FUnktionen wären für mich das Licht an/ausschalten und die Tür auf/zu machen zu können. SO wie ich das dann verstanden habe, kann ich die Konfiguration ebenfalls ändern? Dann wäre die dritte funktion die Uhrzeiten zu ändern (open and close Time).

                            OliverIOO 1 Antwort Letzte Antwort
                            0
                            • J jwerlsdf

                              Die wichtigsten FUnktionen wären für mich das Licht an/ausschalten und die Tür auf/zu machen zu können. SO wie ich das dann verstanden habe, kann ich die Konfiguration ebenfalls ändern? Dann wäre die dritte funktion die Uhrzeiten zu ändern (open and close Time).

                              OliverIOO Offline
                              OliverIOO Offline
                              OliverIO
                              schrieb am zuletzt editiert von
                              #27

                              @jwerlsdf

                              so hier zum probieren für die erste runde für licht und tor
                              token noch eintragen
                              den device id hab ich jetzt nicht versteckt, ohne den token kann da niemand was mit anfangen
                              vor dem start bitte noch die beiden datenpunkte vom typ boolean anlegen und die datenpunktnamen dann am anfang in der configuration area eintragen.
                              prüfe bitte mal ob du bei den zusätzlichen npm module auch axios eingetragen hast.
                              eigentlich ist das nicht notwendig, da der javascriptadapter selbst axios verwendet, aber um für die zukunft sauber zu sein ist das besser

                              meine aktuellen experimente für das licht hat den status 204 zurückgegeben.
                              der doku nach bedeutet das

                              Action has been queued to be sent to the device

                              Keine Ahnung ob jetzt alles abgespult wird wenn du es anschaltest.

                              // -- configuration area
                              const token = 'apitoken';
                              const outdoorDeviceId = 'laTnMsWSJxBMGgJD';
                              const dp_light = '0_userdata.0.omlet.light'; // datenpunkt mit typ bool anlegen und namen hier eintragen
                              const dp_door = '0_userdata.0.omlet.door'; // datenpunkt mit typ bool anlegen und namen hier eintragen
                              // --
                              
                              const axios = require("axios/dist/browser/axios.cjs");
                              const BASE_URL = 'https://x107.omlet.co.uk/api/v1'; //kann hier geprüft werden https://smart.omlet.de/developers/api
                              let omlet = undefined;
                              
                              async function connect() {
                                  console.log("start main2");
                                  omlet = await omletAPIClient(token);
                                  await getDevices(true);
                              
                                  //console.log(JSON.stringify(await getDevices(), null, 2));
                              }
                              async function getDevices(info = false) {
                                  try {
                                      const devices = await getRequest('/device');
                                      if (devices && info) {
                                          devices.forEach(device => {
                                              console.log(`Device name: ${device.name}, deviceId: ${device.deviceId}`);
                                          });
                                      }
                                      return devices;
                                  } catch (error) {
                                      console.log(error);
                                      return [];
                                  }
                              }
                              async function doAction(deviceId, actionName) {
                                  const devices = await getDevices();
                                  const device = devices.find(device => device.deviceId === deviceId);
                                  if (device) {
                                      const action = device.actions.find(action => action.actionName === actionName);
                                      if (action) {
                                          await postRequest(action.url);
                                      }
                                  }
                              }
                              async function lightOn(deviceId) {
                                  await doAction(deviceId, 'on');
                              }
                              async function lightOff(deviceId) {
                                  await doAction(deviceId, 'off');
                              }
                              async function doorOpen(deviceId) {
                                  await doAction(deviceId, 'open');
                              }
                              async function doorClose(deviceId) {
                                  await doAction(deviceId, 'close');
                              }
                              function omletAPIClient(token) {
                                  return axios.create({
                                      baseURL: BASE_URL,
                                      headers: {
                                          'Authorization': `Bearer ${token}`,
                                          'Content-Type': 'application/json',
                                      },
                                  });
                              }
                              async function getRequest(url) {
                                  try {
                                      const data = await omlet.get(url);
                                      console.debug(`get request: ${url},status: ${data.status}`);
                                      return data.data;
                                  } catch (e) {
                                      console.log(e);
                                  }
                              }
                              async function postRequest(url) {
                                  try {
                                      const data = await omlet.post(url);
                                      console.debug(`post request: ${url},status: ${data.status}`);
                                      return data.data;
                                  } catch (e) {
                                      console.log(e);
                                  }
                              }
                              async function main() {
                                  await connect();
                                  on({ id: dp_door, change: 'ne' }, async (evt) => {
                                      //log(evt);
                                      if (evt.state.val) {
                                          await doorOpen(outdoorDeviceId);
                                      } else {
                                          await doorClose(outdoorDeviceId);
                                      }
                                  });
                                  on({ id: dp_light, change: 'ne' }, async (evt) => {
                                      //log(evt);
                                      if (evt.state.val) {
                                          await lightOn(outdoorDeviceId);
                                      } else {
                                          await lightOff(outdoorDeviceId);
                                      }
                                  });
                              
                                  // await lightOn(outdoorDeviceId);
                                  // await lightOff(outdoorDeviceId);
                              }
                              main();
                              

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

                              1 Antwort Letzte Antwort
                              2
                              • J Offline
                                J Offline
                                jwerlsdf
                                schrieb am zuletzt editiert von
                                #28

                                Vielen vielen lieben Dank. Es funktioniert hervorragend! :)
                                Die Umbenennung mache ich dann über die VIS da false für tür zu etwas verwirrend ist.

                                Würdest du mir noch bitte folgende Funktionen einbauen?
                                -Tür stop
                                -Uhrzeiten einstellbar Manuel oder Zeiteingabe für Tür auf/zu ggf zusätzlich Astrofunktion (wobei ich letzteres auch selbst mit einem zweiten Script lösen könnte.... dann soll einfach alles auf manual laufen.

                                OliverIOO 1 Antwort Letzte Antwort
                                0
                                • J jwerlsdf

                                  Vielen vielen lieben Dank. Es funktioniert hervorragend! :)
                                  Die Umbenennung mache ich dann über die VIS da false für tür zu etwas verwirrend ist.

                                  Würdest du mir noch bitte folgende Funktionen einbauen?
                                  -Tür stop
                                  -Uhrzeiten einstellbar Manuel oder Zeiteingabe für Tür auf/zu ggf zusätzlich Astrofunktion (wobei ich letzteres auch selbst mit einem zweiten Script lösen könnte.... dann soll einfach alles auf manual laufen.

                                  OliverIOO Offline
                                  OliverIOO Offline
                                  OliverIO
                                  schrieb am zuletzt editiert von OliverIO
                                  #29

                                  @jwerlsdf

                                  weiter gehts mit der nächsten version.
                                  vorgehensweise wie oben.
                                  es sind ein paar mehr datenpunkte dazugekommen
                                  bitte vorher die datenpunkte anlegen. typ und detailanweisung im zeilenkommentar beachten

                                  const dp_doorstop = '0_userdata.0.omlet.doorstop'; // datenpunkt mit typ bool und rolle button anlegen und namen hier eintragen
                                  const dp_doortimeopen = '0_userdata.0.omlet.doortimeopen'; // datenpunkt mit typ string, zeit im 24h format im format 06:00 oder 20:30
                                  const dp_doortimeclose = '0_userdata.0.omlet.doortimeclose'; // datenpunkt mit typ string, zeit im 24h format im format 06:00 oder 20:30
                                  const dp_devicedata = '0_userdata.0.omlet.devicedata'; //// datenpunkt mit typ string, hier wird nach jeder aktualisierung der aktuelle device status abgerufen und eingetragen
                                  

                                  wenn im datenpunkt dp_doortimeopen und dp_doortimeclose etwas eingetragen wird, dann sollte die jeweilige zeit gesetzt werden.
                                  im Anschluss wird die Konfiguration gleich abgerufen und im Datenpunkt dp_devicedata abgespeichert, sowie auch dp_doortimeopen und dp_doortimeclose wieder aktualisiert
                                  der button doorstop führt die entsprechende aktion aus.

                                  um mit dem angeschlossenen gerät nicht zu viel unruhe zu erzeugen, habe ich (hoffentlich) nur die lesenden aktionen ausgeführt. die schreibenden aktionen habe ich mal ausgelassen, was aber auch mangels test zu höheren fehlerrisiko neigt. aber mal schauen.
                                  bitte möglichst genau darüber berichten

                                  // -- configuration area
                                  const token = 'apitoken';
                                  const outdoorDeviceId = 'laTnMsWSJxBMGgJD';
                                  const dp_light = '0_userdata.0.omlet.light'; // datenpunkt mit typ bool anlegen und namen hier eintragen
                                  const dp_door = '0_userdata.0.omlet.door'; // datenpunkt mit typ bool anlegen und namen hier eintragen
                                  const dp_doorstop = '0_userdata.0.omlet.doorstop'; // datenpunkt mit typ bool und rolle button anlegen und namen hier eintragen
                                  const dp_doortimeopen = '0_userdata.0.omlet.doortimeopen'; // datenpunkt mit typ string, zeit im 24h format im format 06:00 oder 20:30
                                  const dp_doortimeclose = '0_userdata.0.omlet.doortimeclose'; // datenpunkt mit typ string, zeit im 24h format im format 06:00 oder 20:30
                                  const dp_devicedata = '0_userdata.0.omlet.devicedata'; //// datenpunkt mit typ string, hier wird nach jeder aktualisierung der aktuelle device status abgerufen und eingetragen
                                  
                                  
                                  // --
                                  
                                  const axios = require("axios/dist/browser/axios.cjs");
                                  const BASE_URL = 'https://x107.omlet.co.uk/api/v1'; //kann hier geprüft werden https://smart.omlet.de/developers/api
                                  let omlet = undefined;
                                  
                                  async function connect() {
                                      console.log("start main2");
                                      omlet = await omletAPIClient(token);
                                      await getDevices(true);
                                  
                                      //console.log(JSON.stringify(await getDevices(), null, 2));
                                  }
                                  async function getDevices(info = false) {
                                      try {
                                          const devices = await getRequest('/device');
                                          if (devices && info) {
                                              devices.forEach(device => {
                                                  console.log(`Device name: ${device.name}, deviceId: ${device.deviceId}`);
                                              });
                                          }
                                          return devices;
                                      } catch (error) {
                                          console.log(error);
                                          return [];
                                      }
                                  }
                                  async function getDevice(deviceId) {
                                      try {
                                          const device = await getRequest(`/device/${deviceId}`);
                                          return device;
                                      } catch (error) {
                                          console.log(error);
                                          return {};
                                      }
                                  }
                                  async function getConfiguration(deviceId) {
                                      try {
                                          const configuration = await getRequest(`/device/${deviceId}/configuration`);
                                          return configuration;
                                      } catch (error) {
                                          console.log(error);
                                          return {};
                                      }
                                  }
                                  async function setConfiguration(deviceId, configuration) {
                                      try {
                                          const result = await patchRequest(`/device/${deviceId}/configuration`, configuration);
                                  
                                          return result;
                                      } catch (error) {
                                          console.log(error);
                                          return {};
                                      }
                                  }
                                  async function getDeviceInfo(deviceId) {
                                      const device = await getDevice(deviceId);
                                  
                                      setState(dp_devicedata, JSON.stringify(device, null, 2), true);
                                      setState(dp_doortimeopen, device.configuration.door.openTime, true);
                                      setState(dp_doortimeclose, device.configuration.door.closeTime, true);
                                  }
                                  async function doAction(deviceId, actionName) {
                                      const devices = await getDevices();
                                      const device = devices.find(device => device.deviceId === deviceId);
                                      if (device) {
                                          const action = device.actions.find(action => action.actionName === actionName);
                                          if (action) {
                                              await postRequest(action.url);
                                              await getDeviceInfo(outdoorDeviceId);
                                          }
                                      }
                                  }
                                  async function lightOn(deviceId) {
                                      await doAction(deviceId, 'on');
                                  }
                                  async function lightOff(deviceId) {
                                      await doAction(deviceId, 'off');
                                  }
                                  async function doorOpen(deviceId) {
                                      await doAction(deviceId, 'open');
                                  }
                                  async function doorClose(deviceId) {
                                      await doAction(deviceId, 'close');
                                  }
                                  async function doorStop(deviceId) {
                                      await doAction(deviceId, 'stop');
                                  }
                                  async function setDoorTimeClose(deviceId, time) {
                                      const configuration = getConfiguration(deviceId);
                                      const newConfiguration = {
                                          ...configuration,
                                          door: {
                                              ...configuration.door,
                                              closeTime: time
                                          }
                                      };
                                      await setConfiguration(deviceId, newConfiguration);
                                      await getDeviceInfo(outdoorDeviceId);
                                  }
                                  async function setDoorTimeOpen(deviceId, time) {
                                      const configuration = getConfiguration(deviceId);
                                      const newConfiguration = {
                                          ...configuration,
                                          door: {
                                              ...configuration.door,
                                              openTime: time
                                          }
                                      };
                                      await setConfiguration(deviceId, newConfiguration);
                                      await getDeviceInfo(outdoorDeviceId);
                                  }
                                  function omletAPIClient(token) {
                                      return axios.create({
                                          baseURL: BASE_URL,
                                          headers: {
                                              'Authorization': `Bearer ${token}`,
                                              'Content-Type': 'application/json',
                                          },
                                      });
                                  }
                                  function isValidTime24h(value) {
                                      return /^(?:[01]\d|2[0-3]):[0-5]\d$/.test(value);
                                  }
                                  async function getRequest(url) {
                                      try {
                                          const data = await omlet.get(url);
                                          console.debug(`get request: ${url},status: ${data.status}`);
                                          return data.data;
                                      } catch (e) {
                                          console.log(e);
                                      }
                                  }
                                  async function postRequest(url) {
                                      try {
                                          const data = await omlet.post(url);
                                          console.debug(`post request: ${url},status: ${data.status}`);
                                          return data.data;
                                      } catch (e) {
                                          console.log(e);
                                      }
                                  }
                                  async function patchRequest(url, data) {
                                      try {
                                          const result = await omlet.patch(url, data);
                                          console.debug(`patch request: ${url},status: ${result.status}`);
                                          return result.data;
                                      } catch (e) {
                                          console.log(e);
                                      }
                                  }
                                  function watchTimeState(id, label) {
                                      on({ id: id, change: 'ne', ack: false }, async (obj) => {
                                          const newVal = String(obj.state.val || '').trim();
                                          const oldVal = obj.oldState && obj.oldState.val != null
                                              ? String(obj.oldState.val)
                                              : '';
                                          if (isValidTime24h(newVal)) {
                                              log(`${label}: gültige Zeit gesetzt -> ${newVal}`, 'debug');
                                              if (id === dp_doortimeopen) {
                                                  await setDoorTimeOpen(outdoorDeviceId, newVal);
                                              }
                                              if (id === dp_doortimeclose) {
                                                  await setDoorTimeClose(outdoorDeviceId, newVal);
                                              }
                                              return;
                                          }
                                          log(`${label}: ungültige Zeit "${newVal}" - setze auf "${oldVal}" zurück`, 'warn');
                                  
                                          // ungültige Eingabe zurücksetzen
                                          setState(id, oldVal, true);
                                      });
                                  }
                                  async function main() {
                                      await connect();
                                      await getDeviceInfo(outdoorDeviceId);
                                      on({ id: dp_door, change: 'ne', ack: false }, async (evt) => {
                                          //log(evt);
                                          if (evt.state.val) {
                                              await doorOpen(outdoorDeviceId);
                                          } else {
                                              await doorClose(outdoorDeviceId);
                                          }
                                      });
                                      on({ id: dp_light, change: 'ne', ack: false }, async (evt) => {
                                          //log(evt);
                                          if (evt.state.val) {
                                              await lightOn(outdoorDeviceId);
                                          } else {
                                              await lightOff(outdoorDeviceId);
                                          }
                                      });
                                      on({ id: dp_doorstop, change: 'any', ack: false }, async (/* evt */) => {
                                          //log(evt);
                                          doorStop(outdoorDeviceId);
                                          setState(dp_doorstop, false, true);
                                      });
                                      watchTimeState(dp_doortimeopen, 'Öffnungszeit');
                                      watchTimeState(dp_doortimeclose, 'Schließzeit');
                                      // await lightOn(outdoorDeviceId);
                                      // await lightOff(outdoorDeviceId);
                                  
                                  }
                                  main();
                                  

                                  für astro hat der iobroker ja bereits ereignisse eingebaut,
                                  wenn die dann aufgerufen werden musst du dann einfach nur die Funktionen doorOpen und doorClose mit der deviceId (die in der Variable outdoorDeviceId steht) aufrufen

                                  Sind die Funktionen soweit verständlich? Brauchst du mehr Detaildokumentation für spätere Anpassungen?

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

                                  1 Antwort Letzte Antwort
                                  1
                                  • J Offline
                                    J Offline
                                    jwerlsdf
                                    schrieb zuletzt editiert von jwerlsdf
                                    #30

                                    Hi, danke für das 2te Skript. FUnktionen sind verständlich. Eine Funktion fehlt mir:

                                        "door": {
                                          "openMode": "manual",
                                          "openDelay": 0,
                                          "openTime": "06:00",
                                          "closeMode": "manual",
                                    

                                    In der APP kann ich beim Türstation zwischen 3 Einstellungen auswählen:
                                    Lichtssensor
                                    Zeit
                                    Manuell.

                                    Aktuell habe ich wie du es siehst auf Manuell gestellt. In den Datenpunkten werden die Uhrzeiten angezeigt. Meine Frau/ Ich wissen aber nicht, ob es nun auf Manuell Zeit... ist.
                                    Kannst du mir noch die FUnktion einbauen, welche aktuelle dieser 3 Funktion ich habe und das ich zwischen diesen drei Umschalten kann?
                                    Dann wäre das Skript für mich perfekt.

                                    OliverIOO 1 Antwort Letzte Antwort
                                    0
                                    • J jwerlsdf

                                      Hi, danke für das 2te Skript. FUnktionen sind verständlich. Eine Funktion fehlt mir:

                                          "door": {
                                            "openMode": "manual",
                                            "openDelay": 0,
                                            "openTime": "06:00",
                                            "closeMode": "manual",
                                      

                                      In der APP kann ich beim Türstation zwischen 3 Einstellungen auswählen:
                                      Lichtssensor
                                      Zeit
                                      Manuell.

                                      Aktuell habe ich wie du es siehst auf Manuell gestellt. In den Datenpunkten werden die Uhrzeiten angezeigt. Meine Frau/ Ich wissen aber nicht, ob es nun auf Manuell Zeit... ist.
                                      Kannst du mir noch die FUnktion einbauen, welche aktuelle dieser 3 Funktion ich habe und das ich zwischen diesen drei Umschalten kann?
                                      Dann wäre das Skript für mich perfekt.

                                      OliverIOO Offline
                                      OliverIOO Offline
                                      OliverIO
                                      schrieb zuletzt editiert von OliverIO
                                      #31

                                      @jwerlsdf

                                      schau mal ob das funktioniert.
                                      schau dir mal die zeilen 68-76 an.
                                      An dieser Stelle wird die Konfiguration des devices gelesen und die Werte in die Datenpunkte geschrieben. Wenn du weitere Datenpunkte benötigst, kannst du die selbst hinzufügen (zumindest wenn du sie nur lesen willst).
                                      Für beschreibbare Datenpunkt muss man etwas mehr aufwand treiben.
                                      Wie der aktuelle Stand der Konfiguration aussieht, kannst du dir im Datenpunkt dp_devicedata anschauen. Da ist configuration ein Unterpunkt. Der wird auch immer aktuell geschrieben

                                      // -- configuration area
                                      const token = 'apitoken';
                                      const outdoorDeviceId = 'laTnMsWSJxBMGgJD';
                                      const dp_light = '0_userdata.0.omlet.light'; // datenpunkt mit typ bool anlegen und namen hier eintragen
                                      const dp_door = '0_userdata.0.omlet.door'; // datenpunkt mit typ bool anlegen und namen hier eintragen
                                      const dp_doorstop = '0_userdata.0.omlet.doorstop'; // datenpunkt mit typ bool und rolle button anlegen und namen hier eintragen
                                      const dp_doortimeopen = '0_userdata.0.omlet.doortimeopen'; // datenpunkt mit typ string, zeit im 24h format im format 06:00 oder 20:30
                                      const dp_doortimeclose = '0_userdata.0.omlet.doortimeclose'; // datenpunkt mit typ string, zeit im 24h format im format 06:00 oder 20:30
                                      const dp_devicedata = '0_userdata.0.omlet.devicedata'; //// datenpunkt mit typ string, hier wird nach jeder aktualisierung der aktuelle device status abgerufen und eingetragen
                                      const dp_doormodeopen = "0_userdata.0.omlet.doormodeopen"; //// datenpunkt mit typ string, hier wird nach jeder aktualisierung der aktuelle device status abgerufen und eingetragen
                                      const dp_doormodeclose = "0_userdata.0.omlet.doormodeclose"; //// datenpunkt mit typ string, hier wird nach jeder aktualisierung der aktuelle device status abgerufen und eingetragen
                                      
                                      // --
                                      
                                      const axios = require("axios/dist/browser/axios.cjs");
                                      const BASE_URL = 'https://x107.omlet.co.uk/api/v1'; //kann hier geprüft werden https://smart.omlet.de/developers/api
                                      let omlet = undefined;
                                      
                                      async function connect() {
                                          console.log("start main2");
                                          omlet = await omletAPIClient(token);
                                          await getDevices(true);
                                      
                                          //console.log(JSON.stringify(await getDevices(), null, 2));
                                      }
                                      async function getDevices(info = false) {
                                          try {
                                              const devices = await getRequest('/device');
                                              if (devices && info) {
                                                  devices.forEach(device => {
                                                      console.log(`Device name: ${device.name}, deviceId: ${device.deviceId}`);
                                                  });
                                              }
                                              return devices;
                                          } catch (error) {
                                              console.log(error);
                                              return [];
                                          }
                                      }
                                      async function getDevice(deviceId) {
                                          try {
                                              const device = await getRequest(`/device/${deviceId}`);
                                              return device;
                                          } catch (error) {
                                              console.log(error);
                                              return {};
                                          }
                                      }
                                      async function getConfiguration(deviceId) {
                                          try {
                                              const configuration = await getRequest(`/device/${deviceId}/configuration`);
                                              return configuration;
                                          } catch (error) {
                                              console.log(error);
                                              return {};
                                          }
                                      }
                                      async function setConfiguration(deviceId, configuration) {
                                          try {
                                              const result = await patchRequest(`/device/${deviceId}/configuration`, configuration);
                                      
                                              return result;
                                          } catch (error) {
                                              console.log(error);
                                              return {};
                                          }
                                      }
                                      async function getDeviceInfo(deviceId) {
                                          const device = await getDevice(deviceId);
                                      
                                          setState(dp_devicedata, JSON.stringify(device, null, 2), true);
                                          setState(dp_doortimeopen, device.configuration.door.openTime, true);
                                          setState(dp_doortimeclose, device.configuration.door.closeTime, true);
                                          setState(dp_doormodeopen, device.configuration.door.openMode, true);
                                          setState(dp_doormodeclose, device.configuration.door.closeMode, true);
                                      }
                                      async function doAction(deviceId, actionName) {
                                          const devices = await getDevices();
                                          const device = devices.find(device => device.deviceId === deviceId);
                                          if (device) {
                                              const action = device.actions.find(action => action.actionName === actionName);
                                              if (action) {
                                                  await postRequest(action.url);
                                                  await getDeviceInfo(outdoorDeviceId);
                                              }
                                          }
                                      }
                                      async function lightOn(deviceId) {
                                          await doAction(deviceId, 'on');
                                      }
                                      async function lightOff(deviceId) {
                                          await doAction(deviceId, 'off');
                                      }
                                      async function doorOpen(deviceId) {
                                          await doAction(deviceId, 'open');
                                      }
                                      async function doorClose(deviceId) {
                                          await doAction(deviceId, 'close');
                                      }
                                      async function doorStop(deviceId) {
                                          await doAction(deviceId, 'stop');
                                      }
                                      async function setDoorTimeClose(deviceId, time) {
                                          const configuration = getConfiguration(deviceId);
                                          const newConfiguration = {
                                              ...configuration,
                                              door: {
                                                  ...configuration.door,
                                                  closeTime: time
                                              }
                                          };
                                          await setConfiguration(deviceId, newConfiguration);
                                          await getDeviceInfo(outdoorDeviceId);
                                      }
                                      async function setDoorTimeOpen(deviceId, time) {
                                          const configuration = getConfiguration(deviceId);
                                          const newConfiguration = {
                                              ...configuration,
                                              door: {
                                                  ...configuration.door,
                                                  openTime: time
                                              }
                                          };
                                          await setConfiguration(deviceId, newConfiguration);
                                          await getDeviceInfo(outdoorDeviceId);
                                      }
                                      function omletAPIClient(token) {
                                          return axios.create({
                                              baseURL: BASE_URL,
                                              headers: {
                                                  'Authorization': `Bearer ${token}`,
                                                  'Content-Type': 'application/json',
                                              },
                                          });
                                      }
                                      function isValidTime24h(value) {
                                          return /^(?:[01]\d|2[0-3]):[0-5]\d$/.test(value);
                                      }
                                      async function getRequest(url) {
                                          try {
                                              const data = await omlet.get(url);
                                              console.debug(`get request: ${url},status: ${data.status}`);
                                              return data.data;
                                          } catch (e) {
                                              console.log(e);
                                          }
                                      }
                                      async function postRequest(url) {
                                          try {
                                              const data = await omlet.post(url);
                                              console.debug(`post request: ${url},status: ${data.status}`);
                                              return data.data;
                                          } catch (e) {
                                              console.log(e);
                                          }
                                      }
                                      async function patchRequest(url, data) {
                                          try {
                                              const result = await omlet.patch(url, data);
                                              console.debug(`patch request: ${url},status: ${result.status}`);
                                              return result.data;
                                          } catch (e) {
                                              console.log(e);
                                          }
                                      }
                                      function watchTimeState(id, label) {
                                          on({ id: id, change: 'ne', ack: false }, async (obj) => {
                                              const newVal = String(obj.state.val || '').trim();
                                              const oldVal = obj.oldState && obj.oldState.val != null
                                                  ? String(obj.oldState.val)
                                                  : '';
                                              if (isValidTime24h(newVal)) {
                                                  log(`${label}: gültige Zeit gesetzt -> ${newVal}`, 'debug');
                                                  if (id === dp_doortimeopen) {
                                                      await setDoorTimeOpen(outdoorDeviceId, newVal);
                                                  }
                                                  if (id === dp_doortimeclose) {
                                                      await setDoorTimeClose(outdoorDeviceId, newVal);
                                                  }
                                                  return;
                                              }
                                              log(`${label}: ungültige Zeit "${newVal}" - setze auf "${oldVal}" zurück`, 'warn');
                                      
                                              // ungültige Eingabe zurücksetzen
                                              setState(id, oldVal, true);
                                          });
                                      }
                                      async function main() {
                                          await connect();
                                          await getDeviceInfo(outdoorDeviceId);
                                          on({ id: dp_door, change: 'ne', ack: false }, async (evt) => {
                                              //log(evt);
                                              if (evt.state.val) {
                                                  await doorOpen(outdoorDeviceId);
                                              } else {
                                                  await doorClose(outdoorDeviceId);
                                              }
                                          });
                                          on({ id: dp_light, change: 'ne', ack: false }, async (evt) => {
                                              //log(evt);
                                              if (evt.state.val) {
                                                  await lightOn(outdoorDeviceId);
                                              } else {
                                                  await lightOff(outdoorDeviceId);
                                              }
                                          });
                                          on({ id: dp_doorstop, change: 'any', ack: false }, async (/* evt */) => {
                                              //log(evt);
                                              doorStop(outdoorDeviceId);
                                              setState(dp_doorstop, false, true);
                                          });
                                          watchTimeState(dp_doortimeopen, 'Öffnungszeit');
                                          watchTimeState(dp_doortimeclose, 'Schließzeit');
                                          // await lightOn(outdoorDeviceId);
                                          // await lightOff(outdoorDeviceId);
                                      
                                      }
                                      main();
                                      

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

                                      1 Antwort Letzte Antwort
                                      0
                                      • J Offline
                                        J Offline
                                        jwerlsdf
                                        schrieb zuletzt editiert von jwerlsdf
                                        #32
                                        // -- configuration area
                                        const token = 'XXXXXXXXXX';
                                        const outdoorDeviceId = 'laTnMsWSJxBMGgJD';
                                        const dp_light = '0_userdata.0.omlet.light'; // datenpunkt mit typ bool anlegen und namen hier eintragen
                                        const dp_door = '0_userdata.0.omlet.door'; // datenpunkt mit typ bool anlegen und namen hier eintragen
                                        const dp_doorstop = '0_userdata.0.omlet.doorstop'; // datenpunkt mit typ bool und rolle button anlegen und namen hier eintragen
                                        const dp_doortimeopen = '0_userdata.0.omlet.doortimeopen'; // datenpunkt mit typ string, zeit im 24h format im format 06:00 oder 20:30
                                        const dp_doortimeclose = '0_userdata.0.omlet.doortimeclose'; // datenpunkt mit typ string, zeit im 24h format im format 06:00 oder 20:30
                                        const dp_devicedata = '0_userdata.0.omlet.devicedata'; //// datenpunkt mit typ string, hier wird nach jeder aktualisierung der aktuelle device status abgerufen und eingetragen
                                        const dp_doormodeopen = "0_userdata.0.omlet.doormodeopen"; //// datenpunkt mit typ string, hier wird nach jeder aktualisierung der aktuelle device status abgerufen und eingetragen
                                        const dp_doormodeclose = "0_userdata.0.omlet.doormodeclose"; //// datenpunkt mit typ string, hier wird nach jeder aktualisierung der aktuelle device status abgerufen und eingetragen
                                        const dp_doorcloseLightLevel = "0_userdata.0.omlet.LightLevelclose"; //// datenpunkt mit typ number
                                        const dp_dooropenLightLevel = "0_userdata.0.omlet.LightLevelopen";  //// datenpunkt mit typ number
                                        const dp_dooropenDelay = "0_userdata.0.omlet.Delayopen";  //// datenpunkt mit typ number
                                        const dp_doorcloseDelay = "0_userdata.0.omlet.Delayclose" //// datenpunkt mit typ number
                                        
                                        
                                        // --
                                         
                                        const axios = require("axios/dist/browser/axios.cjs");
                                        const BASE_URL = 'https://x107.omlet.co.uk/api/v1'; //kann hier geprüft werden https://smart.omlet.de/developers/api
                                        let omlet = undefined;
                                         
                                        async function connect() {
                                            console.log("start main2");
                                            omlet = await omletAPIClient(token);
                                            await getDevices(true);
                                         
                                            //console.log(JSON.stringify(await getDevices(), null, 2));
                                        }
                                        async function getDevices(info = false) {
                                            try {
                                                const devices = await getRequest('/device');
                                                if (devices && info) {
                                                    devices.forEach(device => {
                                                        console.log(`Device name: ${device.name}, deviceId: ${device.deviceId}`);
                                                    });
                                                }
                                                return devices;
                                            } catch (error) {
                                                console.log(error);
                                                return [];
                                            }
                                        }
                                        async function getDevice(deviceId) {
                                            try {
                                                const device = await getRequest(`/device/${deviceId}`);
                                                return device;
                                            } catch (error) {
                                                console.log(error);
                                                return {};
                                            }
                                        }
                                        async function getConfiguration(deviceId) {
                                            try {
                                                const configuration = await getRequest(`/device/${deviceId}/configuration`);
                                                return configuration;
                                            } catch (error) {
                                                console.log(error);
                                                return {};
                                            }
                                        }
                                        async function setConfiguration(deviceId, configuration) {
                                            try {
                                                const result = await patchRequest(`/device/${deviceId}/configuration`, configuration);
                                         
                                                return result;
                                            } catch (error) {
                                                console.log(error);
                                                return {};
                                            }
                                        }
                                        async function getDeviceInfo(deviceId) {
                                            const device = await getDevice(deviceId);
                                         
                                            setState(dp_devicedata, JSON.stringify(device, null, 2), true);
                                            setState(dp_doortimeopen, device.configuration.door.openTime, true);
                                            setState(dp_doortimeclose, device.configuration.door.closeTime, true);
                                            setState(dp_doormodeopen, device.configuration.door.openMode, true);
                                            setState(dp_doormodeclose, device.configuration.door.closeMode, true);
                                            setState(dp_doorcloseLightLevel, device.configuration.door.closeLightLevel, true);
                                            setState(dp_dooropenLightLevel, device.configuration.door.openLightLevel, true);
                                            setState(dp_dooropenDelay, device.configuration.door.openDelay, true);
                                            setState(dp_doorcloseDelay, device.configuration.door.closeDelay, true);
                                        }
                                        async function doAction(deviceId, actionName) {
                                            const devices = await getDevices();
                                            const device = devices.find(device => device.deviceId === deviceId);
                                            if (device) {
                                                const action = device.actions.find(action => action.actionName === actionName);
                                                if (action) {
                                                    await postRequest(action.url);
                                                    await getDeviceInfo(outdoorDeviceId);
                                                }
                                            }
                                        }
                                        async function lightOn(deviceId) {
                                            await doAction(deviceId, 'on');
                                        }
                                        async function lightOff(deviceId) {
                                            await doAction(deviceId, 'off');
                                        }
                                        async function doorOpen(deviceId) {
                                            await doAction(deviceId, 'open');
                                        }
                                        async function doorClose(deviceId) {
                                            await doAction(deviceId, 'close');
                                        }
                                        async function doorStop(deviceId) {
                                            await doAction(deviceId, 'stop');
                                        }
                                        async function setDoorTimeClose(deviceId, time) {
                                            const configuration = getConfiguration(deviceId);
                                            const newConfiguration = {
                                                ...configuration,
                                                door: {
                                                    ...configuration.door,
                                                    closeTime: time
                                                }
                                            };
                                            await setConfiguration(deviceId, newConfiguration);
                                            await getDeviceInfo(outdoorDeviceId);
                                        }
                                        async function setDoorTimeOpen(deviceId, time) {
                                            const configuration = getConfiguration(deviceId);
                                            const newConfiguration = {
                                                ...configuration,
                                                door: {
                                                    ...configuration.door,
                                                    openTime: time
                                                }
                                            };
                                            await setConfiguration(deviceId, newConfiguration);
                                            await getDeviceInfo(outdoorDeviceId);
                                        }
                                        function omletAPIClient(token) {
                                            return axios.create({
                                                baseURL: BASE_URL,
                                                headers: {
                                                    'Authorization': `Bearer ${token}`,
                                                    'Content-Type': 'application/json',
                                                },
                                            });
                                        }
                                        function isValidTime24h(value) {
                                            return /^(?:[01]\d|2[0-3]):[0-5]\d$/.test(value);
                                        }
                                        async function getRequest(url) {
                                            try {
                                                const data = await omlet.get(url);
                                                console.debug(`get request: ${url},status: ${data.status}`);
                                                return data.data;
                                            } catch (e) {
                                                console.log(e);
                                            }
                                        }
                                        async function postRequest(url) {
                                            try {
                                                const data = await omlet.post(url);
                                                console.debug(`post request: ${url},status: ${data.status}`);
                                                return data.data;
                                            } catch (e) {
                                                console.log(e);
                                            }
                                        }
                                        async function patchRequest(url, data) {
                                            try {
                                                const result = await omlet.patch(url, data);
                                                console.debug(`patch request: ${url},status: ${result.status}`);
                                                return result.data;
                                            } catch (e) {
                                                console.log(e);
                                            }
                                        }
                                        function watchTimeState(id, label) {
                                            on({ id: id, change: 'ne', ack: false }, async (obj) => {
                                                const newVal = String(obj.state.val || '').trim();
                                                const oldVal = obj.oldState && obj.oldState.val != null
                                                    ? String(obj.oldState.val)
                                                    : '';
                                                if (isValidTime24h(newVal)) {
                                                    log(`${label}: gültige Zeit gesetzt -> ${newVal}`, 'debug');
                                                    if (id === dp_doortimeopen) {
                                                        await setDoorTimeOpen(outdoorDeviceId, newVal);
                                                    }
                                                    if (id === dp_doortimeclose) {
                                                        await setDoorTimeClose(outdoorDeviceId, newVal);
                                                    }
                                                    return;
                                                }
                                                log(`${label}: ungültige Zeit "${newVal}" - setze auf "${oldVal}" zurück`, 'warn');
                                         
                                                // ungültige Eingabe zurücksetzen
                                                setState(id, oldVal, true);
                                            });
                                        }
                                        async function main() {
                                            await connect();
                                            await getDeviceInfo(outdoorDeviceId);
                                            on({ id: dp_door, change: 'ne', ack: false }, async (evt) => {
                                                //log(evt);
                                                if (evt.state.val) {
                                                    await doorOpen(outdoorDeviceId);
                                                } else {
                                                    await doorClose(outdoorDeviceId);
                                                }
                                            });
                                            on({ id: dp_light, change: 'ne', ack: false }, async (evt) => {
                                                //log(evt);
                                                if (evt.state.val) {
                                                    await lightOn(outdoorDeviceId);
                                                } else {
                                                    await lightOff(outdoorDeviceId);
                                                }
                                            });
                                            on({ id: dp_doorstop, change: 'any', ack: false }, async (/* evt */) => {
                                                //log(evt);
                                                doorStop(outdoorDeviceId);
                                                setState(dp_doorstop, false, true);
                                            });
                                            watchTimeState(dp_doortimeopen, 'Öffnungszeit');
                                            watchTimeState(dp_doortimeclose, 'Schließzeit');
                                            // await lightOn(outdoorDeviceId);
                                            // await lightOff(outdoorDeviceId);
                                         
                                        }
                                        main();
                                        

                                        Hi, habe jetzt noch einmal ein paar Datenpunkte hinzugefügt. Ab wann werden denn die Datenpunkte in beide Richtungen geschrieben? Als ich die Tür über das Skript aufgemacht habe, ging es sofort. Als ich in der APP beispielsweise den Mode von "time" auf "manual" gestellt habe, ging es auch nach 5 Minuten nicht, erst nachdem ch das skript neu gestaret habe.

                                        OliverIOO 1 Antwort Letzte Antwort
                                        0
                                        • J jwerlsdf
                                          // -- configuration area
                                          const token = 'XXXXXXXXXX';
                                          const outdoorDeviceId = 'laTnMsWSJxBMGgJD';
                                          const dp_light = '0_userdata.0.omlet.light'; // datenpunkt mit typ bool anlegen und namen hier eintragen
                                          const dp_door = '0_userdata.0.omlet.door'; // datenpunkt mit typ bool anlegen und namen hier eintragen
                                          const dp_doorstop = '0_userdata.0.omlet.doorstop'; // datenpunkt mit typ bool und rolle button anlegen und namen hier eintragen
                                          const dp_doortimeopen = '0_userdata.0.omlet.doortimeopen'; // datenpunkt mit typ string, zeit im 24h format im format 06:00 oder 20:30
                                          const dp_doortimeclose = '0_userdata.0.omlet.doortimeclose'; // datenpunkt mit typ string, zeit im 24h format im format 06:00 oder 20:30
                                          const dp_devicedata = '0_userdata.0.omlet.devicedata'; //// datenpunkt mit typ string, hier wird nach jeder aktualisierung der aktuelle device status abgerufen und eingetragen
                                          const dp_doormodeopen = "0_userdata.0.omlet.doormodeopen"; //// datenpunkt mit typ string, hier wird nach jeder aktualisierung der aktuelle device status abgerufen und eingetragen
                                          const dp_doormodeclose = "0_userdata.0.omlet.doormodeclose"; //// datenpunkt mit typ string, hier wird nach jeder aktualisierung der aktuelle device status abgerufen und eingetragen
                                          const dp_doorcloseLightLevel = "0_userdata.0.omlet.LightLevelclose"; //// datenpunkt mit typ number
                                          const dp_dooropenLightLevel = "0_userdata.0.omlet.LightLevelopen";  //// datenpunkt mit typ number
                                          const dp_dooropenDelay = "0_userdata.0.omlet.Delayopen";  //// datenpunkt mit typ number
                                          const dp_doorcloseDelay = "0_userdata.0.omlet.Delayclose" //// datenpunkt mit typ number
                                          
                                          
                                          // --
                                           
                                          const axios = require("axios/dist/browser/axios.cjs");
                                          const BASE_URL = 'https://x107.omlet.co.uk/api/v1'; //kann hier geprüft werden https://smart.omlet.de/developers/api
                                          let omlet = undefined;
                                           
                                          async function connect() {
                                              console.log("start main2");
                                              omlet = await omletAPIClient(token);
                                              await getDevices(true);
                                           
                                              //console.log(JSON.stringify(await getDevices(), null, 2));
                                          }
                                          async function getDevices(info = false) {
                                              try {
                                                  const devices = await getRequest('/device');
                                                  if (devices && info) {
                                                      devices.forEach(device => {
                                                          console.log(`Device name: ${device.name}, deviceId: ${device.deviceId}`);
                                                      });
                                                  }
                                                  return devices;
                                              } catch (error) {
                                                  console.log(error);
                                                  return [];
                                              }
                                          }
                                          async function getDevice(deviceId) {
                                              try {
                                                  const device = await getRequest(`/device/${deviceId}`);
                                                  return device;
                                              } catch (error) {
                                                  console.log(error);
                                                  return {};
                                              }
                                          }
                                          async function getConfiguration(deviceId) {
                                              try {
                                                  const configuration = await getRequest(`/device/${deviceId}/configuration`);
                                                  return configuration;
                                              } catch (error) {
                                                  console.log(error);
                                                  return {};
                                              }
                                          }
                                          async function setConfiguration(deviceId, configuration) {
                                              try {
                                                  const result = await patchRequest(`/device/${deviceId}/configuration`, configuration);
                                           
                                                  return result;
                                              } catch (error) {
                                                  console.log(error);
                                                  return {};
                                              }
                                          }
                                          async function getDeviceInfo(deviceId) {
                                              const device = await getDevice(deviceId);
                                           
                                              setState(dp_devicedata, JSON.stringify(device, null, 2), true);
                                              setState(dp_doortimeopen, device.configuration.door.openTime, true);
                                              setState(dp_doortimeclose, device.configuration.door.closeTime, true);
                                              setState(dp_doormodeopen, device.configuration.door.openMode, true);
                                              setState(dp_doormodeclose, device.configuration.door.closeMode, true);
                                              setState(dp_doorcloseLightLevel, device.configuration.door.closeLightLevel, true);
                                              setState(dp_dooropenLightLevel, device.configuration.door.openLightLevel, true);
                                              setState(dp_dooropenDelay, device.configuration.door.openDelay, true);
                                              setState(dp_doorcloseDelay, device.configuration.door.closeDelay, true);
                                          }
                                          async function doAction(deviceId, actionName) {
                                              const devices = await getDevices();
                                              const device = devices.find(device => device.deviceId === deviceId);
                                              if (device) {
                                                  const action = device.actions.find(action => action.actionName === actionName);
                                                  if (action) {
                                                      await postRequest(action.url);
                                                      await getDeviceInfo(outdoorDeviceId);
                                                  }
                                              }
                                          }
                                          async function lightOn(deviceId) {
                                              await doAction(deviceId, 'on');
                                          }
                                          async function lightOff(deviceId) {
                                              await doAction(deviceId, 'off');
                                          }
                                          async function doorOpen(deviceId) {
                                              await doAction(deviceId, 'open');
                                          }
                                          async function doorClose(deviceId) {
                                              await doAction(deviceId, 'close');
                                          }
                                          async function doorStop(deviceId) {
                                              await doAction(deviceId, 'stop');
                                          }
                                          async function setDoorTimeClose(deviceId, time) {
                                              const configuration = getConfiguration(deviceId);
                                              const newConfiguration = {
                                                  ...configuration,
                                                  door: {
                                                      ...configuration.door,
                                                      closeTime: time
                                                  }
                                              };
                                              await setConfiguration(deviceId, newConfiguration);
                                              await getDeviceInfo(outdoorDeviceId);
                                          }
                                          async function setDoorTimeOpen(deviceId, time) {
                                              const configuration = getConfiguration(deviceId);
                                              const newConfiguration = {
                                                  ...configuration,
                                                  door: {
                                                      ...configuration.door,
                                                      openTime: time
                                                  }
                                              };
                                              await setConfiguration(deviceId, newConfiguration);
                                              await getDeviceInfo(outdoorDeviceId);
                                          }
                                          function omletAPIClient(token) {
                                              return axios.create({
                                                  baseURL: BASE_URL,
                                                  headers: {
                                                      'Authorization': `Bearer ${token}`,
                                                      'Content-Type': 'application/json',
                                                  },
                                              });
                                          }
                                          function isValidTime24h(value) {
                                              return /^(?:[01]\d|2[0-3]):[0-5]\d$/.test(value);
                                          }
                                          async function getRequest(url) {
                                              try {
                                                  const data = await omlet.get(url);
                                                  console.debug(`get request: ${url},status: ${data.status}`);
                                                  return data.data;
                                              } catch (e) {
                                                  console.log(e);
                                              }
                                          }
                                          async function postRequest(url) {
                                              try {
                                                  const data = await omlet.post(url);
                                                  console.debug(`post request: ${url},status: ${data.status}`);
                                                  return data.data;
                                              } catch (e) {
                                                  console.log(e);
                                              }
                                          }
                                          async function patchRequest(url, data) {
                                              try {
                                                  const result = await omlet.patch(url, data);
                                                  console.debug(`patch request: ${url},status: ${result.status}`);
                                                  return result.data;
                                              } catch (e) {
                                                  console.log(e);
                                              }
                                          }
                                          function watchTimeState(id, label) {
                                              on({ id: id, change: 'ne', ack: false }, async (obj) => {
                                                  const newVal = String(obj.state.val || '').trim();
                                                  const oldVal = obj.oldState && obj.oldState.val != null
                                                      ? String(obj.oldState.val)
                                                      : '';
                                                  if (isValidTime24h(newVal)) {
                                                      log(`${label}: gültige Zeit gesetzt -> ${newVal}`, 'debug');
                                                      if (id === dp_doortimeopen) {
                                                          await setDoorTimeOpen(outdoorDeviceId, newVal);
                                                      }
                                                      if (id === dp_doortimeclose) {
                                                          await setDoorTimeClose(outdoorDeviceId, newVal);
                                                      }
                                                      return;
                                                  }
                                                  log(`${label}: ungültige Zeit "${newVal}" - setze auf "${oldVal}" zurück`, 'warn');
                                           
                                                  // ungültige Eingabe zurücksetzen
                                                  setState(id, oldVal, true);
                                              });
                                          }
                                          async function main() {
                                              await connect();
                                              await getDeviceInfo(outdoorDeviceId);
                                              on({ id: dp_door, change: 'ne', ack: false }, async (evt) => {
                                                  //log(evt);
                                                  if (evt.state.val) {
                                                      await doorOpen(outdoorDeviceId);
                                                  } else {
                                                      await doorClose(outdoorDeviceId);
                                                  }
                                              });
                                              on({ id: dp_light, change: 'ne', ack: false }, async (evt) => {
                                                  //log(evt);
                                                  if (evt.state.val) {
                                                      await lightOn(outdoorDeviceId);
                                                  } else {
                                                      await lightOff(outdoorDeviceId);
                                                  }
                                              });
                                              on({ id: dp_doorstop, change: 'any', ack: false }, async (/* evt */) => {
                                                  //log(evt);
                                                  doorStop(outdoorDeviceId);
                                                  setState(dp_doorstop, false, true);
                                              });
                                              watchTimeState(dp_doortimeopen, 'Öffnungszeit');
                                              watchTimeState(dp_doortimeclose, 'Schließzeit');
                                              // await lightOn(outdoorDeviceId);
                                              // await lightOff(outdoorDeviceId);
                                           
                                          }
                                          main();
                                          

                                          Hi, habe jetzt noch einmal ein paar Datenpunkte hinzugefügt. Ab wann werden denn die Datenpunkte in beide Richtungen geschrieben? Als ich die Tür über das Skript aufgemacht habe, ging es sofort. Als ich in der APP beispielsweise den Mode von "time" auf "manual" gestellt habe, ging es auch nach 5 Minuten nicht, erst nachdem ch das skript neu gestaret habe.

                                          OliverIOO Offline
                                          OliverIOO Offline
                                          OliverIO
                                          schrieb zuletzt editiert von
                                          #33

                                          @jwerlsdf

                                          hah, glatt vergessen einzubauen.
                                          ich hab dir auch noch einen knopf für manuellen refresh eingebaut. bitte datenpunkt gemäß anweisung anlegen

                                          const token = 'XXXXXXXXXX';
                                          const outdoorDeviceId = 'laTnMsWSJxBMGgJD';
                                          const dp_light = '0_userdata.0.omlet.light'; // datenpunkt mit typ bool anlegen und namen hier eintragen
                                          const dp_door = '0_userdata.0.omlet.door'; // datenpunkt mit typ bool anlegen und namen hier eintragen
                                          const dp_doorstop = '0_userdata.0.omlet.doorstop'; // datenpunkt mit typ bool und rolle button anlegen und namen hier eintragen
                                          const dp_doortimeopen = '0_userdata.0.omlet.doortimeopen'; // datenpunkt mit typ string, zeit im 24h format im format 06:00 oder 20:30
                                          const dp_doortimeclose = '0_userdata.0.omlet.doortimeclose'; // datenpunkt mit typ string, zeit im 24h format im format 06:00 oder 20:30
                                          const dp_devicedata = '0_userdata.0.omlet.devicedata'; //// datenpunkt mit typ string, hier wird nach jeder aktualisierung der aktuelle device status abgerufen und eingetragen
                                          const dp_doormodeopen = "0_userdata.0.omlet.doormodeopen"; //// datenpunkt mit typ string, hier wird nach jeder aktualisierung der aktuelle device status abgerufen und eingetragen
                                          const dp_doormodeclose = "0_userdata.0.omlet.doormodeclose"; //// datenpunkt mit typ string, hier wird nach jeder aktualisierung der aktuelle device status abgerufen und eingetragen
                                          const dp_doorcloseLightLevel = "0_userdata.0.omlet.LightLevelclose"; //// datenpunkt mit typ number
                                          const dp_dooropenLightLevel = "0_userdata.0.omlet.LightLevelopen";  //// datenpunkt mit typ number
                                          const dp_dooropenDelay = "0_userdata.0.omlet.Delayopen";  //// datenpunkt mit typ number
                                          const dp_doorcloseDelay = "0_userdata.0.omlet.Delayclose" //// datenpunkt mit typ number
                                          
                                          const dp_refresh = '0_userdata.0.omlet.refresh'; // datenpunkt mit typ bool und rolle button anlegen und namen hier eintragen
                                          const refreshtime = 5; //time in seconds to refresh data
                                          
                                          // --
                                          
                                          const axios = require("axios/dist/browser/axios.cjs");
                                          const BASE_URL = 'https://x107.omlet.co.uk/api/v1'; //kann hier geprüft werden https://smart.omlet.de/developers/api
                                          let omlet = undefined;
                                          
                                          async function connect() {
                                              console.log("start main2");
                                              omlet = await omletAPIClient(token);
                                              await getDevices(true);
                                          
                                              //console.log(JSON.stringify(await getDevices(), null, 2));
                                          }
                                          async function getDevices(info = false) {
                                              try {
                                                  const devices = await getRequest('/device');
                                                  if (devices && info) {
                                                      devices.forEach(device => {
                                                          console.log(`Device name: ${device.name}, deviceId: ${device.deviceId}`);
                                                      });
                                                  }
                                                  return devices;
                                              } catch (error) {
                                                  console.log(error);
                                                  return [];
                                              }
                                          }
                                          async function getDevice(deviceId) {
                                              try {
                                                  const device = await getRequest(`/device/${deviceId}`);
                                                  return device;
                                              } catch (error) {
                                                  console.log(error);
                                                  return {};
                                              }
                                          }
                                          async function getConfiguration(deviceId) {
                                              try {
                                                  const configuration = await getRequest(`/device/${deviceId}/configuration`);
                                                  return configuration;
                                              } catch (error) {
                                                  console.log(error);
                                                  return {};
                                              }
                                          }
                                          async function setConfiguration(deviceId, configuration) {
                                              try {
                                                  const result = await patchRequest(`/device/${deviceId}/configuration`, configuration);
                                          
                                                  return result;
                                              } catch (error) {
                                                  console.log(error);
                                                  return {};
                                              }
                                          }
                                          async function getDeviceInfo(deviceId) {
                                              const device = await getDevice(deviceId);
                                          
                                              setState(dp_devicedata, JSON.stringify(device, null, 2), true);
                                              setState(dp_doortimeopen, device.configuration.door.openTime, true);
                                              setState(dp_doortimeclose, device.configuration.door.closeTime, true);
                                              setState(dp_doormodeopen, device.configuration.door.openMode, true);
                                              setState(dp_doormodeclose, device.configuration.door.closeMode, true);
                                              setState(dp_doorcloseLightLevel, device.configuration.door.closeLightLevel, true);
                                              setState(dp_dooropenLightLevel, device.configuration.door.openLightLevel, true);
                                              setState(dp_dooropenDelay, device.configuration.door.openDelay, true);
                                              setState(dp_doorcloseDelay, device.configuration.door.closeDelay, true);
                                          }
                                          async function doAction(deviceId, actionName) {
                                              const devices = await getDevices();
                                              const device = devices.find(device => device.deviceId === deviceId);
                                              if (device) {
                                                  const action = device.actions.find(action => action.actionName === actionName);
                                                  if (action) {
                                                      await postRequest(action.url);
                                                      await getDeviceInfo(outdoorDeviceId);
                                                  }
                                              }
                                          }
                                          async function lightOn(deviceId) {
                                              await doAction(deviceId, 'on');
                                          }
                                          async function lightOff(deviceId) {
                                              await doAction(deviceId, 'off');
                                          }
                                          async function doorOpen(deviceId) {
                                              await doAction(deviceId, 'open');
                                          }
                                          async function doorClose(deviceId) {
                                              await doAction(deviceId, 'close');
                                          }
                                          async function doorStop(deviceId) {
                                              await doAction(deviceId, 'stop');
                                          }
                                          async function setDoorTimeClose(deviceId, time) {
                                              const configuration = getConfiguration(deviceId);
                                              const newConfiguration = {
                                                  ...configuration,
                                                  door: {
                                                      ...configuration.door,
                                                      closeTime: time
                                                  }
                                              };
                                              await setConfiguration(deviceId, newConfiguration);
                                              await getDeviceInfo(outdoorDeviceId);
                                          }
                                          async function setDoorTimeOpen(deviceId, time) {
                                              const configuration = getConfiguration(deviceId);
                                              const newConfiguration = {
                                                  ...configuration,
                                                  door: {
                                                      ...configuration.door,
                                                      openTime: time
                                                  }
                                              };
                                              await setConfiguration(deviceId, newConfiguration);
                                              await getDeviceInfo(outdoorDeviceId);
                                          }
                                          function omletAPIClient(token) {
                                              return axios.create({
                                                  baseURL: BASE_URL,
                                                  headers: {
                                                      'Authorization': `Bearer ${token}`,
                                                      'Content-Type': 'application/json',
                                                  },
                                              });
                                          }
                                          function isValidTime24h(value) {
                                              return /^(?:[01]\d|2[0-3]):[0-5]\d$/.test(value);
                                          }
                                          async function getRequest(url) {
                                              try {
                                                  const data = await omlet.get(url);
                                                  console.debug(`get request: ${url},status: ${data.status}`);
                                                  return data.data;
                                              } catch (e) {
                                                  console.log(e);
                                              }
                                          }
                                          async function postRequest(url) {
                                              try {
                                                  const data = await omlet.post(url);
                                                  console.debug(`post request: ${url},status: ${data.status}`);
                                                  return data.data;
                                              } catch (e) {
                                                  console.log(e);
                                              }
                                          }
                                          async function patchRequest(url, data) {
                                              try {
                                                  const result = await omlet.patch(url, data);
                                                  console.debug(`patch request: ${url},status: ${result.status}`);
                                                  return result.data;
                                              } catch (e) {
                                                  console.log(e);
                                              }
                                          }
                                          function watchTimeState(id, label) {
                                              on({ id: id, change: 'ne', ack: false }, async (obj) => {
                                                  const newVal = String(obj.state.val || '').trim();
                                                  const oldVal = obj.oldState && obj.oldState.val != null
                                                      ? String(obj.oldState.val)
                                                      : '';
                                                  if (isValidTime24h(newVal)) {
                                                      log(`${label}: gültige Zeit gesetzt -> ${newVal}`, 'debug');
                                                      if (id === dp_doortimeopen) {
                                                          await setDoorTimeOpen(outdoorDeviceId, newVal);
                                                      }
                                                      if (id === dp_doortimeclose) {
                                                          await setDoorTimeClose(outdoorDeviceId, newVal);
                                                      }
                                                      return;
                                                  }
                                                  log(`${label}: ungültige Zeit "${newVal}" - setze auf "${oldVal}" zurück`, 'warn');
                                          
                                                  // ungültige Eingabe zurücksetzen
                                                  setState(id, oldVal, true);
                                              });
                                          }
                                          async function main() {
                                              await connect();
                                              await getDeviceInfo(outdoorDeviceId);
                                              on({ id: dp_door, change: 'ne', ack: false }, async (evt) => {
                                                  //log(evt);
                                                  if (evt.state.val) {
                                                      await doorOpen(outdoorDeviceId);
                                                  } else {
                                                      await doorClose(outdoorDeviceId);
                                                  }
                                              });
                                              on({ id: dp_light, change: 'ne', ack: false }, async (evt) => {
                                                  //log(evt);
                                                  if (evt.state.val) {
                                                      await lightOn(outdoorDeviceId);
                                                  } else {
                                                      await lightOff(outdoorDeviceId);
                                                  }
                                              });
                                              on({ id: dp_doorstop, change: 'any', ack: false }, async (/* evt */) => {
                                                  //log(evt);
                                                  doorStop(outdoorDeviceId);
                                                  setState(dp_doorstop, false, true);
                                              });
                                              on({ id: dp_refresh, change: 'any', ack: false }, async (/* evt */) => {
                                                  //log(evt);
                                                  await getDeviceInfo(outdoorDeviceId);
                                                  setState(dp_refresh, false, true);
                                              });
                                              watchTimeState(dp_doortimeopen, 'Öffnungszeit');
                                              watchTimeState(dp_doortimeclose, 'Schließzeit');
                                              schedule(`*/${refreshtime} * * * *`, () => {
                                                  log('Will be triggered every 2 minutes!');
                                              });
                                              // await lightOn(outdoorDeviceId);
                                              // await lightOff(outdoorDeviceId);
                                          
                                          }
                                          main();
                                          

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

                                          1 Antwort Letzte Antwort
                                          0
                                          Antworten
                                          • In einem neuen Thema antworten
                                          Anmelden zum Antworten
                                          • Älteste zuerst
                                          • Neuste zuerst
                                          • Meiste Stimmen


                                          Support us

                                          ioBroker
                                          Community Adapters
                                          Donate

                                          230

                                          Online

                                          32.7k

                                          Benutzer

                                          82.5k

                                          Themen

                                          1.3m

                                          Beiträge
                                          Community
                                          Impressum | Datenschutz-Bestimmungen | Nutzungsbedingungen | Einwilligungseinstellungen
                                          ioBroker Community 2014-2025
                                          logo
                                          • Anmelden

                                          • Du hast noch kein Konto? Registrieren

                                          • Anmelden oder registrieren, um zu suchen
                                          • Erster Beitrag
                                            Letzter Beitrag
                                          0
                                          • Home
                                          • Aktuell
                                          • Tags
                                          • Ungelesen 0
                                          • Kategorien
                                          • Unreplied
                                          • Beliebt
                                          • GitHub
                                          • Docu
                                          • Hilfe