This page last changed on Oct 11, 2013 by dwillems.

Hi,

At the moment I am creating a demo for a home automation panel. One of the elements is setting the temperature. This will be just changing the value in a label for now. The set temperature can be changed by pressing scenes switches (such as Away 12, Sleep 15, Home 21, Comfort 23) and by pressing up and down buttons to changes the currently set temperature by minus or plus one.

Changing the temperature using switches works correctly, example of one of the switches:
rule "ClimateScene1"
when
$evt : Event(source == "climate1_Sensor", value == "on")
then
execute.command("climate2_OFF");
execute.command("climate3_OFF");
execute.command("climate4_OFF");
execute.command("temp_ON", 12);
end

However, I dont know how to increase and decrease the temperature with the up and down buttons, could someone help me with that?

Also, how do I add the celsius symbol ° to the label?

Thank you and kind regards,

Don

I assume that you have temp_STATUS sensor which keeps temperature (by the way you can use it instead temp_ON).
To increase/decrease temperature with buttons you will need create 2 switches, one for increase and the second for decrease. Then write rules:


rule "Increase Temp"
when
  $e: Event(source=="Increase_temp_Sensor",value=="on")
  $t: Event(source=="temp_STATUS")
then
  execute.command("Increase_temp_STATUS","off")
  execute.command("temp_STATUS", String.format("%.1f"), Double.parseDouble($t.getValue().toString())+1);
end

rule "Decrease Temp"
when
  $e: Event(source=="Decrease_temp_Sensor",value=="on")
  $t: Event(source=="temp_STATUS")
then
  execute.command("Decrease_temp_STATUS","off")
  execute.command("temp_STATUS", String.format("%.1f"), Double.parseDouble($t.getValue().toString())-1);
end

Adding ° to the label can be done is String.format("%.1f \u2103",...) but then you would need to get substring in the parseDouble call.

Posted by aktur at Oct 11, 2013 15:12

When using these rules, the temperature increases/decreases twice with one button press. Any ideas why?

rule "Increase Temp"
no-loop
when
  $e: Event(source=="Increase_temp_Sensor",value=="ON")
  $t: Event(source=="temp_Sensor")
then
  double correctedValue = Double.parseDouble($t.getValue().toString()) +0.5;
  execute.command("Increase_temp_STATUS","off");
  execute.command("temp_ON", String.format("%.1f",correctedValue));
end

rule "Decrease Temp"
no-loop
when
  $e: Event(source=="Decrease_temp_Sensor",value=="ON")
  $t: Event(source=="temp_Sensor")
then
  double correctedValue = Double.parseDouble($t.getValue().toString()) -0.5;
  execute.command("Decrease_temp_STATUS","off");
  execute.command("temp_ON", String.format("%.1f",correctedValue));
end
Posted by dwillems at Oct 17, 2013 14:19

There's a typo. Event source name should be same as what you set to off in first execute command.

 Increase_temp_Sensor 
Posted by atamariya at Oct 17, 2013 14:56

Indeed I've reproduced the behavior on my setup. It seems that the rules engine gets 2 calls (sometimes only one). Therefore it increases temp_ON twice, sometimes once. One, a bit ugly, solution would be to delay rules execution so the second immediate call will be suppressed. This can be done with timer(int: 500ms) statement. However, the real solution would be to investigate why the rule is called twice when it should be called only once.

Posted by aktur at Oct 20, 2013 10:28

Event source name is a sensor name while the execution is a command name. Sensor and command can have the same names because they are in different name spaces but they don't have to, which is the case here.

Posted by aktur at Oct 20, 2013 10:30

May be sensor polling thread is colliding with button press action.

Posted by atamariya at Oct 20, 2013 10:53

This is my idea too. This is either bug or a feature

Posted by aktur at Oct 20, 2013 10:59
Document generated by Confluence on Jun 05, 2016 09:40