This page last changed on Dec 20, 2013 by sattva.

Switch doesn't react. Please help to understand how to use it.

Following objects created:

Sensor: SensBoilerOnOff, type: switch
  Command: BoilerStatus. In-memory virtual command, Command: Status, Address: adrboiler

Switch: SwBoiler, Sensor: SensBoilerOnOff, command(on): BoilerOn, command(off): BoilerOff
  Command: BoilerOn. In-memory virtual command, Command: on, Address: adrboiler.
  Command: BoilerOff. In-memory virtual command, Command: off, Address: adrboiler.

We have 3 connands: BoilerStatus, BoilerOn, BoilerOff with address: adrboiler.
Don't know if it is correct.

UIDesign
  Label -> Sensor -> SensBoilerOnOff. On text: on. Off text: off.
  Button1 (On) -> Command: BoilerOn.  In-memory virtual command, Command: on, Address: adrboiler.
  Button2 (Off) -> Command: BoilerOff. In-memory virtual command, Command: off, Address: adrboiler.

When I click buttons, Label changes to "on" or "off". It's ok.

  execute.command("BoilerOff", "off"); // works fine - label changes.

  Event (source == "SensBoilerOnOff") // works fine - I can trace button pressed.

  switches.name("SwBoiler").off(); // Even doesn't start!

Even doesn't start! - some errors on a non-stop listing.

rule "Boiler on/off"
when
  Event (source == "SwBoiler", value == "on") // Never works!
then
  execute.command("TemperOut",  "90");
end

Doesn't react - Never works!.

Please help to find my misunderstanding. I looked in many examples, but it doesn't help.
Thank you in advance.

Mistakes found!

Incorrect!!!
---
rule "Boiler on/off"
when
  Event (source == "SwBoiler", value == "on") // <== SwBoiler - switch name, but it must be sensor name!
then
  execute.command("TemperOut",  "90");
end
Correct:
---
rule "Boiler on/off"
when
  Event (source == "SensBoilerOnOff", value == "on") // <== SwBoiler - switch name, but it must be sensor name!
then
  execute.command("TemperOut",  "90");
end

In this case sommand will be executed only once as switch changed its state to "on".

If we need to trace switch state we can use the following rule:
---
rule "Boiler on. Difference calculation."
when
  CustomState (source == "SensLiters", $TotalLiters: value) // Value 1 to compare
  CustomState (source == "SensWaterStartL", $UsageStartLit: value) // Value 2 to compare
  Switch (source == "SensBoilerOnOff", value == "on") // <= Again sensor name "SensBoilerOnOff" not switch itself!
then

  ... Some calculations here with Value 1 and Value 2 ...

  execute.command("Water in boiler",  sWaterRest ); // Output result of calculations
end

Possibly it is obvious for all, but not for a newbie like me.

Posted by sattva at Dec 21, 2013 01:24

Thanks for sharing, valuable information.
Kind regards,
Neil.

Posted by nwe at Dec 24, 2013 08:36
Document generated by Confluence on Jun 05, 2016 09:39