Problem defining a variable from a sensor

54 views
Skip to first unread message

ReneS

unread,
May 14, 2017, 1:05:37 PM5/14/17
to OpenRemote
Hello all,

I'm having a problem defining a variable from a sensor state.
The sensor is a HTTP GET command and produces a value, for example 16.5. I'm not sure is this is a "char" string.

This is the command I'm using:
CustomState(source == "Dummy", setpointinit : value);

In boot.log I see the following error:
Rule Compilation error source cannot be resolved to a variable
Syntax error on token ":", :: expected

Can someone help?

Thanks in advance
Cheers,
Rene

Michal Rutka

unread,
May 15, 2017, 1:02:09 AM5/15/17
to OpenRemote
Seems like there is ; after CustomState(). Remove it. In case of more errors send the complete code.

ReneS

unread,
May 15, 2017, 1:45:52 PM5/15/17
to OpenRemote
Hello Michal,

Removing the ; did not solve my problem. I guess I'm going about it the wrong way.
I'm not a Java programmer :-)
The thing I'm trying to do is relatively simpel:
Assign an initial value to an in-memory sensor using the value of another sensor.
I've been looking at a lot of examples but I can't work it out...

Could you give me some pointers?
Thanks.

Regards,
Rene

Michal Rutka

unread,
May 15, 2017, 2:59:29 PM5/15/17
to OpenRemote
Are you getting the same syntax error? Please send the complete rule which isn't working as it should. Also, please try to explain the complete scenario you want to do.

ReneS

unread,
May 16, 2017, 12:55:13 PM5/16/17
to OpenRemote
As a basis I used the demo example. The functionality is a display of a temperature with a "+" an "-" button for controlling a thermostat.
This part I got working. My problem is setting the initial value of the display. For this I want to use the acual setting of the thermostat.
The sensor is working but I can't get this value into a variable.
The error is:


Rule Compilation error source cannot be resolved to a variable
setpointinit cannot be resolved

Syntax error on token ":", :: expected

Code of the rule:

rule "-PSB: Init"
salience 10
then

  CustomState(source == "Dummy", setpointinit : value);
  execute.command("kachel-setpoint-inc","OFF");
  execute.command("kachel-setpoint-dec","OFF");
end



Michal Rutka

unread,
May 16, 2017, 1:03:45 PM5/16/17
to OpenRemote
At least you've missed the LHS of the rule. It should look something like:

rule "init"
when
  CustomState(source == "Dummy", setpointinit : value)
then
  // and here you need to set the initial value of your thermostat
  execute.command("your thermostat setpoint command", setpointinit.toString() );
end

ReneS

unread,
May 16, 2017, 2:30:08 PM5/16/17
to OpenRemote
Ok, that gets the value in the variable but it gets updated every time the value of "Dummy" changes...



On Sunday, May 14, 2017 at 7:05:37 PM UTC+2, ReneS wrote:

Michal Rutka

unread,
May 16, 2017, 4:10:21 PM5/16/17
to OpenRemote
Then you need to init it only when the value is not initialized yet, like this one

rule "init"
when


CustomState(source == "Dummy", setpointinit : value)

Event(source=="your thermostat set point sensor in-memory var", value=="")


then
// and here you need to set the initial value of your thermostat
execute.command("your thermostat setpoint command", setpointinit.toString() );
end

Uninitialized var can be either empty stiring "" or "status". You can have two rules to cover both.

ReneS

unread,
May 17, 2017, 1:00:52 PM5/17/17
to OpenRemote
Hi Michal,

Finally I've got it working :-)
I think the main problem was that the defining of the variable is done in the "when" part. That wasn't logical to me...
Thanks for the assist.

Cheers,
Rene


On Sunday, May 14, 2017 at 7:05:37 PM UTC+2, ReneS wrote:

Michal Rutka

