+ Antworten
Ergebnis 1 bis 7 von 7
  1. #1
    Registriert seit
    Jan 2010
    Ort
    Österreich/Linz/St. Florian
    Beiträge
    199

    Standard Smarter Raumduft Moodo

    Hallo

    Hat jemand schon Moodo Smart Aroma Diffuser in Verwendung bzw in IPS integriert?
    Ist aktuell im Angebot und überlege ihn zu bestellen

    Danke
    Alex
    FS 20FHZ 1300, Zigbee Xiaomi Wassermelder, DMX, 1Wire, HM Wired und Funk, Dell Win7 IPS Unlimited, IPS-View, 3xiPad 1, 1x iPad4, mehrere HD Kameras, Alexa´s

  2. #2
    Registriert seit
    Sep 2016
    Ort
    Münsingen (CH)
    Beiträge
    44

    Ich habe mir so ein Teil zugelegt. Bin ich begeistert von dem Teil. Die 4 Venti lassen sich einzeln regeln somit riechts jedes mal etwas anders.

    Anbei mein Skript.
    Die Daten von der API abholen funktioniert. Senden "noch" nicht (stosse an meine Programmierkentnisse).
    Klicken Sie auf die Grafik für eine größere Ansicht 

Name:	Bildschirmfoto 2019-01-13 um 09.57.55.jpg 
Hits:	79 
Größe:	166.6 KB 
ID:	47304
    Klicken Sie auf die Grafik für eine größere Ansicht 

