Treppenhausmodul: Dauer programmatisch einstellen?

Ich benutze das Treppenhausmodul von IPS. Gerne würde ich unterschiedliche Dauer der An-Zeit tagsüber und nachts einstellen. Momentan habe ich mir beholfen, indem ich 2 Kopien der Steuerung eingerichtet habe, welche zu gewissen Tageszeiten aktiviert/inaktiviert werden. Dies ist aber nicht gerade elegant. Geht das programmatisch, z.B. mit PHP?

Ich mache das in einem Aktionsskript, aber die Logik ist ident

SetValue($_IPS['VARIABLE'], $_IPS['VALUE']);
$lichtid=IPS_GetObject($_IPS['VARIABLE'])["ObjectInfo"];
IPS_SetProperty($lichtid,"Duration",$_IPS['VALUE']);
IPS_ApplyChanges($lichtid);

Ich nutze mehrere „Trepphausinstanzen“ und in der Variable für die Einschaltdauer habe ich in der Beschreibung der dazugehörigen ID von der Treppenhausinstanz stehen. Somit brauche ich nur ein Aktionsskript und kann es für mehrere verwenden.
Mit dem IPS_SetProperty wird die Einschaltdauer gesetzt und mit IPS_ApplyChanges gespeichert.

3 „Gefällt mir“

Danke. Ich schäme mich ein bisschen, dass ich dies vergessen habe - aber wie kann ich diesen Skript auslösen, wenn sich Location/IsDay jeweils ändert? Es ist mir peinlich, aber ich habe IPS seit einigen Jahren vernachlässigt…

Nachtrag: ich habe es mir von ChatGPT erklären lassen. Stimmt es aber? Siehe dies.

Ich habe den Skript etwas erweitert.

<?php
/*
README:
-----------------------------------------------------------------------------------
This script sets the "Duration" property of a staircase light control instance 
in IP-Symcon. The desired duration depends on:

1) The IP-Symcon variable named "IsDay"
   - If "IsDay" is TRUE, the script uses a custom day duration.
   - If "IsDay" is FALSE and the current hour >= 18, it uses a custom night duration.
   - If "IsDay" is FALSE and the current hour < 18, it uses the night duration as a fallback.

2) The script automatically searches for a variable named "IsDay".
   - If it cannot find it, the script reports an error and exits.

3) The script checks whether the configured ID is an instance (the staircase light control).

4) If the script is triggered manually (SENDER = "Execute"), it checks for two events:
   - An on-change event on "IsDay" (named "IsDay Trigger")
   - A daily event at 18:00 (named "NightTime Trigger")
   If either event is missing, the script creates it and attaches it to itself.

WHAT YOU NEED TO CONFIGURE:
-----------------------------------------------------------------------------------
- $dayDuration:       Duration (unit depends on your instance) when "IsDay" is TRUE
- $nightDuration:     Duration when "IsDay" is FALSE and time >= 18:00
- $targetInstanceID:  ID of your Staircase Light Control instance
-----------------------------------------------------------------------------------
*/

echo "----------------------------------------\n";
echo "Starting Staircase Light Duration Script\n";
echo "----------------------------------------\n";

// -----------------------------------------------------------
// Configuration
// -----------------------------------------------------------
$dayDuration       = 10;       // Duration if IsDay == TRUE
$nightDuration     = 1;        // Duration if IsDay == FALSE and time >= 18:00
$targetInstanceID  = 13332;    // Staircase light control instance to be configured


// -----------------------------------------------------------
// 1) Auto-find a variable named "IsDay"
// -----------------------------------------------------------
echo "Searching for a variable named 'IsDay'...\n";

$isDayID = null;
foreach (IPS_GetObjectList() as $objID) {
    $obj = IPS_GetObject($objID);
    // Check if this is a variable (ObjectType = 2) named "IsDay"
    if ($obj['ObjectType'] === 2 && IPS_GetName($objID) === "IsDay") {
        $isDayID = $objID;
        echo "  Found 'IsDay' with ID #$isDayID.\n";
        break;
    }
}

// If no "IsDay" variable found, echo error and stop
if ($isDayID === null) {
    echo "ERROR: No variable named 'IsDay' found. Exiting...\n";
    return;
}

// -----------------------------------------------------------
// 2) Check that $targetInstanceID is an actual instance
// -----------------------------------------------------------
echo "Using target instance ID: #$targetInstanceID.\n";

