Navigation

    Logo
    • Register
    • Login
    • Search
    • Recent
    • Tags
    • Unread
    • Categories
    • Unreplied
    • Popular
    • GitHub
    • Docu
    • Hilfe
    1. Home
    2. Deutsch
    3. Skripten / Logik
    4. JavaScript
    5. Javascript für CURL Aufruf

    NEWS

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

    • ioBroker goes Matter ... Matter Adapter in Stable

    • Monatsrückblick - April 2025

    Javascript für CURL Aufruf

    This topic has been deleted. Only users with topic management privileges can see it.
    • cash
      cash Most Active last edited by cash

      Ich bräuchte da mal etwas Hilfe. Ich bekomme Morgen eine Elgato Key Ligtht Air. Das ist eine Videoleuchte die per WLAN im Netz hängt. Ich will das Licht für die Beleuchtung meines Schreibtisches nutzen und falls nötig auch mal als Videolicht.

      Ich habe im Netz gefunden, dass man das Licht über eine Rest Api steuern kann. Dort gibt es eine Anleitung damit man das ganze in die Touchbar vom Mac bekommt. Ich möchte das natürlich über ioBroker steuern.
      Das Licht soll dann Morgens bei Arbeitsbeginn automatisch angehen.

      Für die besagte Anleitung Anleitung soll man eine Datei erstellen elgato-on.sh
      Inhalt:

      #!/bin/bash
      curl --location --request PUT 'http://<your lights ip>:9123/elgato/lights' \
      --header 'Content-Type: application/json' \
      --data-raw '{"lights":[{"brightness":10,"temperature":162,"on":1}],"numberOfLights":1}'
      

      Daraus will ich ein Javascript basteln. Nur weiß ich leider nicht wie. Ich habe so etwas ähnliches für eine Foscam

      **************************
      * Schaltet die Elgato Key Light Air 
      *
      * 29.01.21 V1.00    Erste Version
      
      **************************/
      var logging = true;
      var URL;
      
      function func_Elagto_an(){
          
              URL = "http://192.168.178.230:9123/elgato/lights";
             
              request.get(URL).on('error', function(error){
                  if(error){
                      log(error, 'error');
                  }
              });
              
              if(logging){       
                  log('Elgato Key Light Air wurde eingeschaltet.');
              }
             
      
      
      }
      

      Wie bekommt man den Header bzw data-raw in die url übergeben?

      Alternativ habe ich noch diese Hinweise gefunden:

      After doing some exploration, I discovered that the Key Light Air devices actually have a web server built in, exposing a REST API.

      Key Light Air has an HTTP listener on TCP 9123
      An HTTP API is available at /elgato/lights
      The “lights” API accepts a payload (body) with several parameters

      Here’s an example of what the JSON payload looks like for controlling the Elgato Key Light Air.

      {
        "Lights": [
          {
            "Temperature": 344,
            "Brightness": 100,
            "On": 1
          }
        ],
        "NumberOfLights": 1
      }
      

      Through some trial and error, I discovered that:

      Brightness can only be set to a value between 3 and 100
      The color temperature field can be 143 (7000K) to 344 (2900K)

      On is either 0 or 1, depending on whether you want to switch the light on or off

      Würde mich freuen wenn mir jemand helfen kann.

      Grüße

      cash 1 Reply Last reply Reply Quote 0
      • cash
        cash Most Active @cash last edited by

        So Lampe ist heute gekommen. Was ich bisher geschafft habe:

        function func_Elagto_an(){
            
                URL = "http://192.168.178.75:9123/elgato/lights";
               
            request({url : URL},
                function (error, response, body) {
                    
                    
                    if(error){
                        log('error: ' + error);
                    } else {
                    const Inhalt = body.split(",");
                    const on = Inhalt[1].split(":") 
                    const brightness = Inhalt[2].split(":")    
                    const temperature = Inhalt[3].split(":")   
                     
                    log(typeof(temperature[1]));
                    log('ON: ' +on[2]);
                    log('Brightness: ' +brightness[1]);
                    log('Temperatur: ' +temperature[1]);
                        
                            log('body: ' + body);
                            
                            //log('response: ' + JSON.stringify(response));
                        
                    }
                }
            );
                
               
        
        
        }
        

        Als Log kommt

        javascript.2	2021-01-30 15:47:42.057	info	(787) script.js.Büro.Videolicht: Temperatur: 186}]}
        javascript.2	2021-01-30 15:47:42.057	info	(787) script.js.Büro.Videolicht: Brightness: 63
        javascript.2	2021-01-30 15:47:42.056	info	(787) script.js.Büro.Videolicht: ON: 0
        javascript.2	2021-01-30 15:47:42.056	info	(787) script.js.Büro.Videolicht: string
        

        Jetzt muss ich nur noch irgendwie nicht nur die Antwort empfangen sondern auch etwas senden.

        cash 1 Reply Last reply Reply Quote 0
        • cash
          cash Most Active @cash last edited by

          Quick & Dirty habe ich es jetzt hinbekommen. Ich habe die sh Datei ins ioBroker Verzeichnis kopiert

          function func_elgato_on(){
              exec('bash elgato_on.sh');
              
            
          }
          

          Gefällt mir zwar irgendwie nicht so gut aber für den Anfang reicht es. Falls hier noch jemand eine Lösung für mich hat würde ich mich freuen

          E 1 Reply Last reply Reply Quote 0
          • E
            Eric @cash last edited by

            @cash Wärest Du so nett den Inhalt Deiner sh Datei zu teilen? Das wäre großartig.

            cash 1 Reply Last reply Reply Quote 0
            • cash
              cash Most Active @Eric last edited by

              @eric ??? Den Inhalt der sh-Datei habe ich im ersten Post erwähnt. Mittlerweile erledige ich das ganze aber komplett über Javascript mit axios. Dazu habe ich hier auch einen Thread eröffnet ebenfalls mit dem fertigen Javascript zum steuern.

              E 1 Reply Last reply Reply Quote 0
              • E
                Eric @cash last edited by

                @cash Danke vielmals! Hatte es in der Tat übersehen. Sorry. Ich schaue mir auch Deinen anderen Thread an und gebe Bescheid falls ich auch noch etwas beitragen kann 🙂

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

                Support us

                ioBroker
                Community Adapters
                Donate

                1.1k
                Online

                31.7k
                Users

                79.7k
                Topics

                1.3m
                Posts

                2
                6
                751
                Loading More Posts
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes
                Reply
                • Reply as topic
                Log in to reply
                Community
                Impressum | Datenschutz-Bestimmungen | Nutzungsbedingungen
                The ioBroker Community 2014-2023
                logo