This page last changed on Sep 15, 2013 by keithmmt.

Hi,

I would like to offset the value of co2 sensor, for an example when sensor shown 1678 and want to subtract 800 which becomes to 878.
I had also checking pervious topic articles and found similar solutions as below, but not properly showing the value, hope help to advise how can do that for this case.
many thanks,
Keith

rule "Correct CO2"
when
$evt : Event(source=="co2sensor")
then
double correctedValue = Double.parseDouble($evt.getValue().toString()) - 800;
execute.command("VirtualWrite", Double.toString(correctedValue));
end

Your rule seems to be OK if your virtual sensor is of type 'custom' (without custom state items).

In case of a virtual range sensor try the following:

execute.command("VirtualWrite", Integer.toString((int)correctedValue));

In general I'ld suggest the following procedure to get it running:

  1. Add logging:
     
    System.out.println("Rule : Correct CO2");
    

    You should see this message in the console

  2. Play around with constants:
     
    execute.command("VirtualWrite", "820");
    
Posted by rhitz at Sep 15, 2013 12:46

I've using the custom sensor without state and changed as following but still not properly show the value.
please help to check.

rule "Correct co2"
when
$evt : Event(source=="co2sensor")
then
double correctedValue = Double.parseDouble($evt.getValue().toString()) - 800;
execute.command("VirtualWrite", Integer.toString((int)correctedValue));
System.out.println("Rule : Correct co2");
end

Posted by keithmmt at Sep 16, 2013 10:08

As I've already said your original rule is OK if you use a custom sensor. The following rule should work:

rule "Correct CO2"

when

  $evt : Event(source=="co2sensor")

then

  double correctedValue = Double.parseDouble($evt.getValue().toString()) - 800;
  execute.command("VirtualWrite", Double.toString(correctedValue));

end

If it doesn't work simplify your rule and check if the rule is triggered:

rule "Correct CO2"

when

  $evt : Event(source=="co2sensor")

then

  System.out.println("Rule : Correct CO2");

end

If you do not see the log message "Rule : Correct CO2" in the console your CO2 sensor doesn't send data or there is something wrong with the source name "co2sensor".

Posted by rhitz at Sep 16, 2013 20:26

Hi Rainer,

Thanks help! I've simplify the rule and doesn't showing the message.
i will double checking source "co2sensor"

Many thanks!

Posted by keithmmt at Sep 17, 2013 07:09
Document generated by Confluence on Jun 05, 2016 09:40