unread,
May 17, 2017, 5:18:38 PM5/17/17
to OpenRemote
Glad to hear this! It would be nice if you can post the final rules which are working for you. This way, the others with similar problem can see how it should be done.

ReneS

unread,
May 18, 2017, 1:33:29 PM5/18/17
to OpenRemote
And here's the complete code of the rules for my thermostat:

package org.openremote.controller.protocol;

import java.util.*;
import java.util.Date;
import java.text.SimpleDateFormat;
import java.io.*;
import org.openremote.controller.model.event.*;
import org.openremote.controller.utils.Logger;
import org.openremote.controller.Constants;

global org.openremote.controller.statuscache.CommandFacade execute;

function void log(String msg)
{
  Logger.getLogger(Constants.RUNTIME_EVENTPROCESSOR_LOG_CATEGORY + ".drools").debug(msg);
}

declare Event
  @role(event)
end


rule "init"
salience 10
when
CustomState(source == "kachel-setpoint-status", setpointinit : value)
Event(source == "kachel-setpoint", value == "")
then
  execute.command("kachel-setpoint",setpointinit);

  execute.command("kachel-setpoint-inc","OFF");
  execute.command("kachel-setpoint-dec","OFF");
end

function Double _GetTemp(Object o){
  String s = o.toString();
  try{
    if(s.length()>1){
      return(Double.parseDouble(s.substring(0, s.length()-1)));
    }else{
      return(0.0);
    }
  } catch (NumberFormatException e) {
    return(0.0);
  }
}

function String _ShiftTemp(Object o, double sh){
  String s = o.toString();
  try{
    Double t = Double.parseDouble(s.substring(0,s.length()-1)) + sh;
    return(String.format("%.1f\u00B0",t));
  } catch (NumberFormatException e) {
    return("0.0\u00B0");
  }
}

function String _ShiftTemp_noformat(Object o, double sh){
  String s = o.toString();
  try{
    Double t = Double.parseDouble(s.substring(0,s.length()-1)) + sh;
String rs = t.toString();
    return(rs.substring(0,4));
  } catch (NumberFormatException e) {
    return("0.0\u00B0");
  }
}

rule "kachel-setpoint inc"
  timer(int:10ms)
when
  Event(source == "kachel-setpoint", $v: value, eval(_GetTemp(value) < 23))
  Event(source == "kachel-setpoint-inc" , value == "ON")
then
  execute.command("kachel-setpoint-inc","off");

  execute.command("kachel-setpoint-dec","OFF");
  execute.command("kachel-setpoint", _ShiftTemp($v.toString(), 0.5));
  execute.command("kachel-setpoint-set", _ShiftTemp_noformat($v.toString(), 0.5));
end

rule "kachel-setpoint dec"
  timer(int:10ms)
when
  Event(source == "kachel-setpoint", $v: value, eval(_GetTemp(value) > 15))
  Event(source == "kachel-setpoint-dec" , value == "ON")
then

  execute.command("kachel-setpoint-inc","OFF");
  execute.command("kachel-setpoint-dec","off");
  execute.command("kachel-setpoint", _ShiftTemp($v.toString(), -0.5));
  execute.command("kachel-setpoint-set", _ShiftTemp_noformat($v.toString(), -0.5));
end

rule "kachel-setpoint INC/dec" // needed when change on the boundary
  salience -10
  timer(int:300ms)
when
  Event(source == "kachel-setpoint-inc" , value == "ON")
then
  execute.command("kachel-setpoint-inc","off");

  execute.command("kachel-setpoint-dec","OFF");
end

rule "kachel-setpoint inc/DEC" // needed when change on the boundary
  salience -10
  timer(int:300ms)
when
  Event(source == "kachel-setpoint-dec" , value == "ON")
then

  execute.command("kachel-setpoint-inc","OFF");
  execute.command("kachel-setpoint-dec","off");
end




On Sunday, May 14, 2017 at 7:05:37 PM UTC+2, ReneS wrote:
Reply all
Reply to author
Forward
0 new messages