Light Level control + Scene activator don't works

8 years 11 months ago #1502 by osalval
Light Level Works but adding scene activator don't, I can't see was wrong:

/*
Light Level control TV
*/
int ThresholdHIGH = 520; // HIGH Threshold
int ThresholdLOW = 420; // LOW Threshold

public void Setup()
{
EventHelper.ModuleChangedHandler((o, m, p) =>
{
// filter digital switch
if (m.Domain == Domains.VIRTUAL && m.Address == "N3S0" && p.Property == "Sensor.DigitalValue")
{
// filter when switch on event
if (p.Value == "1")
{
if (m.Domain == Domains.MYSENSORS && m.Address == "N23S1" && p.Property == "Sensor.LightLevel")
{
Console.WriteLine(m.Address + " property " + p.Property + " value " + p.Value);
ModuleParameter LL = ModuleHelper.GetProperty(Domains.MYSENSORS, "N23S1", "Sensor.LightLevel");
Console.WriteLine("Light Level: " + LL.DecimalValue);

if (LL.DecimalValue > ThresholdHIGH) {
Console.WriteLine("Light Level HIGH: " + LL.DecimalValue);
DriverHelper.ProcessCommad(Domains.MYSENSORS, "N23S0", "ControlDown", "");

} else if (LL.DecimalValue <= ThresholdHIGH && LL.DecimalValue >= ThresholdLOW) {
Console.WriteLine("Light Level NORMAL: " + LL.DecimalValue);
DriverHelper.ProcessCommad(Domains.MYSENSORS, "N23S0", "ControlStop", "");

} else if (LL.DecimalValue < ThresholdLOW) {
Console.WriteLine("Light Level LOW: " + LL.DecimalValue);
DriverHelper.ProcessCommad(Domains.MYSENSORS, "N23S0", "ControlUp", "");
}
}
}
} return true;
});
}

Please Log in or Create an account to join the conversation.

8 years 11 months ago #1543 by osalval
I see that program executes only once, as first line after:
EventHelper.ModuleChangedHandler((o, m, p) =>
is to detect change of switch
So first should be to detect change of Light Level and then introduce detection of switch to execute the 3 thresholds

Please Log in or Create an account to join the conversation.

8 years 11 months ago #1544 by osalval
Inverting both:
if (m.Domain == ................
doesn't work neither.
I suppose there sould be only 1 filter.

Please Log in or Create an account to join the conversation.

8 years 11 months ago #1545 by osalval
Solved :)
/* Light Level control TV */
int ThresholdHIGH = 720; // HIGH Threshold
int ThresholdLOW = 520; // LOW Threshold
public void Setup()
{
EventHelper.ModuleChangedHandler((o, m, p) =>
{ // filter Event Change Sensor.LightLevel
if (m.Domain == Domains.MYSENSORS && m.Address == "N23S1" && p.Property == "Sensor.LightLevel")
{
ModuleParameter LL = ModuleHelper.GetProperty(Domains.MYSENSORS, "N23S1", "Sensor.LightLevel");
Console.WriteLine("Light Level: " + LL.DecimalValue);
// filter to execute only when digital switch = ON
ModuleParameter SC = ModuleHelper.GetProperty(Domains.VIRTUAL, "N3S0", "Sensor.DigitalValue");
Console.WriteLine("Scene control: " + SC.DecimalValue);

if (LL.DecimalValue > ThresholdHIGH && SC.DecimalValue == 1) {
Console.WriteLine("Light Level HIGH: " + LL.DecimalValue);
DriverHelper.ProcessCommad(Domains.MYSENSORS, "N23S0", "ControlDown", "");

} else if (LL.DecimalValue <= ThresholdHIGH && LL.DecimalValue >= ThresholdLOW && SC.DecimalValue == 1) {
Console.WriteLine("Light Level NORMAL: " + LL.DecimalValue);
DriverHelper.ProcessCommad(Domains.MYSENSORS, "N23S0", "ControlStop", "");

} else if (LL.DecimalValue < ThresholdLOW && SCD.DecimalValue == 1) {
Console.WriteLine("Light Level LOW: " + LL.DecimalValue);
DriverHelper.ProcessCommad(Domains.MYSENSORS, "N23S0", "ControlUp", "");
}
} return true;
});
}

Please Log in or Create an account to join the conversation.

Time to create page: 0.276 seconds

Forum latest

  • No posts to display.