Weiter zum Inhalt
  • Home
  • Aktuell
  • 0 Ungelesen 0
  • Kategorien
  • Unreplied
  • Beliebt
  • GitHub
  • Docu
  • Hilfe
Skins
  • Hell
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dunkel
  • 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

  • Neue Adresse: die ioBroker-Webseite liegt jetzt auf iobroker.com
    BluefoxB
    Bluefox
    3
    1
    159

  • Die neue ioBroker Webseite ist online!
    BluefoxB
    Bluefox
    11
    1
    187

  • Information zum Kontoabgleich und zur Namensänderung
    BluefoxB
    Bluefox
    11
    1
    505

Omlet Hühnerstall webhook API

Geplant Angeheftet Gesperrt Verschoben JavaScript
43 Beiträge 4 Kommentatoren 4.1k Aufrufe 3 Beobachtet
  • Ä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
    J
    jwerlsdf
    schrieb am zuletzt editiert von
    #34

    Dank dir. Werde ich in den nächsten Tagen testen.

    OliverIOO 1 Antwort Letzte Antwort
    0
    • J jwerlsdf

      Dank dir. Werde ich in den nächsten Tagen testen.

      OliverIOO
      OliverIOO
      OliverIO
      schrieb am zuletzt editiert von OliverIO
      #35

      @jwerlsdf

      Klappe den alles? Habe keine Rückmeldung mehr gelesen

      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
        J
        jwerlsdf
        schrieb am zuletzt editiert von
        #36

        Hi, aktuell was ich beobachtet habe, ja. Die Rückmeldung wollte ich erst geben, wenn ich den Futterautomat erhalten habe, der aber bisher noch nicht geliefert wurde. Auch diesen kann man mittels API einbinden. Sollte es bei der Einbindung Probleme geben, melde ih mich noch mal, ansonsten aber auch so.

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

          @oliverio

          // -- configuration area
          const token = 'TTTTTTTTT';
          const outdoorDeviceId = 'XXXXX'; //outdoor
          //const feederDeviceId = 'YYYYYYYYY'; //feeder
          
          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();
          

          OliverIOO 1 Antwort Letzte Antwort
          1
          • J jwerlsdf

            @oliverio

            // -- configuration area
            const token = 'TTTTTTTTT';
            const outdoorDeviceId = 'XXXXX'; //outdoor
            //const feederDeviceId = 'YYYYYYYYY'; //feeder
            
            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();
            

            OliverIOO
            OliverIOO
            OliverIO
            schrieb am zuletzt editiert von
            #38

            @jwerlsdf

            wahrscheinlich sind wir noch nicht fertig, aber die erste stufe ist schon mal da.
            das skript wurde (mithilfe von KI) soweit umgestellt, das du keine device id mehr heraussuchen musst. das skript ruft einfach die informationen ab und legt die datenpunkte je device an.
            die informationen werden dann alle 5 sekunden aktualisiert.
            prüfe bitte mal, ob die informationen alle so sinnvoll sind.
            auch ob die angelegten datenpunkte für den einzelnen device typ passen.
            prüfe auch ob die steuerung noch so funktioniert. das kann ich hier schlecht ausprobieren.

            da das skript den befehl setObjekt zum anlegen von Datenpunkte verwendet musst du in den adapter einstellungen des javascript adapters die folgende option setzen
            640812c3-4bac-4a02-be9f-77954a692c44-image.jpeg

            const token = "xxx";
            
            const BASE_DP = "0_userdata.0.omlet";
            const refreshtime = 5; // Sekunden
            
            const axios = require("axios");
            const BASE_URL = "https://x107.omlet.co.uk/api/v1";
            
            let omlet;
            const initializedDevices = new Set();
            
            function cleanId(input) {
              return String(input || "unknown")
                .normalize("NFD")
                .replace(/[\u0300-\u036f]/g, "")
                .replace(/[^a-zA-Z0-9_]+/g, "_")
                .replace(/_+/g, "_")
                .replace(/^_+|_+$/g, "");
            }
            
            function getDeviceBase(device) {
              return `${BASE_DP}.${cleanId(device.name)}`;
            }
            
            function getType(value) {
              if (typeof value === "boolean") return "boolean";
              if (typeof value === "number") return "number";
              return "string";
            }
            
            async function ensureFolder(id, name) {
              if (!existsObject(id)) {
                setObject(id, {
                  type: "folder",
                  common: { name },
                  native: {},
                });
              }
            }
            
            async function ensureState(id, value, common) {
              if (!existsObject(id)) {
                await createStateAsync(id, value, common);
              }
            }
            
            async function ensureDeviceDatapoints(device) {
              const base = getDeviceBase(device);
            
              await ensureFolder(BASE_DP, "Omlet");
              await ensureFolder(base, device.name);
            
              await ensureState(`${base}.devicedata`, "", {
                name: "Device JSON Daten",
                type: "string",
                role: "json",
                read: true,
                write: false,
              });
            
              await ensureState(`${base}.refresh`, false, {
                name: "Refresh",
                type: "boolean",
                role: "button",
                read: true,
                write: true,
              });
            
              await ensureState(`${base}.door`, false, {
                name: "Tür / Klappe öffnen oder schließen",
                type: "boolean",
                role: "switch",
                read: true,
                write: true,
              });
            
              await ensureState(`${base}.doorstop`, false, {
                name: "Tür / Klappe stoppen",
                type: "boolean",
                role: "button",
                read: true,
                write: true,
              });
            
              const hasLight = Array.isArray(device.actions) &&
                device.actions.some(a => a.actionName === "on" || a.actionName === "off");
            
              if (hasLight) {
                await ensureState(`${base}.light`, false, {
                  name: "Licht",
                  type: "boolean",
                  role: "switch",
                  read: true,
                  write: true,
                });
              }
            
              if (device.configuration && device.configuration.door) {
                await ensureDoorConfigurationDatapoints(base);
              }
            }
            
            async function ensureDoorConfigurationDatapoints(base) {
              await ensureState(`${base}.doortimeopen`, "", {
                name: "Öffnungszeit",
                type: "string",
                role: "text",
                read: true,
                write: true,
              });
            
              await ensureState(`${base}.doortimeclose`, "", {
                name: "Schließzeit",
                type: "string",
                role: "text",
                read: true,
                write: true,
              });
            
              await ensureState(`${base}.doormodeopen`, "", {
                name: "Öffnungsmodus",
                type: "string",
                role: "text",
                read: true,
                write: true,
              });
            
              await ensureState(`${base}.doormodeclose`, "", {
                name: "Schließmodus",
                type: "string",
                role: "text",
                read: true,
                write: true,
              });
            
              await ensureState(`${base}.LightLevelclose`, 0, {
                name: "Schließen bei Lichtwert",
                type: "number",
                role: "value",
                read: true,
                write: true,
              });
            
              await ensureState(`${base}.LightLevelopen`, 0, {
                name: "Öffnen bei Lichtwert",
                type: "number",
                role: "value",
                read: true,
                write: true,
              });
            
              await ensureState(`${base}.Delayopen`, 0, {
                name: "Öffnungsverzögerung",
                type: "number",
                role: "value",
                read: true,
                write: true,
              });
            
              await ensureState(`${base}.Delayclose`, 0, {
                name: "Schließverzögerung",
                type: "number",
                role: "value",
                read: true,
                write: true,
              });
            }
            
            async function updateDeviceDatapoints(device) {
              const base = getDeviceBase(device);
            
              await setStateAsync(`${base}.devicedata`, JSON.stringify(device, null, 2), true);
            
              if (device.state && device.state.door && device.state.door.state) {
                await setStateAsync(`${base}.door`, device.state.door.state === "open", true);
              }
            
              if (device.state && device.state.feeder && device.state.feeder.state) {
                await setStateAsync(`${base}.door`, device.state.feeder.state === "open", true);
              }
            
              if (existsObject(`${base}.light`) && device.state && device.state.light && device.state.light.state) {
                await setStateAsync(`${base}.light`, device.state.light.state === "on", true);
              }
            
              if (device.configuration && device.configuration.door) {
                const door = device.configuration.door;
            
                await setStateAsync(`${base}.doortimeopen`, door.openTime || "", true);
                await setStateAsync(`${base}.doortimeclose`, door.closeTime || "", true);
                await setStateAsync(`${base}.doormodeopen`, door.openMode || "", true);
                await setStateAsync(`${base}.doormodeclose`, door.closeMode || "", true);
                await setStateAsync(`${base}.LightLevelclose`, door.closeLightLevel ?? 0, true);
                await setStateAsync(`${base}.LightLevelopen`, door.openLightLevel ?? 0, true);
                await setStateAsync(`${base}.Delayopen`, door.openDelay ?? 0, true);
                await setStateAsync(`${base}.Delayclose`, door.closeDelay ?? 0, true);
              }
            }
            
            async function refreshDevice(deviceId) {
              const device = await getDevice(deviceId);
            
              if (!device || !device.deviceId) return;
            
              await ensureDeviceDatapoints(device);
              await updateDeviceDatapoints(device);
            }
            
            async function refreshAllDevices() {
              const devices = await getDevices();
            
              for (const device of devices) {
                await refreshDevice(device.deviceId);
              }
            }
            
            function isValidTime24h(value) {
              return /^(?:[01]\d|2[0-3]):[0-5]\d$/.test(String(value));
            }
            
            async function updateDoorConfiguration(deviceId, key, value) {
              const configuration = await getConfiguration(deviceId);
            
              if (!configuration || !configuration.door) return;
            
              configuration.door[key] = value;
            
              await setConfiguration(deviceId, configuration);
              await refreshDevice(deviceId);
            }
            
            function setupDeviceWatcher(device) {
              const base = getDeviceBase(device);
            
              if (initializedDevices.has(device.deviceId)) return;
              initializedDevices.add(device.deviceId);
            
              on({ id: `${base}.door`, change: "ne", ack: false }, async evt => {
                if (evt.state.val) {
                  await doAction(device.deviceId, "open");
                } else {
                  await doAction(device.deviceId, "close");
                }
            
                await refreshDevice(device.deviceId);
              });
            
              if (existsObject(`${base}.light`)) {
                on({ id: `${base}.light`, change: "ne", ack: false }, async evt => {
                  if (evt.state.val) {
                    await doAction(device.deviceId, "on");
                  } else {
                    await doAction(device.deviceId, "off");
                  }
            
                  await refreshDevice(device.deviceId);
                });
              }
            
              on({ id: `${base}.doorstop`, change: "any", ack: false }, async () => {
                await doAction(device.deviceId, "stop");
                await setStateAsync(`${base}.doorstop`, false, true);
                await refreshDevice(device.deviceId);
              });
            
              on({ id: `${base}.refresh`, change: "any", ack: false }, async () => {
                await refreshDevice(device.deviceId);
                await setStateAsync(`${base}.refresh`, false, true);
              });
            
              if (device.configuration && device.configuration.door) {
                watchDoorConfiguration(device, base);
              }
            
              log(`Omlet Watcher angelegt: ${device.name} (${device.deviceId})`);
            }
            
            function watchDoorConfiguration(device, base) {
              on({ id: `${base}.doortimeopen`, change: "ne", ack: false }, async evt => {
                const value = String(evt.state.val || "").trim();
            
                if (!isValidTime24h(value)) {
                  log(`Ungültige Öffnungszeit: ${value}`, "warn");
                  await refreshDevice(device.deviceId);
                  return;
                }
            
                await updateDoorConfiguration(device.deviceId, "openTime", value);
              });
            
              on({ id: `${base}.doortimeclose`, change: "ne", ack: false }, async evt => {
                const value = String(evt.state.val || "").trim();
            
                if (!isValidTime24h(value)) {
                  log(`Ungültige Schließzeit: ${value}`, "warn");
                  await refreshDevice(device.deviceId);
                  return;
                }
            
                await updateDoorConfiguration(device.deviceId, "closeTime", value);
              });
            
              on({ id: `${base}.doormodeopen`, change: "ne", ack: false }, async evt => {
                await updateDoorConfiguration(device.deviceId, "openMode", String(evt.state.val));
              });
            
              on({ id: `${base}.doormodeclose`, change: "ne", ack: false }, async evt => {
                await updateDoorConfiguration(device.deviceId, "closeMode", String(evt.state.val));
              });
            
              on({ id: `${base}.LightLevelclose`, change: "ne", ack: false }, async evt => {
                await updateDoorConfiguration(device.deviceId, "closeLightLevel", Number(evt.state.val));
              });
            
              on({ id: `${base}.LightLevelopen`, change: "ne", ack: false }, async evt => {
                await updateDoorConfiguration(device.deviceId, "openLightLevel", Number(evt.state.val));
              });
            
              on({ id: `${base}.Delayopen`, change: "ne", ack: false }, async evt => {
                await updateDoorConfiguration(device.deviceId, "openDelay", Number(evt.state.val));
              });
            
              on({ id: `${base}.Delayclose`, change: "ne", ack: false }, async evt => {
                await updateDoorConfiguration(device.deviceId, "closeDelay", Number(evt.state.val));
              });
            }
            
            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 {
                return await getRequest(`/device/${deviceId}`);
              } catch (error) {
                console.log(error);
                return {};
              }
            }
            
            async function getConfiguration(deviceId) {
              try {
                return await getRequest(`/device/${deviceId}/configuration`);
              } catch (error) {
                console.log(error);
                return {};
              }
            }
            
            async function setConfiguration(deviceId, configuration) {
              try {
                return await patchRequest(`/device/${deviceId}/configuration`, configuration);
              } catch (error) {
                console.log(error);
                return {};
              }
            }
            
            async function doAction(deviceId, actionName) {
              const device = await getDevice(deviceId);
            
              if (!device || !Array.isArray(device.actions)) return;
            
              const action = device.actions.find(a => a.actionName === actionName);
            
              if (!action) {
                log(`Aktion "${actionName}" für Gerät "${device.name}" nicht verfügbar`, "warn");
                return;
              }
            
              log(`Omlet Aktion: ${device.name} -> ${actionName}`);
              await postRequest(action.url);
            }
            
            function omletAPIClient(token) {
              return axios.create({
                baseURL: BASE_URL,
                headers: {
                  Authorization: `Bearer ${token}`,
                  "Content-Type": "application/json",
                },
              });
            }
            
            async function getRequest(url) {
              const data = await omlet.get(url);
              console.debug(`get request: ${url}, status: ${data.status}`);
              return data.data;
            }
            
            async function postRequest(url) {
              const data = await omlet.post(url);
              console.debug(`post request: ${url}, status: ${data.status}`);
              return data.data;
            }
            
            async function patchRequest(url, data) {
              const result = await omlet.patch(url, data);
              console.debug(`patch request: ${url}, status: ${result.status}`);
              return result.data;
            }
            
            async function main() {
              omlet = omletAPIClient(token);
            
              await refreshAllDevices();
            
              const devices = await getDevices(true);
            
              for (const device of devices) {
                const fullDevice = await getDevice(device.deviceId);
                await ensureDeviceDatapoints(fullDevice);
                setupDeviceWatcher(fullDevice);
              }
            
              setInterval(async () => {
                await refreshAllDevices();
              }, refreshtime * 1000);
            }
            
            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
              J
              jwerlsdf
              schrieb am zuletzt editiert von
              #39

              ok, skript importiert und es kommen daten bereits rein. Er baut auch die Struktur 1 Baum (omlet) mit zwei Zweigen (Devices) auf. Die Struktur von der Tür scheint auf den ersten Blick ok zu sein.
              Die Struktur des Feeders ist falsch:
              Es gibt 4 Datenpunkte:

              1. devicedata ist korrekt und es kommen wichtige Daten rein.
                2-4 ist falsch: Door, Doorstop, refresh (wobei refesh könnte man als manuellen anstoß drinnen lassen)
              OliverIOO 1 Antwort Letzte Antwort
              0
              • J jwerlsdf

                ok, skript importiert und es kommen daten bereits rein. Er baut auch die Struktur 1 Baum (omlet) mit zwei Zweigen (Devices) auf. Die Struktur von der Tür scheint auf den ersten Blick ok zu sein.
                Die Struktur des Feeders ist falsch:
                Es gibt 4 Datenpunkte:

                1. devicedata ist korrekt und es kommen wichtige Daten rein.
                  2-4 ist falsch: Door, Doorstop, refresh (wobei refesh könnte man als manuellen anstoß drinnen lassen)
                OliverIOO
                OliverIOO
                OliverIO
                schrieb am zuletzt editiert von
                #40

                @jwerlsdf sagte:

                2-4 ist falsch: Door, Doorstop, refresh (wobei refesh könnte man als manuellen anstoß drinnen lassen)

                dann bitte mir korrekt vorschlagen.
                die geräte die du da hast sind für mich abstrakt
                und bestehen aktuell nur aus den daten.

                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
                  J
                  jwerlsdf
                  schrieb am zuletzt editiert von
                  #41

                  Futterklappen zu
                  
                       "actionName": "close",
                       "description": "Close Feeder",
                       "actionValue": "close",
                       "pendingValue": "closepending",
                       "
                       "url": "/device/XXXXXXXXXXXX/action/close"
                     },
                  
                  Futterklappen auf
                     {
                       "actionName": "open",
                       "description": "Open Feeder",
                       "actionValue": "open",
                       "pendingValue": "openpending",
                       
                       "url": "/device/XXXXXXXXXXXX/action/open"
                     },
                  
                  
                     "feeder": {
                     
                  Modus (Lichtsensor/ Zeit):
                  Lichtsensor: 
                       "mode": "light",
                       "openLightLevel": 27,
                       "closeLightLevel": 6,
                       
                  Zeit: 
                  Modus: Zeit:
                       "openTime1": "06:30",
                       "closeTime1": "19:00",
                       
                       
                  
                  Batteriestatus + WLan Verbindung
                  
                   "state": {
                     "general": {
                       "batteryLevel": 80,
                       "powerSource": "battery",
                  
                     },
                     "connectivity": {
                       "connected": false
                       
                  
                  aktuelle Status Gesamtübersicht
                     },
                     "feeder": {
                       "state": "open // Futterklappen
                       "fault": "blocked", // Warnhinweise
                       "feedLevel": 34, //Füllstand
                       "lightLevel": 100,//Lichtstatus
                       "mode": "faulted" //MOdus Warnhinweise ???
                     }
                   },
                   "remainingDays": 3, //verbleibende Tage bis das Futter leer ist
                  
                  Hühnerzahl -und Größe sowie Futtermittel
                  
                  "meta": {
                     "feed_type": "crumb",
                     "large_chicken_count": "4",
                     "medium_chicken_count": "0",
                     "small_chicken_count": "0"
                     
                     
                  
                  

                  Ich habe dir nun alles rausgesucht bzw. unnötiges rausgestrichen. Reicht dir das?

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

                    Hallo, anbei das nun fertige Skript im ersten Post.

                    1 Antwort Letzte Antwort
                    0
                    • S
                      S
                      skinni
                      schrieb am zuletzt editiert von
                      #43

                      Funzt astrein, vielen Dank für die Arbeit!

                      1 Antwort Letzte Antwort
                      0

                      Hey! Du scheinst an dieser Unterhaltung interessiert zu sein, hast aber noch kein Konto.

                      Hast du es satt, bei jedem Besuch durch die gleichen Beiträge zu scrollen? Wenn du dich für ein Konto anmeldest, kommst du immer genau dorthin zurück, wo du zuvor warst, und kannst dich über neue Antworten benachrichtigen lassen (entweder per E-Mail oder Push-Benachrichtigung). Du kannst auch Lesezeichen speichern und Beiträge positiv bewerten, um anderen Community-Mitgliedern deine Wertschätzung zu zeigen.

                      Mit deinem Input könnte dieser Beitrag noch besser werden 💗

                      Registrieren Anmelden
                      Antworten
                      • In einem neuen Thema antworten
                      Anmelden zum Antworten
                      • Älteste zuerst
                      • Neuste zuerst
                      • Meiste Stimmen


                      Support us

                      ioBroker
                      Community Adapters
                      Donate

                      245

                      Online

                      33.1k

                      Benutzende

                      83.8k

                      Themen

                      1.4m

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

                      • Du hast noch kein Konto? Registrieren

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