if (!IPS_InstanceExists($targetInstanceID)) {
    echo "ERROR: ID #$targetInstanceID is not an instance or does not exist. Exiting...\n";
    return;
}
echo "Confirmed that #$targetInstanceID is a valid instance.\n";

// -----------------------------------------------------------
// 3) Determine the desired duration based on IsDay + current time
// -----------------------------------------------------------
$isDay       = GetValue($isDayID);  // TRUE if daytime
$currentHour = (int) date("G");     // 0..23

echo "IsDay current value: " . ($isDay ? "TRUE" : "FALSE") . "\n";
echo "Current Hour: $currentHour\n";

if ($isDay) {
    // If IsDay == TRUE
    $desiredDuration = $dayDuration;
    echo "Logic: Using daytime duration: $dayDuration.\n";
} else {
    // If IsDay == FALSE
    if ($currentHour >= 18) {
        $desiredDuration = $nightDuration;
        echo "Logic: Using nighttime duration: $nightDuration (>= 18:00).\n";
    } else {
        // Optional fallback if before 18:00 and IsDay == false
        $desiredDuration = $nightDuration;
        echo "Logic: Using nighttime duration: $nightDuration (< 18:00 fallback).\n";
    }
}

// -----------------------------------------------------------
// 4) Apply the changes to your staircase light control
// -----------------------------------------------------------
IPS_SetProperty($targetInstanceID, "Duration", $desiredDuration);
IPS_ApplyChanges($targetInstanceID);

echo "Applied Duration=$desiredDuration to instance #$targetInstanceID.\n";

// -----------------------------------------------------------
// 5) If the script is triggered manually, ensure the needed events exist
// -----------------------------------------------------------
if ($_IPS['SENDER'] === "Execute") {
    echo "\nScript triggered manually. Checking for required events...\n";

    $foundIsDayTrigger    = false; // Trigger that fires on IsDay changes
    $foundNightTimeTrigger = false; // Trigger that fires daily at 18:00
    $allEvents = IPS_GetEventList();

    foreach ($allEvents as $eid) {
        $event = IPS_GetEvent($eid);
        $eventName = IPS_GetName($eid);

        // Look for an event named "IsDay Trigger" that monitors changes on $isDayID
        if ($event['EventType'] === 0                // 0 = triggered event
            && $eventName === "IsDay Trigger"        
            && $event['TriggerVariableID'] === $isDayID
            && $event['TriggerType'] === 1) {        // 1 = OnChange
            $foundIsDayTrigger = true;
        }

        // Look for an event named "NightTime Trigger" that runs daily at 18:00
        if ($event['EventType'] === 1                // 1 = cyclic event
            && $eventName === "NightTime Trigger") {
            // We won't check the exact time settings here, just the name.
            $foundNightTimeTrigger = true;
        }
    }

    // Create the IsDay Trigger if missing
    if (!$foundIsDayTrigger) {
        echo "Creating missing 'IsDay Trigger' event...\n";
        $eid = IPS_CreateEvent(0); // 0 = Triggered Event
        IPS_SetName($eid, "IsDay Trigger");
        IPS_SetParent($eid, $_IPS['SELF']); // Attach to this script
        IPS_SetEventTrigger($eid, 1 /* OnChange */, $isDayID);
        IPS_SetEventActive($eid, true);
        echo "  'IsDay Trigger' event created (ID #$eid).\n";
    } else {
        echo "Event 'IsDay Trigger' already exists.\n";
    }

    // Create the NightTime Trigger if missing
    if (!$foundNightTimeTrigger) {
        echo "Creating missing 'NightTime Trigger' event...\n";
        $eid = IPS_CreateEvent(1); // 1 = Cyclic Event
        IPS_SetName($eid, "NightTime Trigger");
        IPS_SetParent($eid, $_IPS['SELF']); // Attach to this script

        // Set it to run daily at 18:00
        // Time configuration:
        // IPS_SetEventCyclic($eventID, $dateType, $dateValue, $dateDay, $timeType, $timeValue, $timeDay);
        // For daily we use (0,0,0,0,1,1,0) => every day, type=1 (once per day).
        IPS_SetEventCyclic($eid, 0, 0, 0, 1, 1, 0);
        IPS_SetEventCyclicTimeFrom($eid, 18, 0, 0);

        IPS_SetEventActive($eid, true);
        echo "  'NightTime Trigger' event created (ID #$eid) for 18:00 daily.\n";
    } else {
        echo "Event 'NightTime Trigger' already exists.\n";
    }
}

echo "----------------------------------------\n";
echo "Script completed successfully.\n";
echo "----------------------------------------\n";
?>