Hi,
Maybe someone can help me with this one. I’m trying to change a variable using a Flow Script. However, I’m not successful. The status variable has a custom action, a PHP script. I think this is why I’m unable to change the status variable using a Flow Script. Here’s the PHP script (the PHP script is made by a very helpful forum member):
<?php
//Start writing your code here
$IdentState = 'StatusVariable';
$IdentIntensity = 'IntensityVariable';
If ($_IPS['SENDER'] == 'Variable' || $_IPS['SENDER'] == 'WebFront' || $_IPS['SENDER'] == 'VoiceControl' || $_IPS['SENDER'] == 'Action') { // execute this script on variable change only
$Sender = $_IPS['VARIABLE']; // Which variable triggers this script?
$ParentInstance = IPS_GetParent($Sender); // Who is the parent instance of this variable?
$ChildsOfInstance = IPS_GetChildrenIDs($ParentInstance); // array of all instance childs
If (IPS_GetObject($Sender)['ObjectIdent'] == $IdentState) // if the trigger variable is the state variable
{
If ($_IPS['VALUE']) // boolean true
//If requested action is „on“ and current status is „off“, load intensity value from saved variable.
{
$Intensity = (int)IPS_GetObject($ParentInstance)['ObjectInfo']; // reading the intensity, stored in the instance info area
foreach ($ChildsOfInstance as $Child) //looking for the matching intensity variable, under the instance
{
If (IPS_GetObject($Child)['ObjectIdent'] == $IdentIntensity) //found intensity variable
{
RequestAction($Child, $Intensity); // send the read intensity value the device
}
}
}
else // boolean false
// If requested action is „off“ and current status is „on“, save Intensity value to some variable, when successful change „status“ to „off“
{
foreach ($ChildsOfInstance as $Child) //looking for the matching intensity variable, under the instance
{
If (IPS_GetObject($Child)['ObjectIdent'] == $IdentIntensity) //found intensity variable
{
$Intensity = GetValue($Child); // getting the current value
IPS_SetInfo($ParentInstance,$Intensity); // store the current intensity into the info area of the instance
RequestAction($Child, 0); // send intensity 0 to the device to switch it off
}
}
}
}
}
else
{
IPS_LogMessage($_IPS['SELF'],'Script can only be executed on variable change. Sender was: '.$_IPS['SENDER']);
}
?>