Hi,
I used to have a SmartControl Code running on top of Dimmers in order to control them in the following way :
short press -> toggle
long press -> dim+ or dim-
release -> change dim direction.
This program was running fin until the LastUpdateTime method was removed.
Does anyone knows the replacement method for this?
I tried changing the code but nothing works as fine as it did before. Anyone any solution to this problem;
(The new code I addes is tagged between START and END NEW CODE, the old code is put in comment)
Thx,
Boeky
var SMART_CONTROL_ENABLE = "HomeGenie.SmartControl.Enable";
var DIGITAL_INPUT_MODULE_NAME = "HomeGenie.SmartControl.DigitalInputModule";
//var DIGITAL_OUTPUT_MODULE_NAME = "HomeGenie.SmartControl.DigitalOutputModule";
int LEVEL_ON = 1;
double LONG_PRESS_SECONDS = 1.5;
int DIM_AMOUNT = 5;
var DIM_DIRECTION = "down";
//
var smart_devices = Modules.WithFeature(SMART_CONTROL_ENABLE);
//
When.ModuleParameterIsChanging((module, parameter) => {
// TODO: the sensor buttons should also be marked with a specific feature
if (module.IsOfDeviceType("Sensor"))
{
if (parameter.Name == "Status.Level")
{
var sensorLevel = parameter.DecimalValue;
var levelTimestamp = parameter.UpdateTime.Ticks;
if (sensorLevel == LEVEL_ON)
{
Pause(LONG_PRESS_SECONDS);
if (levelTimestamp == parameter.UpdateTime.Ticks)
{
// while the button is kept pressed...
while (levelTimestamp == parameter.UpdateTime.Ticks)
{
// Dim all SmartControl enabled dimmers by 5%
smart_devices.Each((mod) =>
{
if (mod.Parameter(DIGITAL_INPUT_MODULE_NAME).Value == module.Instance.Name && mod.Parameter(DIGITAL_INPUT_MODULE_NAME).Value != "")
{
if(DIM_DIRECTION == "down")
{
mod.Level -= DIM_AMOUNT;
}
else
{
mod.Level += DIM_AMOUNT;
}
}
return false;
});
}
//Changing DIM_DIRECTION
if(DIM_DIRECTION == "down")
{
DIM_DIRECTION = "up";
}
else
{
DIM_DIRECTION = "down";
}
} else // START NEW CODE
{
smart_devices.Each((mod) =>
{
if (mod.Parameter(DIGITAL_INPUT_MODULE_NAME).Value == module.Instance.Name && mod.Parameter(DIGITAL_INPUT_MODULE_NAME).Value != "")
{
mod.Toggle();
//Reset DIM_DIRECTION to down when the lamp is turned on.
if(mod.Level > 0)
{
DIM_DIRECTION = "down";
}
}
return false;
});
} //END NEW CODE
}
//else
//{
// timeout before turning it off
//var endTime = parameter.UpdateTime;
//var startTime = parameter.LastUpdateTime;
//var pressDuration = new TimeSpan(endTime.Ticks - startTime.Ticks);
// short press
//if (pressDuration.TotalSeconds < LONG_PRESS_SECONDS)
//{
//smart_devices.Each((mod) =>
//{
//if (mod.Parameter(DIGITAL_INPUT_MODULE_NAME).Value == module.Instance.Name && mod.Parameter(DIGITAL_INPUT_MODULE_NAME).Value != "")
//{
//mod.Toggle();
//Reset DIM_DIRECTION to down when the lamp is turned on.
//if(mod.Level > 0)
//{
//DIM_DIRECTION = "down";
//}
//}
//return false;
//});
//}
//}
}
}
return true;
});
Program.GoBackground();