Name:	Bildschirmfoto 2019-01-13 um 09.56.50.jpg 
Hits:	97 
Größe:	173.2 KB 
ID:	47305

    [PHP]
    <?
    // A sample PHP Script to POST data using cURL
    // saschild 13.1.19
    $email = 'EMAILADRESSE'; //Hier email eintragen
    $password =PASSWORT'; // Hier Passwort eintragen

    $url = "https://rest.moodo.co/api";
    $data = array(
    'email' => $email,
    'password' => $password
    );

    $payload = json_encode($data);

    // Prepare new cURL resource
    $ch = curl_init($url . "/login");
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLINFO_HEADER_OUT, true);
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);

    // Set HTTP Header for POST request
    curl_setopt($ch, CURLOPT_HTTPHEADER, array(
    'Content-Type: application/json',
    'Content-Length: ' . strlen($payload))
    );


    // Submit the POST request
    $result = curl_exec($ch);
    //print $result;
    $sessionToken = substr($result, 10, -2);
    //print $sessionToken;
    // Close cURL session handle
    curl_close($ch);


    # An HTTP GET request example


    $ch = curl_init($url . "/boxes");
    curl_setopt($ch, CURLOPT_TIMEOUT, 5);
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    // Set HTTP Header for POST request
    curl_setopt($ch, CURLOPT_HTTPHEADER, array(
    'Content-Type: application/json',
    'token: ' . ($sessionToken))
    );
    $data = curl_exec($ch);
    curl_close($ch);
    //echo $data;
    $json = json_decode($data);
    // alle Variablen ID anpassen
    SetValueString(44537, $json->boxes[0]->settings[0]->capsule_info->title);
    SetValueInteger(50833, $json->boxes[0]->settings[0]->fan_speed);
    SetValueInteger(20507, hexdec($json->boxes[0]->settings[0]->capsule_info->color)); // HEX-Color Profil
    SetValueString(51732, $json->boxes[0]->settings[1]->capsule_info->title);
    SetValueInteger(58790, $json->boxes[0]->settings[1]->fan_speed);
    SetValueInteger(18093, hexdec($json->boxes[0]->settings[1]->capsule_info->color)); // HEX-Color Profil
    SetValueString(50380, $json->boxes[0]->settings[2]->capsule_info->title);
    SetValueInteger(11661, $json->boxes[0]->settings[2]->fan_speed);
    SetValueInteger(58567, hexdec($json->boxes[0]->settings[2]->capsule_info->color)); // HEX-Color Profil
    SetValueString(44190, $json->boxes[0]->settings[3]->capsule_info->title);
    SetValueInteger(54194, $json->boxes[0]->settings[3]->fan_speed);
    SetValueInteger(54350, hexdec($json->boxes[0]->settings[3]->capsule_info->color)); // HEX-Color Profil
    SetValueBoolean(46316, $json->boxes[0]->interval);
    SetValueBoolean(31101, $json->boxes[0]->shuffle);
    SetValueInteger(48123, $json->boxes[0]->fan_volume);
    SetValueBoolean(10910, $json->boxes[0]->box_status);
    ?>
    /PHP]

  3. #3
    Registriert seit
    Sep 2016
    Ort
    Münsingen (CH)
    Beiträge
    44

    Hallo
    Ich benötige einen Tipp.
    Ich habe in mein Skript nun noch POST eingebaut.
    Den Wert der Variablen sende ich mit meinem Skript mit POST an die API. Der Rückgabewert den mir die API gibt, schreibe ich nun wieder in die Variablen. Ich weiss dass dies im Normalfall die selben Werte sind aber wenn vorher eine andere Variable via App geändert wurde, ist sie nun wieder aktuell.

    Nach jeder Änderung einer meiner 13 bedienbaren Variablen muss demnach mein Skript ausgelöst werden.

    Gibt es oder hat jemand eine elegantere und einfachere Lösung als bei jeder der bedienbaren Variablen mein Skript als Aktion zu hinterlegen?
    Danke.
    PHP-Code:
    // A sample PHP Script to POST data using cURL
    // Data in JSON format
    //*****Variabeln*****
    $Slot0Title 44537;
    $Slot0FanSpeed 50833;
    $Slot0Color 20507;
    $Slot0FanActive 43436;
    $Slot1Title 51732;
    $Slot1FanSpeed 58790;
    $Slot1Color 18093;
    $Slot1FanActive 12443;
    $Slot2Title 50380;
    $Slot2FanSpeed 11661;
    $Slot2Color 58567;
    $Slot2FanActive 26210;
    $Slot3Title 44190;
    $Slot3FanSpeed 54194;
    $Slot3Color 54350;
    $Slot3FanActive 51796;
    $interval 46316;
    $shuffle 31101;
    $fan_volume 48123;
    $box_status 49845;
    $interval_type 46351;
    $is_online 24843;
    $email 'XXXXXXXX';
    $password ='XXXXXXX';
    $device_key 1261;

    $url "https://rest.moodo.co/api";
    $data = array(
        
    'email' => $email,
        
    'password' => $password
        
    );

    $payload json_encode($data);

    // Prepare new cURL resource
    $ch curl_init($url "/login");
    curl_setopt($chCURLOPT_RETURNTRANSFERtrue);
    curl_setopt($chCURLINFO_HEADER_OUTtrue);
    curl_setopt($chCURLOPT_POSTtrue);
    curl_setopt($chCURLOPT_POSTFIELDS$payload);

    // Set HTTP Header for POST request
    curl_setopt($chCURLOPT_HTTPHEADER, array(
        
    'Content-Type: application/json',
        
    'Content-Length: ' strlen($payload))
    );


    // Submit the POST request
    $result curl_exec($ch);
    //print $result;
    $sessionToken substr($result10, -2);
    //print $sessionToken;
    // Close cURL session handle
    //curl_close($ch);
    //********************
    $datapost = array(
       
    //'token' => $sessionToken,
      
    'device_key' => 1261,
      
    'fan_volume' => GetValueInteger($fan_volume),
      
    "box_status" => GetValueInteger($box_status),
      
    'settings_slot0' => array(
        
    'fan_speed' => GetValueInteger($Slot0FanSpeed),
        
    'fan_active' => GetValueBoolean($Slot0FanActive)
      ),
      
    'settings_slot1' => array( 
        
    'fan_speed' => GetValueInteger($Slot1FanSpeed),
        
    'fan_active' => GetValueBoolean($Slot1FanActive)
      ),
      
    'settings_slot2' => array(
        
    'fan_speed' => GetValueInteger($Slot2FanSpeed),
        
    'fan_active' => GetValueBoolean($Slot2FanActive)
      ),
      
    'settings_slot3' => array(
        
    'fan_speed' => GetValueInteger($Slot3FanSpeed),
        
    'fan_active' => GetValueBoolean($Slot3FanActive)
      ),
        );

    $payload json_encode($datapost);

    // Prepare new cURL resource
    $ch curl_init($url "/boxes");
    curl_setopt($chCURLOPT_RETURNTRANSFERtrue);
    curl_setopt($chCURLINFO_HEADER_OUTtrue);
    curl_setopt($chCURLOPT_POSTtrue);
    curl_setopt($chCURLOPT_POSTFIELDS$payload);

    // Set HTTP Header for POST request
    curl_setopt($chCURLOPT_HTTPHEADER, array(
        
    'Content-Type: application/json',
        
    'token: ' . ($sessionToken),
        
    'Content-Length: ' strlen($payload))
    );


    // Submit the POST request
    $result curl_exec($ch);
    //print $result;
    // Close cURL session handle
    curl_close($ch);

    // DATEN VERARBEITEN
    $json json_decode($result);
    SetValueInteger($fan_volume$json->box->fan_volume);
    SetValueInteger($box_status$json->box->box_status);
    SetValueBoolean($is_online$json->box->is_online);
    SetValueBoolean($shuffle$json->box->shuffle);
    SetValueBoolean($interval$json->box->interval);
    SetValueInteger($interval_type$json->box->interval_type);
    SetValueString($Slot0Title$json->box->settings[0]->capsule_info->title);
    SetValueInteger($Slot0FanSpeed$json->box->settings[0]->fan_speed);
    SetValueBoolean($Slot0FanActive,$json->box->settings[0]->fan_active);
    SetValueInteger($Slot0Colorhexdec($json->box->settings[0]->capsule_info->color)); // HEX-Color Profil
    SetValueString($Slot1Title$json->box->settings[1]->capsule_info->title);
    SetValueInteger($Slot1FanSpeed$json->box->settings[1]->fan_speed);
    SetValueInteger($Slot1Colorhexdec($json->box->settings[1]->capsule_info->color)); // HEX-Color Profil
    SetValueString($Slot2Title$json->box->settings[2]->capsule_info->title);
    SetValueInteger($Slot2FanSpeed$json->box->settings[2]->fan_speed);
    SetValueInteger($Slot2Colorhexdec($json->box->settings[2]->capsule_info->color)); // HEX-Color Profil
    SetValueString($Slot3Title$json->box->settings[3]->capsule_info->title);
    SetValueInteger($Slot3FanSpeed$json->box->settings[3]->fan_speed);
    SetValueInteger($Slot3Colorhexdec($json->box->settings[3]->capsule_info->color)); // HEX-Color Profil

    ?> 

  4. #4
    Registriert seit
    Jun 2011
    Beiträge
    510

    Moin,

    danke erst mal für dein Script ... also ich finde das so OK :0) Leider sind meine Programmierkenntnisse nicht so groß. Ne schlankere Lösung habe ich daher leider auch nicht. Ich hab aber noch die Favoriten mit aufgenommen. Müsste ich dann auch nochmal mit POST verknüpfen ... mal schauen

    PHP-Code:
    $ch curl_init($url "/favorites/false/XXX");
     
    curl_setopt($chCURLOPT_TIMEOUT5);
     
    curl_setopt($chCURLOPT_CONNECTTIMEOUT5);
     
    curl_setopt($chCURLOPT_RETURNTRANSFERtrue);
     
    // Set HTTP Header for POST request 
     
    curl_setopt($chCURLOPT_HTTPHEADER, array(
     
    'Content-Type: application/json',
     
    'token: ' . ($sessionToken))
     );
     
    $data curl_exec($ch);
     
    curl_close($ch);
     
    //echo $data;
     
    $json json_decode($data);
    //print_r($json);

    $Programm_1 $json->favorites[0]->title;
    $Programm_2 $json->favorites[1]->title;
    $Programm_3 $json->favorites[2]->title;
    $Programm_4 $json->favorites[3]->title;
    $Programm_5 $json->favorites[4]->title;

    IPS_SetVariableProfileAssociation("Duft_Thema",  1$json->favorites[0]->title""0xFFFFFF);
    IPS_SetVariableProfileAssociation("Duft_Thema",  2$json->favorites[1]->title""0xFFFFFF);
    IPS_SetVariableProfileAssociation("Duft_Thema",  3$json->favorites[2]->title""0xFFFFFF);
    IPS_SetVariableProfileAssociation("Duft_Thema",  4$json->favorites[3]->title""0xFFFFFF);
    IPS_SetVariableProfileAssociation("Duft_Thema",  5$json->favorites[4]->title""0xFFFFFF); 
    Andreas
    Geändert von wuppi83 (22.01.19 um 10:16 Uhr)
    Professional

  5. #5
    Registriert seit
    Sep 2013
    Ort
    Niederösterreich
    Beiträge
    386

    Jetzt habt Ihr mich wieder daran erinnert, das ich ja auch so ein Ding irgendwo als Staubfänger rumstehen habe
    Habe mal ein bisschen was gebastelt.

    Skript kopieren, Daten eintragen, einmal ausführen.
    Hoffe es funktioniert

    PHP-Code:
    <?
    /*******************************************************************************

        MSC - Version 0.5c vom 27.01.2019

    ********************************************************************************

        SKRIPT ZUM AUSWERTEN VON Moodo Lufterfirschern
        über die  REST-API
        
    --------------------------------------------------------------------------------

        Auswerteskript

    ********************************************************************************
    *******************************************************************************/

         // Login-Daten
        
    $email 'xxxx';
        
    $password 'xxxx';

        
    // Abfragezyklus in Sekunden
        
    $time 30;

    // -----------------------------------------------------------------------------

        
    $parentID IPS_GetParent($_IPS['SELF']);
        
    /*******************************************************************************
    *******************************************************************************/

    // Auslösendes Ereignis bestimmen
    // *****************************************************************************
    switch($_IPS['SENDER']){

    // *****************************************************************************
    // Auslöser WebFront
    // -----------------------------------------------------------------------------
        
    case "WebFront":
            
    $object IPS_GetObject($_IPS['VARIABLE']);
            
    $sessionToken moodo_login();
            
            switch(
    $object['ObjectIdent']){
                case 
    "box_status":
                    
    $result moodo_switch(IPS_GetObject($object['ParentID'])['ObjectIdent'], "box_status"$_IPS['VALUE']);
                    
    moodo_logout();
                    
    SetValue($_IPS['VARIABLE'], $_IPS['VALUE']);
                break;
                case 
    "shuffle":
                    
    $result moodo_switch(IPS_GetObject($object['ParentID'])['ObjectIdent'], "shuffle"$_IPS['VALUE']);
                    
    moodo_logout();
                    
    SetValue($_IPS['VARIABLE'], $_IPS['VALUE']);
                break;
                case 
    "interval":
                    
    $result moodo_switch(IPS_GetObject($object['ParentID'])['ObjectIdent'], "interval"$_IPS['VALUE']);
                    
    moodo_logout();
                    
    SetValue($_IPS['VARIABLE'], $_IPS['VALUE']);
                break;
                case 
    "interval_type":
                    
    $result moodo_switch(IPS_GetObject($object['ParentID'])['ObjectIdent'], "interval_type"$_IPS['VALUE']);
                    
    moodo_logout();
                    
    SetValue($_IPS['VARIABLE'], $_IPS['VALUE']);
                break;                                    
                case 
    "fan_volume":
                    
    $result moodo_fanVolume(IPS_GetObject($object['ParentID'])['ObjectIdent'], $_IPS['VALUE']);
                    
    moodo_logout();
                    
    SetValue($_IPS['VARIABLE'], $_IPS['VALUE']);
                break;
                case 
    "favorites":
                    
    $fan_volume IPS_GetObjectIDByIdent("fan_volume"$object['ParentID']);
                    
    $buffer IPS_GetObjectIDByIdent("fav_buffer"$object['ParentID']);

                    
    moodo_setFav(IPS_GetObject($object['ParentID'])['ObjectIdent'], $fan_volume$_IPS['VALUE'], $buffer);
                    
    moodo_logout();
                    
    SetValue($_IPS['VARIABLE'], $_IPS['VALUE']);                
                break;
                default:
                    
    moodo_logout();
                break;
                }
        break;

    // *****************************************************************************
    // Auslöser TimerEvent
    // -----------------------------------------------------------------------------
        
    case "TimerEvent":
               
    IPS_SetEventActive(IPS_GetObjectIDByIdent("scriptTimer"$_IPS['SELF']), false);
               
    IPS_SetEventActive(IPS_GetObjectIDByIdent("resetTimer"$_IPS['SELF']), true);
            
            
    $sessionToken moodo_login();
            
    $boxes moodo_getBoxes();

            if(
    array_key_exists("boxes"$boxes)){
                foreach(
    $boxes['boxes'] as $key => $box){
                    
    $boxID IPS_GetObjectIDByIdent($box['device_key'], $parentID);
                        
    SetValue(IPS_GetObjectIDByIdent("box_status"$boxID), $box['box_status']);
                        
    SetValue(IPS_GetObjectIDByIdent("is_online"$boxID), $box['is_online']);
                        
    SetValue(IPS_GetObjectIDByIdent("fan_volume"$boxID), $box['fan_volume']);                   
                        
    SetValue(IPS_GetObjectIDByIdent("shuffle"$boxID), $box['shuffle']);
                        
    SetValue(IPS_GetObjectIDByIdent("interval"$boxID), $box['interval']);
                        
    SetValue(IPS_GetObjectIDByIdent("interval_type"$boxID), $box['interval_type']);
                        
    SetValue(IPS_GetObjectIDByIdent("fav_buffer"$boxID), json_encode(moodo_getFav($box['device_key'])));
                    
                    
    $array = array();
                    foreach(
    $box['settings'] as $skey => $slots){
                        
    $array[$slots['slot_id']]['capsule_type_code'] = $slots['capsule_type_code'];
                        
    $array[$slots['slot_id']]['fan_speed'] = $slots['fan_speed'];

                        
    $slotID IPS_GetObjectIDByIdent("slot".$slots['slot_id'], $boxID);
                            
    SetValue(IPS_GetObjectIDByIdent("fan"$slotID), $slots['fan_speed']);
                            
    SetValue(IPS_GetObjectIDByIdent("color"$slotID), hexdec($slots['capsule_info']['color']));
                            
    SetValue(IPS_GetObjectIDByIdent("title"$slotID), $slots['capsule_info']['title']);
                        }
                    
                    
                    
    $buffer json_decode(GetValue(IPS_GetObjectIDByIdent("fav_buffer"$boxID)), true);
                    foreach(
    $buffer as $key => $favs){
                        if(
    $favs['slots'] === $array){
                            
    SetValue(IPS_GetObjectIDByIdent("favorites"$boxID), $key);
                            break;
                            }
                        else 
    SetValue(IPS_GetObjectIDByIdent("favorites"$boxID), -1);
                        }
                    }
                }
            
            
    moodo_logout();

            
    IPS_SetEventActive(IPS_GetObjectIDByIdent("scriptTimer"$_IPS['SELF']), true);
               
    IPS_SetEventActive(IPS_GetObjectIDByIdent("resetTimer"$_IPS['SELF']), false);        
        break;
        
    // *****************************************************************************
    // Auslöser Skript ausführen
    // -----------------------------------------------------------------------------
        
    case "Execute";
            
    $sessionToken moodo_login();
            
    $boxes moodo_getBoxes();
            
    $interval moodo_getInterval();
            
    moodo_Profil("_MoodoIval"$interval, array(=> "#00FF00"=> "#3366FF"=> "#FF2244"));

            if(
    array_key_exists("boxes"$boxes)){
                echo 
    "Installation gestartet\n";
                
    $pos 10;
                
                foreach(
    $boxes['boxes'] as $key => $box){
                    
    $cat SetKatByName($parentID$box['name'], $box['device_key'], $pos);
                        
    CreateVariableByName($cat"Status""box_status"0"~Switch"10""$_IPS['SELF']);
                        
    CreateVariableByName($cat"Online""is_online"0""11"Cloud""");
                        
    CreateVariableByName($cat"Ventilator""fan_volume"1"~Intensity.100"12""$_IPS['SELF']);
                        
    CreateVariableByName($cat"Favoriten""favorites"1"_MoodoFav"13"Favorite"$_IPS['SELF']);
                        
    CreateVariableByName($cat"Shuffle""shuffle"0"~Switch"14"Shuffle"$_IPS['SELF']);
                        
    CreateVariableByName($cat"Interval""interval"0"~Switch"15"Climate"$_IPS['SELF']);
                        
    CreateVariableByName($cat"Intervaltyp""interval_type"1"_MoodoIval"16"Information"$_IPS['SELF']);
                        
    CreateVariableByName($cat"FavBuffer""fav_buffer"3""40"Database"""true);

                    
    $did SetDummyByName($cat"Slot 0""slot0"50"Flower");
                        
    CreateVariableByName($did"Ventilator""fan"1"~Intensity.100"10"""");
                        
    CreateVariableByName($did"Farbe""color"1"~HexColor"11"Macro""");
                        
    CreateVariableByName($did"Kapsel""title"3""12"Keyboard""");
                    
                    
    $did SetDummyByName($cat"Slot 1""slot1"51"Flower");
                        
    CreateVariableByName($did"Ventilator""fan"1"~Intensity.100"10"""");
                        
    CreateVariableByName($did"Farbe""color"1"~HexColor"11"Macro""");
                        
    CreateVariableByName($did"Kapsel""title"3""12"Keyboard""");
                    
                    
    $did SetDummyByName($cat"Slot 2""slot2"52"Flower");
                        
    CreateVariableByName($did"Ventilator""fan"1"~Intensity.100"10"""");
                        
    CreateVariableByName($did"Farbe""color"1"~HexColor"11"Macro""");
                        
    CreateVariableByName($did"Kapsel""title"3""12"Keyboard""");
                                                                                    
                    
    $did SetDummyByName($cat"Slot 3""slot3"53"Flower");
                        
    CreateVariableByName($did"Ventilator""fan"1"~Intensity.100"10"""");
                        
    CreateVariableByName($did"Farbe""color"1"~HexColor"11"Macro""");
                        
    CreateVariableByName($did"Kapsel""title"3""12"Keyboard""");
                        
                    
    $pos++;
                    }

                
    SetEventByName($_IPS['SELF'], "ScriptTimer""scriptTimer"10$timetrue);
                
    SetEventByName($_IPS['SELF'], "ResetTimer""resetTimer"11$time 2false);
                
                
    IPS_SetPosition($_IPS['SELF'], 100);
                
    moodo_logout();

                echo 
    "Installation abgeschlossen";            
                }                                                                
            else{
                if(
    array_key_exists("error"$boxes)) echo "Abfrage nicht möglich!\n".$boxes['error'];        
                else echo 
    "Abfrage nicht möglich! - UNBEKANNTER FEHELR";
                }
            return;
        break;
        
    // *****************************************************************************
    // Auslöser Default
    // -----------------------------------------------------------------------------
        
    default:
            return;
        break;
        }    


    /*******************************************************************************
    ********************************************************************************

        FUNKTIONEN

    ********************************************************************************
    *******************************************************************************/

    // Funktion Kategorie anlegen
    // ---------------------------
    function SetKatByName($parentID$name$ident$position){
        
    $kid = @IPS_GetCategoryIDByName($name$parentID);
        if(
    $kid === false){
            
    $kid IPS_CreateCategory();
                
    IPS_SetName($kid$name);
                
    IPS_SetIdent($kid $ident);
                
    IPS_SetParent($kid$parentID);
                
    IPS_SetPosition ($kid$position);
            }

        return 
    $kid;
        }

    // Funktion Dummy erstellen
    // -------------------------
    function SetDummyByName($parentID$name$ident$position$icon$check false){
        
    $did = @IPS_GetObjectIDByIdent($ident$parentID);
        
        if(
    $did === false){
            
    $did = @IPS_CreateInstance("{485D0419-BE97-4548-AA9C-C083EB82E61E}");
            
    IPS_SetName($did$name);
            
    IPS_SetIdent($did$ident);
            
    IPS_SetParent($did$parentID);
            
    IPS_SetPosition($did$position);
            
    IPS_SetIcon($did$icon);
            }

        if(
    $check){
            if(
    $name != IPS_GetObject($did)['ObjectName']) IPS_SetName($did$name);
            if(
    $position != IPS_GetObject($did)['ObjectPosition']) IPS_SetPosition($did$position);
            }
        return 
    $did;
        } 
        
    // Funktion Variable erstellen
    // ----------------------------
    function CreateVariableByName($parentID$name$ident$type$profil$pos$icon$script$visible false){
        
    $vid = @IPS_GetObjectIDByIdent($ident$parentID);

        if(
    $vid === false){
            
    $vid IPS_CreateVariable($type);
                
    IPS_SetParent($vid$parentID);
                   
    IPS_SetName($vid$name);
                   
    IPS_SetIdent($vid$ident);
                
    IPS_SetName($vid$name);
                
    IPS_SetPosition($vid$pos);
                   
    IPS_SetIcon($vid$icon);
                
    IPS_SetHidden($vid$visible);
                   
    IPS_SetVariableCustomProfile($vid$profil);
                   if(
    $script !== ""IPS_SetVariableCustomAction($vid$script);
                   
    IPS_SetPosition($vid$pos);
            }

        return 
    $vid;
        }

    // Profile anlegen
    // ----------------
    function moodo_Profil($profil$data$color ""){
        if(
    IPS_VariableProfileExists($profil)) $Associations IPS_GetVariableProfile($profil)['Associations'];
        else{
            
    IPS_CreateVariableProfile($profil 1);
            
    $Associations IPS_GetVariableProfile($profil)['Associations'];
            }

        if(
    count($data) != count($Associations)){
            foreach(
    $Associations as $ass){
                
    IPS_SetVariableProfileAssociation($profil $ass['Value'] , """"0);
                }
                    
            foreach(
    $data as $key => $value){
                if(
    $color !== ""IPS_SetVariableProfileAssociation($profil$key$value['title'], ""hexdec($color[$key]));
                else 
    IPS_SetVariableProfileAssociation($profil$key$value['title'], "", -1);
                }
            }
        else{
            foreach(
    $data as $key => $value){
                if(@
    $Associations[$key]['Name'] != $value['title']){
                    if(
    $color !== ""IPS_SetVariableProfileAssociation($profil$key$value['title'], ""hexdec($color[$key]));
                    else 
    IPS_SetVariableProfileAssociation($profil$key$value['title'], "", -1);
                    }
                }
            }
        }

    // Funktion TimerEvent erstellen
    // -----------------------------------------------------------------------------
    function SetEventByName($parentID$name$ident$position$value$state){
       
    $eid = @IPS_GetObjectIDByIdent($ident$parentID);

        if(
    $eid === false){
            
    $eid IPS_CreateEvent(1);

            
    IPS_SetEventCyclic($eid00001$value);
            
    IPS_SetName($eid$name);
            
    IPS_SetParent($eid$parentID);
            
    IPS_SetPosition($eid$position);
            
    IPS_SetIdent($eid$ident);
            
    IPS_SetEventActive($eid$state);
            }

        return 
    $eid;
        }
        
    // Funktion Moodo Login
    // ---------------------    
    function moodo_login(){
    Global 
    $email$password;

        
    $data = array(
            
    'email' => $email,
            
    'password' => $password
            
    );
        
        
    $ch curl_init("https://rest.moodo.co/api/login");
            
    curl_setopt($chCURLOPT_RETURNTRANSFERtrue);
            
    curl_setopt($chCURLINFO_HEADER_OUTtrue);
            
    curl_setopt($chCURLOPT_POSTtrue);
            
    curl_setopt($chCURLOPT_POSTFIELDSjson_encode($data));
            
    curl_setopt($chCURLOPT_HTTPHEADER, array(
                
    'Content-Type: application/json',
                
    'Content-Length: ' strlen(json_encode($data)))
                );

            
    $result curl_exec($ch);

        return 
    json_decode($result)->token;
        }

    // Funktion Moodo Logout
    // ----------------------
    function moodo_logout(){
    Global 
    $sessionToken;

        
    $ch curl_init("https://rest.moodo.co/api/logout");
            
    curl_setopt($chCURLOPT_RETURNTRANSFERtrue);
            
    curl_setopt($chCURLINFO_HEADER_OUTtrue);
            
    curl_setopt($chCURLOPT_POSTtrue);
            
    curl_setopt($chCURLOPT_HTTPHEADER, array(
                
    'Content-Type: application/json',
                
    'token: '.$sessionToken,
                ));
                
            
    $result curl_exec($ch);
        
    curl_close($ch);
        }

    // Funktion alle Moodo Boxen auslesen
    // -----------------------------------
    function moodo_getBoxes(){
    Global 
    $sessionToken;

        
    $ch curl_init("https://rest.moodo.co/api/boxes");
            
    curl_setopt($chCURLOPT_RETURNTRANSFERtrue);
            
    curl_setopt($chCURLINFO_HEADER_OUTtrue);
            
    curl_setopt($chCURLOPT_HTTPHEADER, array(
                
    'Content-Type: application/json',
                
    'token: '.$sessionToken,
                ));

            
    $result curl_exec($ch);
        
        return 
    json_decode($resulttrue);
        }

    // Funktion Favoriten auslesen
    // ----------------------------
    function moodo_getFav($deviceKey){
    Global 
    $sessionToken;

        
    $ch curl_init("https://rest.moodo.co/api/favorites/true/".$deviceKey);
            
    curl_setopt($chCURLOPT_RETURNTRANSFERtrue);
            
    curl_setopt($chCURLINFO_HEADER_OUTtrue);
            
    curl_setopt($chCURLOPT_HTTPHEADER, array(
                
    'Content-Type: application/json',
                
    'token: '.$sessionToken,
                ));

            
    $result curl_exec($ch);
            
    $json json_decode($resulttrue);

            if(
    array_key_exists("favorites"$json)){
                
    $array = array();
                foreach(
    $json['favorites'] as $key => $value){
                    
    $array[$key]['title'] = $value['title'];
                    
    $array[$key]['id'] = $value['id'];

                    foreach(
    $value['settings'] as $skey => $slots){
                        
    $array[$key]['slots'][$slots['slot_id']]['capsule_type_code'] = $slots['capsule_type_code'];
                        
    $array[$key]['slots'][$slots['slot_id']]['fan_speed'] = $slots['fan_speed'];
                        }
                    }
                
    moodo_Profil("_MoodoFav"$array);
                }
        
        return 
    $array;
        }

    // Funktion Intervaltypen auslesen
    // --------------------------------
    function moodo_getInterval(){
    Global 
    $sessionToken;

        
    $ch curl_init("https://rest.moodo.co/api/interval/");
            
    curl_setopt($chCURLOPT_RETURNTRANSFERtrue);
            
    curl_setopt($chCURLINFO_HEADER_OUTtrue);
            
    curl_setopt($chCURLOPT_HTTPHEADER, array(
                
    'Content-Type: application/json',
                
    'token: '.$sessionToken,
                ));

            
    $result curl_exec($ch);
            
    $json json_decode($resulttrue);
            
    $lang_de = array(
                
    "powerful Moodo" => "kraftvoll",
                
    "efficient Moodo" => "effizient",
                
    "saver Moodo" => "sparend"
                
    );

            if(
    array_key_exists("interval_types"$json)){
                foreach(
    $json['interval_types'] as $key => $value){
                    
    $array[$value['type']]['title'] = $lang_de[$value['description']];
                    
    $array[$value['type']]['work_minutes'] = $value['work_minutes'];
                    
    $array[$value['type']]['sleep_minutes'] = $value['sleep_minutes'];
                    }
                }
        
        return 
    $array;
        }

    // Funktion Funktionen einer Moodo Box ein/ausschalten
    // ----------------------------------------------------
    function moodo_switch($deviceKey$mode$state){
    Global 
    $sessionToken;

        switch(
    $mode){
            case 
    "box_status":
                
    $rest "boxes";
            break;
            case 
    "shuffle":
                
    $rest "shuffle";
            break;
            case 
    "interval":
                
    $rest "interval";
            break;
            case 
    "interval_type":
                
    $rest "interval";
            break;        
            default:
                return;
            break;
            }
            
        
    $ch curl_init("https://rest.moodo.co/api/".$rest."/".$deviceKey);
            
    curl_setopt($chCURLOPT_RETURNTRANSFERtrue);
            
    curl_setopt($chCURLINFO_HEADER_OUTtrue);

            
    $cl "";
            if(
    $mode == "interval_type"){
                
    curl_setopt($chCURLOPT_POSTtrue);
                
    curl_setopt($chCURLOPT_POSTFIELDSjson_encode(array("interval_type" => $state)));
                
    $cl 'Content-Length: '.strlen(json_encode(array("interval_type" => $state)));
                }
            elseif(
    $state == truecurl_setopt($chCURLOPT_POSTtrue);
            else 
    curl_setopt($chCURLOPT_CUSTOMREQUEST"DELETE");
            
            
    curl_setopt($chCURLOPT_HTTPHEADER, array(
                
    'Content-Type: application/json',
                
    $cl,
                
    'token: '.$sessionToken,
                ));

            
    $result curl_exec($ch);
        
        return 
    json_decode($resulttrue);
        }

    // Funktion Ventilatorstufe einer Moodo Box stellen
    // -------------------------------------------------
    function moodo_fanVolume($deviceKey$value){
    Global 
    $sessionToken;
        
        
    $ch curl_init("https://rest.moodo.co/api/intensity/".$deviceKey);
            
    curl_setopt($chCURLOPT_RETURNTRANSFERtrue);
            
    curl_setopt($chCURLINFO_HEADER_OUTtrue);
            
    curl_setopt($chCURLOPT_POSTtrue);
            
    curl_setopt($chCURLOPT_POSTFIELDSjson_encode(array("fan_volume" => $value)));
            
    curl_setopt($chCURLOPT_HTTPHEADER, array(
                
    'Content-Type: application/json',
                
    'Content-Length: '.strlen(json_encode(array("fan_volume" => $value))),
                
    'token: '.$sessionToken,
                ));
            
            
    $result curl_exec($ch);
        
        return 
    json_decode($resulttrue);
        }

    // Funktion Favoriten auswählen
    // -----------------------------
    function moodo_setFav($deviceKey$fan_volume$favSelect$buffer){
    Global 
    $sessionToken;
        
    $favIDs json_decode(GetValue($buffer), true);

        
    $data = array(
            
    "favorite_id" => $favIDs[$favSelect]['id'],
            
    "device_key" => (int)$deviceKey,
            
    "fan_volume" => GetValue($fan_volume),
            
    "duration_minutes" => 0
            
    );

        
    $ch curl_init("https://rest.moodo.co/api/favorites");
            
    curl_setopt($chCURLOPT_RETURNTRANSFERtrue);
            
    curl_setopt($chCURLINFO_HEADER_OUTtrue);
            
    curl_setopt($chCURLOPT_CUSTOMREQUEST"PATCH");
            
    curl_setopt($chCURLOPT_POSTFIELDSjson_encode($data));
            
    curl_setopt($chCURLOPT_HTTPHEADER, array(
                
    'Content-Type: application/json',
                
    'Content-Length: '.strlen(json_encode($data)),
                
    'token: '.$sessionToken,
                ));

            
    $result curl_exec($ch);

        return 
    json_decode($resulttrue);
        }

    /*******************************************************************************
    *******************************************************************************/
    ?>
    Gruß Manfred
    IPS 5.2 | Win u. Symbox | IPSView | Wago | Homematic | IPS-868 | Philips HUE | Modbus | PV FroniusHybrid | AEG USV | Qnap | Synology | IP Kameras | iRobot | Gardena R70Li | Sony TV / AV | Sat Duo2 | Philips/Samsung TV | Sonos | Buderus | RPi | Arduino || Visu: 24", 10", 7" Tablets ....

  6. #6
    Registriert seit
    Sep 2016
    Ort
    Münsingen (CH)
    Beiträge
    44

    Hallo manni,
    Ich versuche seit zwei Tagen mein Skript umzubauen... der Erfolg hält sich in Grenzen.
    Ich habe mal Dein Skript getestet, funktioniert aber das Profil MoodoFav wird nicht erstellt.
    Code:
    Warning: Profile with name #_MoodoFav does not exist in /Library/Application Support/Symcon/scripts/14119.ips.php on line 262
    Danke für Deine Arbeit.

  7. #7
    Registriert seit
    Sep 2013
    Ort
    Niederösterreich
    Beiträge
    386

    Zitat Zitat von saschild Beitrag anzeigen
    Hallo manni,
    Code:
    Warning: Profile with name #_MoodoFav does not exist in /Library/Application Support/Symcon/scripts/14119.ips.php on line 262

    UPS

    UPDATE:
    PHP-Code:
    <?
    /*******************************************************************************

        MSC - Version 0.6 vom 27.01.2019

    ********************************************************************************

        SKRIPT ZUM AUSWERTEN VON Moodo Lufterfirschern
        über die REST-API
        
    --------------------------------------------------------------------------------

        Auswerteskript

    ********************************************************************************
    *******************************************************************************/

        // Login-Daten
        
    $email 'xxxxx';
        
    $password 'xxxxx';

        
    // Abfragezyklus in Sekunden
        
    $time 30;

    // -----------------------------------------------------------------------------

        
    $parentID IPS_GetParent($_IPS['SELF']);
        
    /*******************************************************************************
    *******************************************************************************/

    // Auslösendes Ereignis bestimmen
    // *****************************************************************************
    switch($_IPS['SENDER']){

    // *****************************************************************************
    // Auslöser WebFront
    // -----------------------------------------------------------------------------
        
    case "WebFront":
            
    $object IPS_GetObject($_IPS['VARIABLE']);
            
    $sessionToken moodo_login();
            
            switch(
    $object['ObjectIdent']){
                case 
    "box_status":
                    
    $result moodo_switch(IPS_GetObject($object['ParentID'])['ObjectIdent'], "box_status"$_IPS['VALUE']);
                    
    moodo_logout();
                    
    SetValue($_IPS['VARIABLE'], $_IPS['VALUE']);
                break;
                case 
    "shuffle":
                    
    $result moodo_switch(IPS_GetObject($object['ParentID'])['ObjectIdent'], "shuffle"$_IPS['VALUE']);
                    
    moodo_logout();
                    
    SetValue($_IPS['VARIABLE'], $_IPS['VALUE']);
                break;
                case 
    "interval":
                    
    $result moodo_switch(IPS_GetObject($object['ParentID'])['ObjectIdent'], "interval"$_IPS['VALUE']);
                    
    moodo_logout();
                    
    SetValue($_IPS['VARIABLE'], $_IPS['VALUE']);
                break;
                case 
    "interval_type":
                    
    $result moodo_switch(IPS_GetObject($object['ParentID'])['ObjectIdent'], "interval_type"$_IPS['VALUE']);
                    
    moodo_logout();
                    
    SetValue($_IPS['VARIABLE'], $_IPS['VALUE']);
                break;                                    
                case 
    "fan_volume":
                    
    $result moodo_fanVolume(IPS_GetObject($object['ParentID'])['ObjectIdent'], $_IPS['VALUE']);
                    
    moodo_logout();
                    
    SetValue($_IPS['VARIABLE'], $_IPS['VALUE']);
                break;
                case 
    "favorites":
                    
    $fan_volume IPS_GetObjectIDByIdent("fan_volume"$object['ParentID']);
                    
    $buffer IPS_GetObjectIDByIdent("fav_buffer"$object['ParentID']);

                    
    moodo_setFav(IPS_GetObject($object['ParentID'])['ObjectIdent'], $fan_volume$_IPS['VALUE'], $buffer);
                    
    moodo_logout();
                    
    SetValue($_IPS['VARIABLE'], $_IPS['VALUE']);                
                break;
                default:
                    
    moodo_logout();
                break;
                }
        break;

    // *****************************************************************************
    // Auslöser TimerEvent
    // -----------------------------------------------------------------------------
        
    case "TimerEvent":
               
    IPS_SetEventActive(IPS_GetObjectIDByIdent("scriptTimer"$_IPS['SELF']), false);
               
    IPS_SetEventActive(IPS_GetObjectIDByIdent("resetTimer"$_IPS['SELF']), true);
            
            
    $sessionToken moodo_login();
            
    $boxes moodo_getBoxes();

            if(
    array_key_exists("boxes"$boxes)){
                foreach(
    $boxes['boxes'] as $key => $box){
                    
    $boxID IPS_GetObjectIDByIdent($box['device_key'], $parentID);
                        
    SetValue(IPS_GetObjectIDByIdent("box_status"$boxID), $box['box_status']);
                        
    SetValue(IPS_GetObjectIDByIdent("is_online"$boxID), $box['is_online']);
                        
    SetValue(IPS_GetObjectIDByIdent("fan_volume"$boxID), $box['fan_volume']);                   
                        
    SetValue(IPS_GetObjectIDByIdent("shuffle"$boxID), $box['shuffle']);
                        
    SetValue(IPS_GetObjectIDByIdent("interval"$boxID), $box['interval']);
                        
    SetValue(IPS_GetObjectIDByIdent("interval_type"$boxID), $box['interval_type']);
                        
    SetValue(IPS_GetObjectIDByIdent("fav_buffer"$boxID), json_encode(moodo_getFav($box['device_key'])));
                    
                    
    $array = array();
                    foreach(
    $box['settings'] as $skey => $slots){
                        
    $array[$slots['slot_id']]['capsule_type_code'] = $slots['capsule_type_code'];
                        
    $array[$slots['slot_id']]['fan_speed'] = $slots['fan_speed'];

                        
    $slotID IPS_GetObjectIDByIdent("slot".$slots['slot_id'], $boxID);
                            
    SetValue(IPS_GetObjectIDByIdent("fan"$slotID), $slots['fan_speed']);
                            
    SetValue(IPS_GetObjectIDByIdent("color"$slotID), hexdec($slots['capsule_info']['color']));
                            
    SetValue(IPS_GetObjectIDByIdent("title"$slotID), $slots['capsule_info']['title']);
                        }
                    
                    
                    
    $buffer json_decode(GetValue(IPS_GetObjectIDByIdent("fav_buffer"$boxID)), true);
                    foreach(
    $buffer as $key => $favs){
                        if(
    $favs['slots'] === $array){
                            
    SetValue(IPS_GetObjectIDByIdent("favorites"$boxID), $key);
                            break;
                            }
                        else 
    SetValue(IPS_GetObjectIDByIdent("favorites"$boxID), -1);
                        }
                    }
                }
            
            
    moodo_logout();

            
    IPS_SetEventActive(IPS_GetObjectIDByIdent("scriptTimer"$_IPS['SELF']), true);
               
    IPS_SetEventActive(IPS_GetObjectIDByIdent("resetTimer"$_IPS['SELF']), false);        
        break;
        
    // *****************************************************************************
    // Auslöser Skript ausführen
    // -----------------------------------------------------------------------------
        
    case "Execute";
            
    $sessionToken moodo_login();
            
    $boxes moodo_getBoxes();
            
    $interval moodo_getInterval();
            
    moodo_Profil("_MoodoIval"$interval, array(=> "#00FF00"=> "#3366FF"=> "#FF2244"));
            
    moodo_Profil("_MoodoFav", array(=> ""), "");

            if(
    array_key_exists("boxes"$boxes)){
                echo 
    "Installation gestartet\n";
                
    $pos 10;
                
                foreach(
    $boxes['boxes'] as $key => $box){
                    
    $cat SetKatByName($parentID$box['name'], $box['device_key'], $pos);
                        
    CreateVariableByName($cat"Status""box_status"0"~Switch"10""$_IPS['SELF']);
                        
    CreateVariableByName($cat"Online""is_online"0""11"Cloud""");
                        
    CreateVariableByName($cat"Ventilator""fan_volume"1"~Intensity.100"12""$_IPS['SELF']);
                        
    CreateVariableByName($cat"Favoriten""favorites"1"_MoodoFav"13"Favorite"$_IPS['SELF']);
                        
    CreateVariableByName($cat"Shuffle""shuffle"0"~Switch"14"Shuffle"$_IPS['SELF']);
                        
    CreateVariableByName($cat"Interval""interval"0"~Switch"15"Climate"$_IPS['SELF']);
                        
    CreateVariableByName($cat"Intervaltyp""interval_type"1"_MoodoIval"16"Information"$_IPS['SELF']);
                        
    CreateVariableByName($cat"FavBuffer""fav_buffer"3""40"Database"""true);

                    
    $did SetDummyByName($cat"Slot 0""slot0"50"Flower");
                        
    CreateVariableByName($did"Ventilator""fan"1"~Intensity.100"10"""");
                        
    CreateVariableByName($did"Farbe""color"1"~HexColor"11"Macro""");
                        
    CreateVariableByName($did"Kapsel""title"3""12"Keyboard""");
                    
                    
    $did SetDummyByName($cat"Slot 1""slot1"51"Flower");
                        
    CreateVariableByName($did"Ventilator""fan"1"~Intensity.100"10"""");
                        
    CreateVariableByName($did"Farbe""color"1"~HexColor"11"Macro""");
                        
    CreateVariableByName($did"Kapsel""title"3""12"Keyboard""");
                    
                    
    $did SetDummyByName($cat"Slot 2""slot2"52"Flower");
                        
    CreateVariableByName($did"Ventilator""fan"1"~Intensity.100"10"""");
                        
    CreateVariableByName($did"Farbe""color"1"~HexColor"11"Macro""");
                        
    CreateVariableByName($did"Kapsel""title"3""12"Keyboard""");
                                                                                    
                    
    $did SetDummyByName($cat"Slot 3""slot3"53"Flower");
                        
    CreateVariableByName($did"Ventilator""fan"1"~Intensity.100"10"""");
                        
    CreateVariableByName($did"Farbe""color"1"~HexColor"11"Macro""");
                        
    CreateVariableByName($did"Kapsel""title"3""12"Keyboard""");
                        
                    
    $pos++;
                    }

                
    SetEventByName($_IPS['SELF'], "ScriptTimer""scriptTimer"10$timetrue);
                
    SetEventByName($_IPS['SELF'], "ResetTimer""resetTimer"11$time 2false);
                
                
    IPS_SetPosition($_IPS['SELF'], 100);
                
    moodo_logout();

                echo 
    "Installation abgeschlossen";            
                }                                                                
            else{
                if(
    array_key_exists("error"$boxes)) echo "Abfrage nicht möglich!\n".$boxes['error'];        
                else echo 
    "Abfrage nicht möglich! - UNBEKANNTER FEHELR";
                }
            return;
        break;
        
    // *****************************************************************************
    // Auslöser Default
    // -----------------------------------------------------------------------------
        
    default:
            return;
        break;
        }    


    /*******************************************************************************
    ********************************************************************************

        FUNKTIONEN

    ********************************************************************************
    *******************************************************************************/

    // Funktion Kategorie anlegen
    // ---------------------------
    function SetKatByName($parentID$name$ident$position){
        
    $kid = @IPS_GetCategoryIDByName($name$parentID);
        if(
    $kid === false){
            
    $kid IPS_CreateCategory();
                
    IPS_SetName($kid$name);
                
    IPS_SetIdent($kid $ident);
                
    IPS_SetParent($kid$parentID);
                
    IPS_SetPosition ($kid$position);
            }

        return 
    $kid;
        }

    // Funktion Dummy erstellen
    // -------------------------
    function SetDummyByName($parentID$name$ident$position$icon$check false){
        
    $did = @IPS_GetObjectIDByIdent($ident$parentID);
        
        if(
    $did === false){
            
    $did = @IPS_CreateInstance("{485D0419-BE97-4548-AA9C-C083EB82E61E}");
            
    IPS_SetName($did$name);
            
    IPS_SetIdent($did$ident);
            
    IPS_SetParent($did$parentID);
            
    IPS_SetPosition($did$position);
            
    IPS_SetIcon($did$icon);
            }

        if(
    $check){
            if(
    $name != IPS_GetObject($did)['ObjectName']) IPS_SetName($did$name);
            if(
    $position != IPS_GetObject($did)['ObjectPosition']) IPS_SetPosition($did$position);
            }
        return 
    $did;
        } 
        
    // Funktion Variable erstellen
    // ----------------------------
    function CreateVariableByName($parentID$name$ident$type$profil$pos$icon$script$visible false){
        
    $vid = @IPS_GetObjectIDByIdent($ident$parentID);

        if(
    $vid === false){
            
    $vid IPS_CreateVariable($type);
                
    IPS_SetParent($vid$parentID);
                   
    IPS_SetName($vid$name);
                   
    IPS_SetIdent($vid$ident);
                
    IPS_SetName($vid$name);
                
    IPS_SetPosition($vid$pos);
                   
    IPS_SetIcon($vid$icon);
                
    IPS_SetHidden($vid$visible);
                   
    IPS_SetVariableCustomProfile($vid$profil);
                   if(
    $script !== ""IPS_SetVariableCustomAction($vid$script);
                   
    IPS_SetPosition($vid$pos);
            }

        return 
    $vid;
        }

    // Profile anlegen
    // ----------------
    function moodo_Profil($profil$data$color ""){
        if(
    IPS_VariableProfileExists($profil)) $Associations IPS_GetVariableProfile($profil)['Associations'];
        else{
            
    IPS_CreateVariableProfile($profil 1);
            
    $Associations IPS_GetVariableProfile($profil)['Associations'];
            }

        if(
    count($data) != count($Associations)){
            foreach(
    $Associations as $ass){
                @
    IPS_SetVariableProfileAssociation($profil $ass['Value'] , """"0);
                }
                    
            foreach(
    $data as $key => $value){
                if(
    $color !== "") @IPS_SetVariableProfileAssociation($profil$key$value['title'], ""hexdec($color[$key]));
                else @
    IPS_SetVariableProfileAssociation($profil$key$value['title'], "", -1);
                }
            }
        else{
            foreach(
    $data as $key => $value){
                if(@
    $Associations[$key]['Name'] != $value['title']){
                    if(
    $color !== "") @IPS_SetVariableProfileAssociation($profil$key$value['title'], ""hexdec($color[$key]));
                    else @
    IPS_SetVariableProfileAssociation($profil$key$value['title'], "", -1);
                    }
                }
            }
        }

    // Funktion TimerEvent erstellen
    // -----------------------------------------------------------------------------
    function SetEventByName($parentID$name$ident$position$value$state){
       
    $eid = @IPS_GetObjectIDByIdent($ident$parentID);

        if(
    $eid === false){
            
    $eid IPS_CreateEvent(1);

            
    IPS_SetEventCyclic($eid00001$value);
            
    IPS_SetName($eid$name);
            
    IPS_SetParent($eid$parentID);
            
    IPS_SetPosition($eid$position);
            
    IPS_SetIdent($eid$ident);
            
    IPS_SetEventActive($eid$state);
            }

        return 
    $eid;
        }
        
    // Funktion Moodo Login
    // ---------------------    
    function moodo_login(){
    Global 
    $email$password;

        
    $data = array(
            
    'email' => $email,
            
    'password' => $password
            
    );
        
        
    $ch curl_init("https://rest.moodo.co/api/login");
            
    curl_setopt($chCURLOPT_RETURNTRANSFERtrue);
            
    curl_setopt($chCURLINFO_HEADER_OUTtrue);
            
    curl_setopt($chCURLOPT_POSTtrue);
            
    curl_setopt($chCURLOPT_POSTFIELDSjson_encode($data));
            
    curl_setopt($chCURLOPT_HTTPHEADER, array(
                
    'Content-Type: application/json',
                
    'Content-Length: ' strlen(json_encode($data)))
                );

            
    $result curl_exec($ch);

        return 
    json_decode($result)->token;
        }

    // Funktion Moodo Logout
    // ----------------------
    function moodo_logout(){
    Global 
    $sessionToken;

        
    $ch curl_init("https://rest.moodo.co/api/logout");
            
    curl_setopt($chCURLOPT_RETURNTRANSFERtrue);
            
    curl_setopt($chCURLINFO_HEADER_OUTtrue);
            
    curl_setopt($chCURLOPT_POSTtrue);
            
    curl_setopt($chCURLOPT_HTTPHEADER, array(
                
    'Content-Type: application/json',
                
    'token: '.$sessionToken,
                ));
                
            
    $result curl_exec($ch);
        
    curl_close($ch);
        }

    // Funktion alle Moodo Boxen auslesen
    // -----------------------------------
    function moodo_getBoxes(){
    Global 
    $sessionToken;

        
    $ch curl_init("https://rest.moodo.co/api/boxes");
            
    curl_setopt($chCURLOPT_RETURNTRANSFERtrue);
            
    curl_setopt($chCURLINFO_HEADER_OUTtrue);
            
    curl_setopt($chCURLOPT_HTTPHEADER, array(
                
    'Content-Type: application/json',
                
    'token: '.$sessionToken,
                ));

            
    $result curl_exec($ch);
        
        return 
    json_decode($resulttrue);
        }

    // Funktion Favoriten auslesen
    // ----------------------------
    function moodo_getFav($deviceKey){
    Global 
    $sessionToken;

        
    $ch curl_init("https://rest.moodo.co/api/favorites/true/".$deviceKey);
            
    curl_setopt($chCURLOPT_RETURNTRANSFERtrue);
            
    curl_setopt($chCURLINFO_HEADER_OUTtrue);
            
    curl_setopt($chCURLOPT_HTTPHEADER, array(
                
    'Content-Type: application/json',
                
    'token: '.$sessionToken,
                ));

            
    $result curl_exec($ch);
            
    $json json_decode($resulttrue);

            if(
    array_key_exists("favorites"$json)){
                
    $array = array();
                foreach(
    $json['favorites'] as $key => $value){
                    
    $array[$key]['title'] = $value['title'];
                    
    $array[$key]['id'] = $value['id'];

                    foreach(
    $value['settings'] as $skey => $slots){
                        
    $array[$key]['slots'][$slots['slot_id']]['capsule_type_code'] = $slots['capsule_type_code'];
                        
    $array[$key]['slots'][$slots['slot_id']]['fan_speed'] = $slots['fan_speed'];
                        }
                    }
                
    moodo_Profil("_MoodoFav"$array);
                }
        
        return 
    $array;
        }

    // Funktion Intervaltypen auslesen
    // --------------------------------
    function moodo_getInterval(){
    Global 
    $sessionToken;

        
    $ch curl_init("https://rest.moodo.co/api/interval/");
            
    curl_setopt($chCURLOPT_RETURNTRANSFERtrue);
            
    curl_setopt($chCURLINFO_HEADER_OUTtrue);
            
    curl_setopt($chCURLOPT_HTTPHEADER, array(
                
    'Content-Type: application/json',
                
    'token: '.$sessionToken,
                ));

            
    $result curl_exec($ch);
            
    $json json_decode($resulttrue);
            
    $lang_de = array(
                
    "powerful Moodo" => "kraftvoll",
                
    "efficient Moodo" => "effizient",
                
    "saver Moodo" => "sparend"
                
    );

            if(
    array_key_exists("interval_types"$json)){
                foreach(
    $json['interval_types'] as $key => $value){
                    
    $array[$value['type']]['title'] = $lang_de[$value['description']];
                    
    $array[$value['type']]['work_minutes'] = $value['work_minutes'];
                    
    $array[$value['type']]['sleep_minutes'] = $value['sleep_minutes'];
                    }
                }
        
        return 
    $array;
        }

    // Funktion Funktionen einer Moodo Box ein/ausschalten
    // ----------------------------------------------------
    function moodo_switch($deviceKey$mode$state){
    Global 
    $sessionToken;

        switch(
    $mode){
            case 
    "box_status":
                
    $rest "boxes";
            break;
            case 
    "shuffle":
                
    $rest "shuffle";
            break;
            case 
    "interval":
                
    $rest "interval";
            break;
            case 
    "interval_type":
                
    $rest "interval";
            break;        
            default:
                return;
            break;
            }
            
        
    $ch curl_init("https://rest.moodo.co/api/".$rest."/".$deviceKey);
            
    curl_setopt($chCURLOPT_RETURNTRANSFERtrue);
            
    curl_setopt($chCURLINFO_HEADER_OUTtrue);

            
    $cl "";
            if(
    $mode == "interval_type"){
                
    curl_setopt($chCURLOPT_POSTtrue);
                
    curl_setopt($chCURLOPT_POSTFIELDSjson_encode(array("interval_type" => $state)));
                
    $cl 'Content-Length: '.strlen(json_encode(array("interval_type" => $state)));
                }
            elseif(
    $state == truecurl_setopt($chCURLOPT_POSTtrue);
            else 
    curl_setopt($chCURLOPT_CUSTOMREQUEST"DELETE");
            
            
    curl_setopt($chCURLOPT_HTTPHEADER, array(
                
    'Content-Type: application/json',
                
    $cl,
                
    'token: '.$sessionToken,
                ));

            
    $result curl_exec($ch);
        
        return 
    json_decode($resulttrue);
        }

    // Funktion Ventilatorstufe einer Moodo Box stellen
    // -------------------------------------------------
    function moodo_fanVolume($deviceKey$value){
    Global 
    $sessionToken;
        
        
    $ch curl_init("https://rest.moodo.co/api/intensity/".$deviceKey);
            
    curl_setopt($chCURLOPT_RETURNTRANSFERtrue);
            
    curl_setopt($chCURLINFO_HEADER_OUTtrue);
            
    curl_setopt($chCURLOPT_POSTtrue);
            
    curl_setopt($chCURLOPT_POSTFIELDSjson_encode(array("fan_volume" => $value)));
            
    curl_setopt($chCURLOPT_HTTPHEADER, array(
                
    'Content-Type: application/json',
                
    'Content-Length: '.strlen(json_encode(array("fan_volume" => $value))),
                
    'token: '.$sessionToken,
                ));
            
            
    $result curl_exec($ch);
        
        return 
    json_decode($resulttrue);
        }

    // Funktion Favoriten auswählen
    // -----------------------------
    function moodo_setFav($deviceKey$fan_volume$favSelect$buffer){
    Global 
    $sessionToken;
        
    $favIDs json_decode(GetValue($buffer), true);

        
    $data = array(
            
    "favorite_id" => $favIDs[$favSelect]['id'],
            
    "device_key" => (int)$deviceKey,
            
    "fan_volume" => GetValue($fan_volume),
            
    "duration_minutes" => 0
            
    );

        
    $ch curl_init("https://rest.moodo.co/api/favorites");
            
    curl_setopt($chCURLOPT_RETURNTRANSFERtrue);
            
    curl_setopt($chCURLINFO_HEADER_OUTtrue);
            
    curl_setopt($chCURLOPT_CUSTOMREQUEST"PATCH");
            
    curl_setopt($chCURLOPT_POSTFIELDSjson_encode($data));
            
    curl_setopt($chCURLOPT_HTTPHEADER, array(
                
    'Content-Type: application/json',
                
    'Content-Length: '.strlen(json_encode($data)),
                
    'token: '.$sessionToken,
                ));

            
    $result curl_exec($ch);

        return 
    json_decode($resulttrue);
        }

    /*******************************************************************************
    *******************************************************************************/
    ?>
    Gruß Manfred
    IPS 5.2 | Win u. Symbox | IPSView | Wago | Homematic | IPS-868 | Philips HUE | Modbus | PV FroniusHybrid | AEG USV | Qnap | Synology | IP Kameras | iRobot | Gardena R70Li | Sony TV / AV | Sat Duo2 | Philips/Samsung TV | Sonos | Buderus | RPi | Arduino || Visu: 24", 10", 7" Tablets ....

Ähnliche Themen

  1. Smarter SMC10EU Coffee in IPS?
    Von bennybunny im Forum Sonstige Funkkomponenten / Wetterstationen
    Antworten: 107
    Letzter Beitrag: 27.05.19, 09:24
  2. Antworten: 37
    Letzter Beitrag: 23.05.19, 10:08
  3. Mein smarter Wecker
    Von drapple im Forum Schaufenster
    Antworten: 7
    Letzter Beitrag: 22.09.18, 20:33
  4. Lampen smarter machen
    Von Suner im Forum Sonstige Funkkomponenten / Wetterstationen
    Antworten: 13
    Letzter Beitrag: 28.02.17, 20:17
  5. Daily Deal --- Smarter 1,8 l iKettle (Wasserkocker)
    Von honk0504 im Forum Sonstige Funkkomponenten / Wetterstationen
    Antworten: 26
    Letzter Beitrag: 15.12.15, 21:08