Hi there,
Another wall switch question from me, currently I'm using the following script to detect a change in a wall switch value (
Trigger script):
var wallSwitch = Modules.WithName("Switch 1").Get();
return (wallSwitch.WasFound && wallSwitch.Parameter("Sensor.Generic").DecimalValue == 21);
This works fine, but it only works when the value of the switch has
changed, not when it is pressed.
For example, I press the top right button on the switch (value 21) and the light goes on. Afterwards I press the bottom right button (value 41) and the light goes off, works perfectly.
But, when I press the top right button (value 21) and the light switches off for some other reason (time based event, switch off via app etc.) and I press the top right button again (value 21 again) the Trigger script does not return true because the value has not changed (switch value was, and still is 21)
(I hope you're still following me on this
)
So I decided to try to catch the button pressed event with the following code in the
trigger script:
When.ModuleParameterChanged( (module, parameter) =>
{
if (module.Is("Switch 2") && parameter.DecimalValue == 21)
{
Program.Notify("Debug", "Top right button pressed");
return true;
}
else
{
return false;
}
});
This won't compile, I get the error ''Not all code paths return a value"
So I tried this:
bool retValue = false;
When.ModuleParameterChanged( (module, parameter) =>
{
if (module.Is("Switch 2") && parameter.DecimalValue == 21)
{
Program.Notify("Debug", "Top right button pressed");
retValue = true;
}
else
{
retValue = false;
}
});
return retValue;
The Program.Notify fires, but the 'Code to Run' doesn't, retValue is always false. I realize that I'm misunderstanding how
ModuleParameterChanged actually works, I'm hoping someone can point me in the right direction.
Tanks for any help.