Node-blue Function zur Steuerung von HUE Lampen

Ich habe mal ein node-blue script zur Steuerung von HUE Lampen gebastelt, vielleicht kann es jemand brauchen.
Im wesentlichen kann das Script die Lampe Ein- und Aus-Schalten, Hoch und Runter dimmen und gespeicherte Profile setzen. Profile werden gesetzt durch wiederholtes drücken der Ein-Taste.

// 0 - On; 1 - Off; 2 - Dim up; 3 - Dim down

// some static parameters
$device_id = 62;                                                    // the homegear device id
$profiles = array( 
    array("payload"  => "relax", "brightness" => 144, "hue" => 7676),   // Relax: 144, 7676
    array("payload"  => "read", "brightness" => 254, "hue" => 7676),    // Read:  254, 7676
    array("payload"  => "dimmed", "brightness" => 77, "hue" => 8381),   // Dimmed: 77, 8381
    array("payload"  => "night", "brightness" => 1, "hue" => 8381),     // Night:   1, 8381
    );

// general statements
$bright = $hg->getValue($device_id, 1, "BRIGHTNESS");               // getting the current brightness
$state  = $hg->getValue($device_id, 1, "STATE");                    // getting the current brightness


if($inputIndex == 0) {              // left key short
    if ($state == 0) {
        $profile_nr = 0;
        $message['payload'] = 1;
        $hg->setValue($device_id, 1, "STATE", 1);                   // switch on without confirmation

    } else {
        $profile_nr = getNodeData("profile_nr");
        $message['profile_nr'] = $profile_nr;
        $message['payload'] = $profiles[$profile_nr]['payload'];
        $message['hue'] = $profiles[$profile_nr]['hue'];
        $message['brightness'] = $profiles[$profile_nr]['brightness'];
        $hg->putParamset($device_id, 1, "VALUES", array("BRIGHTNESS" => $message['brightness'], "HUE" => $message['hue']));

        $profile_nr++;
        if ($profile_nr >= count($profiles)) $profile_nr = 0;
        
    }
    setNodeData("profile_nr", $profile_nr);
    return $message;


} else if($inputIndex == 1) {       // right key short
    $hg->setValue($device_id, 1, "STATE", 0);                       // simple switch off
    $message['payload'] = 0;
    return $message;
    
} else if($inputIndex == 2) {       // left key long
    $bright += 10;                                                  // increase brightness
    if ($bright > 254) $bright = 254;                               // not over 254
    $hg->setValue($device_id, 1, "FAST_BRIGHTNESS", $bright);       // set the value without confirmation

} else if($inputIndex == 3) {       // right key long
    $bright -= 10;                                                  // lower the brightness
    if ($bright < 0) $bright = 1;                                   // not below 1
    $hg->setValue($device_id, 1, "FAST_BRIGHTNESS", $bright);       // set the value without confirmation

}
3 Likes