Give value in rules for command

343 views
Skip to first unread message

Richard van der Wulp

unread,
Feb 23, 2017, 4:44:12 AM2/23/17
to OpenRemote
HI all,

Is it possible to set a value within rules to execute a command ?
So can I give a certain value to the kind of Command and/or the value with that command.

I work with velbus. So you can have a command ON or a command OF.
Can I give a value within rules to set that command.
I dont think so, because openremote designer will not let me let that field blank in Designer.

Or

can I set a value with that command. With velbus you can set the channel, or with a dimmer a percentage.
So, I saw some examples with an additional value in the command. Example:

rule "LED"
when
  Event( source == "LED1STATUS", value == "on" )
then
  execute.command( "LED2" , "2" );
end

But that does not seem to work for me.
I see some examples with $param in the designer command, but that doesnt work with me either.
Those examples ar primarily for HTTP commands.


Can you give a value within rules for a command and do you have an example?

Thank you.

Stuart Hanlon

unread,
Feb 23, 2017, 5:28:20 AM2/23/17
to OpenRemote
Hello


You've got a good question there :-)


Okay, so some basics.

The only commands within the Velbus Protocol to support ${param} are dimmer_level & memo_text (Although the ${param} isn't strictly required, you can put any value in and it will be replaced with the dynamic value)

So a rule with..


then
execute.command( "dimmer01" , 25 );
end

Or

rule "Link button event to memo text"
when
Event( source == "A button Sensor", value == "pressed" )
then
execute.command( "memo_text" ,"Hello world:100");

end


Would work.


If I'm reading your question correctly, you just need a tiny tweak to your current rule to get the result you need.

You will need to set an On command and an OFF command for what you're trying to control...


rule "Link two things"
when
Event( source == "A Sensor", value == "on" )
then
execute.command( "Something ON" );

else
execute.command( "Something OFF" );

end


I have something similar running for a client that watches a Velbus glass panel thermostat (heater status) and switches an IP (http addressable) relay.


rule "Sync VMBGP2 HEATER status"
when
Event( source == "GP2-Heater-Status", value == "pressed" )
then
execute.command( "IP_Relay_Ch1_ON" );

else
execute.command( "IP_Relay_Ch1_OFF" );

end


You could take it a stage further and use a regex query to monitor more than 1 sensor and match part of that sensor name to the executed commands.


For example, you might have 10 sensors

1_sensor
2_sensor
3_sensor

Etc

And 10 pairs of commands

1_ON
1_OFF

2_ON
2_OFF

Etc


To save you writing 10 rules, a single rule would match the unique part of the sensor name to the unique part of the command names.

We have this running where multiple new Velbus thermostats are linked to existing heating control relays.


Does that help you?


Best wishes,

Stuart

Richard van der Wulp

unread,
Feb 23, 2017, 7:04:02 AM2/23/17
to OpenRemote
HI Stuart

That certainly helps me to understand.
The dimmer is indeed the one I was working on now, but I saw the opportunities for other rules.

For the dimmer I tried to do it with:

then
  execute.command( "LED2" , 25 );
end

But the rules use the Original value of the command. As you say, it doesnt matter to put $param instead,
And I can understand that, because the value vor Velbus must be the channel and than the dimmerpercentage. So    1:25
But I cant use   the   :  sign, because it gives an error.

So does that mean that this option is of the table for openremote/velbus?
And I have to got the option B?

Thanks




Op donderdag 23 februari 2017 11:28:20 UTC+1 schreef Stuart Hanlon:

Stuart Hanlon

unread,
Feb 23, 2017, 7:26:40 AM2/23/17
to OpenRemote
Arrh...


I see what you're getting at :-)


The only variable that can be inserted into the dimmer_level command is the dimmer level, not the channel number AND dimmer level.


So if I'm understanding correctly, you want to define the channel number within rules.

The only way to do that is to create multiple commands with a command name with a unique identifier.


Then use something clever in rules to define the command you want, then set a level for that command.


I'll dig out an example rule for you to look at.

Richard van der Wulp

unread,
Feb 23, 2017, 7:33:28 AM2/23/17
to OpenRemote
thanks, any examples are welcome

I do not want to define the channel number also
but I think it is required in the combination with openremote and velbus. As the value must be channel:percentage for it to work, like  1:25
So if there is a loophole

Op donderdag 23 februari 2017 13:26:40 UTC+1 schreef Stuart Hanlon:

Stuart Hanlon

unread,
Feb 23, 2017, 9:14:26 AM2/23/17
to OpenRemote
Phew, I see the issue... (I think)

So, in your device command you 'must enter something'.


So, I suggest you put.

1:50

So that if the command were to be used with a button it would set the dimmer level to 50%


Also, if the command is used within a slider, the new slider value will overwrite the 50%.


Likewise in a rule the new value from the rule will overwrite the 50%


So this simple rule should work :-

rule "Link two things"
when
Event( source == "A Sensor", value == "on" )
then

execute.command( "Dim to a level", 25 );

//else
// execute.command( "Something OFF" );

end

Richard Turner created a rule that seperates an RGB HEX colour value In-Memory command status (where the value is set by another In-Memory command linked to a colour picker UI element) into 3 seperate % values for use with 3 Velbus dimmer channels.


In-Memory command "186_RGB_Colour_Picker_Set" > linked to Colour Picker UI element

In-Memory status command linked to Sensor "186_RGB_Colour_Picker_Status"

3 seperate Velbus dimmer_level commands

186-4DC-Ch1R-Dim100
186-4DC-Ch2G-Dim100
186-4DC-Ch3B-Dim100


Does this help ?

rule "186-RGB To 3 Channels" when


// SOURCE here is an In-Memory status sensor that shows the RGB HEX value from a colour picker "186_RGB_Colour_Picker_Status"

$evt:Event( source == "186_RGB_Colour_Picker_Status", $val : value)

then

String valStr = $val.toString();

if (valStr != null && valStr.length() == 6) {

// Split a single 6 digit HEX RGB colour value into 3 seperate RGB values (in HEX format)
String rStr = valStr.substring(0,2);
String gStr = valStr.substring(2,4);
String bStr = valStr.substring(4,6);

// Convert 2 digit HEX values into DEC int values
Integer r = Integer.parseInt(rStr, 16);
Integer g = Integer.parseInt(gStr, 16);
Integer b = Integer.parseInt(bStr, 16);

// Convert 0-255 value to 0-100 whole number
r = (int)Math.round(((double)r / 255d) * 100);
g = (int)Math.round(((double)g / 255d) * 100);
b = (int)Math.round(((double)b / 255d) * 100);

execute.command( "Red_Set", r.toString() );. // In-Memory command used as a reference in the UI for debugging
execute.command( "186-4DC-Ch1R-Dim100", r.toString() ); // A channel of a VMB4DC that is used to drive the Red elements of an RGB fixture


execute.command( "Green_Set", g.toString() );. // In-Memory command used as a reference in the UI for debugging
execute.command( "186-4DC-Ch2G-Dim100", g.toString() ); // A channel of a VMB4DC that is used to drive the Green elements of an RGB fixture


execute.command( "Blue_Set", b.toString() ); // In-Memory command used as a reference in the UI for debugging
execute.command( "186-4DC-Ch3B-Dim100", b.toString() ); // A channel of a VMB4DC that is used to drive the Blue elements of an RGB fixture
}
end


Michal took this a step further when I started playing around with the HTTP driven DMX device by creating random HEX values to use asRGB strings.

Where a pulsing status is used to trigger the rule.
(Not the output state of an 'Interval Timer' relay channel in Velbus as this would give a constant state of "timer", I linked the interval timer relay channel to another relay (momentary action) so that the slave relay showed on and off states)

An interval timer in Rules might be a better option, but I wanted to be able to vary the interval pulse time in VelbusLink or use multiple actions wth different times.

This rule sees 1 trigger and creates 6 different RGB HEX values to be sent to 6 seperate SPi pixels, using the same single HTTP command to address the SPi / DMX adapter. Where the %{param} is used to (only) transfer the HEX value, the start pixel and end pixel information.

package org.openremote.controller.protocol;

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

import java.util.*;


rule "Ch5 slave interval timer"

when

Event( source == "01_VMB1RYNOS_ch5", value == "on" )

then

java.util.Random randomGenerator = new java.util.Random();

execute.command("DMX_Universal_Uni0",String.format("%06X", randomGenerator.nextInt(0x1000000)) + "&start=2&end=2");
execute.command("DMX_Universal_Uni0",String.format("%06X", randomGenerator.nextInt(0x1000000)) + "&start=3&end=3");
execute.command("DMX_Universal_Uni0",String.format("%06X", randomGenerator.nextInt(0x1000000)) + "&start=4&end=4");
execute.command("DMX_Universal_Uni0",String.format("%06X", randomGenerator.nextInt(0x1000000)) + "&start=5&end=5");
execute.command("DMX_Universal_Uni0",String.format("%06X", randomGenerator.nextInt(0x1000000)) + "&start=6&end=6");
execute.command("DMX_Universal_Uni0",String.format("%06X", randomGenerator.nextInt(0x1000000)) + "&start=7&end=7");


end


Stuart Hanlon

unread,
Feb 23, 2017, 9:26:44 AM2/23/17
to OpenRemote
Off topic a little, but this is a good example of a rule.


It uses a Regex to monitor multiple sensors with command names.


It extracts 2 unique elements in the sensor names and uses those to define which command is executed. ("Zone name" and "Time slot" from "Hall_Seditary_Status-query-01")


It also takes the time value from the sensor, adds 30 minutes and injects that new time value into the executed command.


(I'm not totally sure about how this dark magic works, but I'm very grateful that it does, it reduced 42 rules down to just one)


// Sync Seditary times to Active times with 30 minute offset

rule "Alarm Synchroniser"
when
$evt:Event(source matches "^.*_Seditary_Status-query-\\d+$", $source : source)
then
// The sensor value is the time of the seditary alarm as HH:MM
String strValue = $evt.getValue().toString();
String[] values = strValue.split(":");

if (values.length != 2) {
return;
}

int sensorNumber = 0;
int hours = 0;
int mins = 0;
String alarmPrefix = "";

try {
// Extract the number from the sensor name
Pattern p = Pattern.compile("^(.*)_Seditary_Status-query-(\\d+)$");
Matcher m = p.matcher($source);
m.matches();
alarmPrefix = m.group(1);
sensorNumber = new Integer(m.group(2));
hours = new Integer(values[0]);
mins = new Integer(values[1]);

// Add 30 mins to the time and set this as the time for the active alarm
mins += 30;
execute.command(alarmPrefix + "_Active_Time_Set_" + sensorNumber, hours + ":" + mins);

} catch (Exception e) {
System.out.println("############## Alarm synchroniser exception: " + e.getMessage() + " #################");
return;
}

end

Richard van der Wulp

unread,
Feb 25, 2017, 12:06:39 PM2/25/17
to OpenRemote
Well tried and some things and I am not yet there where I want to be.
I am still in a steep learning curve, so I all ask a follow up question.

This is working

rule "FF"
when
  Event( source == "Command1", value == "on" )
then
  execute.command( "DD" , 41 );
end

And this works:

rule "JJ"
when
  Event( source == "Command1", value == "on" )
then
  int number1 = 41;
  execute.command( "DD" , number1);
end


But know I want extract the temperature from sensor, make a calculation with it, and put it into this DD command
I looked at several posts within this and other forums, but i cant seem to find something that works

This is almost similar:

rule "Huidige temperatuur"
when
CustomState(source=="sensor temperatuur", $v: value)
then
double correctedValue1 = Double.parseDouble($v.toString()) - 32;
double correctedValue = (correctedValue1/9) * 5;
execute.command("VTEMP", String.format("%.1f \u2103", correctedValue));
execute.command("VTEMPer", String.format("%.1f ", correctedValue));
temp(String.format("%.1f ", correctedValue));
end


Or this:

rule "Range Event Command Execution"

when

$evt: Range ( source == "Display Volume", value == 100 )

then

execute.command ("TestMSG", $evt.getValue());

end


But when I try use these concepts for my rules, and I update my console, it gives errors like:
String and integer   or String and object van not be combined
Or that is not an event

What could be a rule to make this work?

Thank you

Richard


Op donderdag 23 februari 2017 15:26:44 UTC+1 schreef Stuart Hanlon:

Stuart Hanlon

unread,
Feb 25, 2017, 4:22:50 PM2/25/17
to OpenRemote
Hello Richard,

I'm really curious to know what you're attempting to do :-)

Michal's PID logic might be on a similar line?

I also think that you need some specialist help here :-)

With luck one of the magicians will step forward and help you to the next stage.


In the mean time, I'm working on a GitHub page with a list of sample rules.

https://github.com/openremote/Documentation/wiki/OpenRemote-Rules-examples---A-work-in-progress


One of the rules at the bottom extracts values, modifies them and injects the new value into a command.


I'll not say I'm even close to understanding this dark magic, so I can only wish you luck ;-)


Good luck.


Stuart

Michal Rutka

unread,
Feb 26, 2017, 1:37:28 AM2/26/17
to Richard van der Wulp, OpenRemote
Hi Richard,

Can you copy exact the error message which you get using the rule

rule "Huidige temperatuur"
when
CustomState(source=="sensor temperatuur", $v: value)
then
double correctedValue1 = Double.parseDouble($v.toString()) - 32;
double correctedValue = (correctedValue1/9) * 5;
execute.command("VTEMP", String.format("%.1f \u2103", correctedValue));
execute.command("VTEMPer", String.format("%.1f ", correctedValue));
temp(String.format("%.1f ", correctedValue));
end


Kind regards,
Michal Rutka
--
You received this message because you are subscribed to the Google Groups "OpenRemote" group.
To unsubscribe from this group and stop receiving emails from it, send an email to openremotecommu...@googlegroups.com.
Visit this group at https://groups.google.com/group/openremotecommunity.
To view this discussion on the web visit https://groups.google.com/d/msgid/openremotecommunity/82d081fd-6b3b-4725-93fc-fe5baf88b1e9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Richard van der Wulp

unread,
Feb 26, 2017, 8:50:04 AM2/26/17
to OpenRemote, rvd...@gmail.com
Thanks Michal and Stuart

The error I get with this exact rule:

rule "Huidige temperatuur"
when
CustomState(source=="TEMPkamerschuifpui", $v: value)

then
double correctedValue1 = Double.parseDouble($v.toString()) - 32;
double correctedValue = (correctedValue1/9) * 5;
execute.command("DD", String.format("%.1f \u2103", correctedValue));
end

Where the command DD is a Dimmer_level command of velbus, where you set the dimmer percentage.
And the sensor  TEMPkamerschuifpui gives the room temperature.
Than I get this error:

ERROR 2017-02-26 14:40:31,814 : Creating sensor failed. Error : The included command reference in a sensor (ID = 395429)
 is not an event producer (Command id : 395429, Type : 289)
 XML Element : <sensor xmlns="http://www.openremote.org" id="395429" name="DDS" type="custom">
      <include type="command" ref="289" />
    </sensor>
org.openremote.controller.exception.XMLParsingException: The included command reference in a sensor (ID = 395429) is not
 an event producer (Command id : 395429, Type : 289)


And Stuart. the github site is indeed what would be very very helpfull for beginners like me. And what new people wo are thinking to use openremote will help to decide. I hope you continue that effort.

Thanks
Richard



Op zondag 26 februari 2017 07:37:28 UTC+1 schreef Michal Rutka:
To unsubscribe from this group and stop receiving emails from it, send an email to openremotecommunity+unsub...@googlegroups.com.

Stuart Hanlon

unread,
Feb 26, 2017, 10:21:15 AM2/26/17
to OpenRemote
Hello chaps,

I'll keep adding rules and explanations to that GitHub page for as long as magicians like Michal and Richard keep dreaming them up :-)


Now, I'm a little curious what you're trying to achieve with this rule.


Are you getting the room temperature from a Velbus glass panel?

Cheers
Stuart

Michal Rutka

unread,
Mar 2, 2017, 8:42:07 AM3/2/17
to OpenRemote, rvd...@gmail.com
This error message is complaining about the command which is linked with the sensor. Moreover, it is about a different sensor than the rule uses. The rule is checking "TEMPkamerschuifpui" sensor and the error message is complaining about name="DDS". Can you check this sensor and see how the command is defined? It might be, that if this is a pooling command you forgot to include the pooling interval parameter?

Kind regards,
Michal

Igoris Binkis

unread,
Mar 9, 2017, 4:39:44 PM3/9/17
to OpenRemote
Hi guys,
I came with similar question. I need to make 3 thermostats with change target temperature ability. I'm using rules from Example Home, but it is quite complicated to me to understand, so I'll need some of your help. I just want to make sure I'm doing it right. As I understand, I need to create 3 In-Memory Virtual devices, make commands to Increase On, Decrease On and Status. To setup target temp start point I'm using this part:
rule "Initialise"
salience
10
then
  execute
.command("TargetTemp",_ReadFromFile("TargetTemp","20.0\u00B0"));
end

rule
"Store values"
timer
(int: 2s)
when
(
 
Event($s:source=="TargetTemp", $v:value, eval(!_ReadFromFile($s,"").equals($v))) ||
)
then                                                                                
  log
($s+" old value: "+_ReadFromFile($s,"||")+"; new value:"+$v.toString());                                        
  _WriteToFile
($s, $v);                                                            
end


To increase or decrease value I'm using that (respectively):
rule "Target Temp Inc"
  timer
(int:300ms)
when
 
Event(source == "TargetTemp", $v: value, eval(_GetTemp(value) < 30))
 
Event(source == "TargetTempInc" , value == "ON")
then
  execute
.command("TargetTempInc","off");
  execute
.command("TargetTempDec","OFF");
  execute
.command("TargetTemp", _ShiftTemp($v.toString(), 0.5));
end

And finaly to activate thermosat:
rule "Thermostat On"
when
 
Event(source=="TargetTemp", $v: value)
 
Event(source=="Temp1", value==$v)
then
 
String s = $v.toString();
 
Double t = java.lang.Math.max(16.0, Double.parseDouble(s.substring(0,s.length()-1))+0.3); // 0.3 hysteresis
  execute
.command("Thermostat", "ON" );
end


Is it correct?

Michal Rutka

unread,
Mar 10, 2017, 1:47:43 AM3/10/17
to OpenRemote
I don't understand the last part about activating the thermostat. What it should do? You are calculating something there but exacted only simple ON command ignoring the calculation results.
Message has been deleted

Igoris Binkis

unread,
Mar 10, 2017, 7:03:49 AM3/10/17
to OpenRemote
The last part is when actual temperature meets target temperature+added hysteresis and activates thermostat. How should it look then? Cause these rules are quite complicated for me, and I don't really know how it suppose to be

Michal Rutka

unread,
Mar 11, 2017, 9:27:45 AM3/11/17
to openremot...@googlegroups.com
If you want to meet temperature and add hysteresis then it should look like

rule "Thermostat On"
when
  
Event(source=="TargetTemp", $v: value)

  
Event(source=="Temp1", eval(_GetTemp($v)-_GetTemp(value)>=0.3)) // 0.3 hysteresis
then

  execute.command("Thermostat", "ON" );
end

Igoris Binkis

unread,
Mar 13, 2017, 3:52:41 PM3/13/17
to OpenRemote
I've deployed my rules, but looks like they do not work, as In-Memory sensors shows 0, and I'm unable to change the value. The log file is very long and says:
ERROR 2017-03-13 19:41:36,909 : Error in rule definition 'modeler_rules.drl' : wrong class format
java
.lang.RuntimeException: wrong class format

ERROR 2017-03-13 19:41:36,931 : Cannot start event processor 'Drools Rule Engine' : java.lang.ClassNotFoundException: org/openremote/controller/protocol/Rule_Target_Temp_Inc_0DefaultConsequenceInvoker
org
.drools.RuntimeDroolsException: java.lang.ClassNotFoundException: org/openremote/controller/protocol/Rule_Target_Temp_Inc_0DefaultConsequenceInvoker

TRACE 2017-03-13 19:48:49,831 : Unable to retrieve controller identity
org
.openremote.controller.exception.ConnectionException: The required password for user 'username' was not found. Password manager error : Error accessing users password: {0}
 at org
.openremote.controller.service.BeehiveCommandCheckService$BeehiveCommandChecker.connect(Unknown Source)
 what does it mean?

Michal Rutka

unread,
Mar 14, 2017, 5:24:29 AM3/14/17
to OpenRemote
It means that you are using Java 8 with controller 2.5. Either decrease Java version to 6 or 7 or use the controller beta version 2.6.
Message has been deleted
Message has been deleted

Igoris Binkis

unread,
Mar 14, 2017, 4:54:01 PM3/14/17
to OpenRemote

I've updated the controller to version 2.6, errors seemed to be gone by now, only few left about remote connection and user credentials or so. But In-Memory sensor still shows 0 and it is unable to change its value. Can someone please check through my rules file, to check what is wrong is, as I believe there is something wrong with rules. And also are my In-Memory commands set correctly?

modeler_rules.drl

Michal Rutka

unread,
Mar 15, 2017, 7:23:02 AM3/15/17
to OpenRemote
1. In the rules you are watching for "ON" string while in commands you generate "on" string. You can either change command definition or rules to have the same case strings.
2. You've put everything in one address "settempa", however very command should have different address, for example "settempa", "settempainc" and "settempadec".

Make above changes and it should work, in case of troubles look in boot.log and rules/drools.log

Igoris Binkis

unread,
Mar 15, 2017, 3:47:46 PM3/15/17
to OpenRemote
Boot log still is having messages about "Unable to retrieve controller identity", but I don't think it matters. Drools log says:

DEBUG 2017-03-15 19:35:25,975 (Drools): File read error: TargetTemp1
DEBUG 2017-03-15 19:35:26,134 (Drools): Inserted new event source "TargetTemp2"
DEBUG 2017-03-15 19:35:26,135 (Drools): Fact count changed from 9 to 1 on "TargetTemp2"
DEBUG 2017-03-15 19:35:26,140 (Drools): Inserted new event source "TargetTemp3"
DEBUG 2017-03-15 19:35:26,141 (Drools): Fact count changed from 1 to 2 on "TargetTemp3"
DEBUG 2017-03-15 19:35:26,146 (Drools): Inserted new event source "Pin3Status"
DEBUG 2017-03-15 19:35:26,147 (Drools): Fact count changed from 2 to 3 on "Pin3Status"
DEBUG 2017-03-15 19:35:26,149 (Drools): Inserted new event source "TargetTemp1"
DEBUG 2017-03-15 19:35:26,149 (Drools): Fact count changed from 3 to 4 on "TargetTemp1"
DEBUG 2017-03-15 19:35:26,184 (Drools): Inserted new event source "Pin0Status"
DEBUG 2017-03-15 19:35:26,184 (Drools): Fact count changed from 4 to 5 on "Pin0Status"
DEBUG 2017-03-15 19:35:26,185 (Drools): Inserted new event source "Pin2Status"
DEBUG 2017-03-15 19:35:26,186 (Drools): Fact count changed from 5 to 6 on "Pin2Status"
DEBUG 2017-03-15 19:35:26,935 (Drools): Inserted new event source "Temp2"
DEBUG 2017-03-15 19:35:26,936 (Drools): Fact count changed from 6 to 7 on "Temp2"
DEBUG 2017-03-15 19:35:26,975 (Drools): Inserted new event source "Temp1"
DEBUG 2017-03-15 19:35:26,976 (Drools): Fact count changed from 7 to 8 on "Temp1"
DEBUG 2017-03-15 19:35:27,018 (Drools): Inserted new event source "Temp3"
DEBUG 2017-03-15 19:35:27,018 (Drools): Fact count changed from 8 to 9 on "Temp3"

So I guess it is something wrong with TargetTemp1 "status" command and putting virtual value into it?

Michal Rutka

unread,
Mar 15, 2017, 5:04:03 PM3/15/17
to OpenRemote
In drools.log I don't see any rule executed, not even the initialization one. Therefore I conclude that there must be some errors in the drl file, which you should spot in the boot.log.

Igoris Binkis

unread,
Mar 15, 2017, 5:42:49 PM3/15/17
to OpenRemote
These are boot.log and drools.log files, I cannot spot anything in them, except that "Unable to retrieve controller identity" stuff. May it cause problems?
boot.log
drools.log

Michal Rutka

unread,
Mar 15, 2017, 7:03:03 PM3/15/17
to OpenRemote
This time the initialize rule executes. So everything seems OK. What is the problem then? You haven't press increase/decrease buttons because they are not logged.

Igoris Binkis

unread,
Mar 16, 2017, 5:36:49 PM3/16/17
to OpenRemote
Hi Michal,
Thank you so much for helping me. So, finally I've got TargetTemp value to show, but I still cannot change it. And the log file does not show any buttons pressed. I've tried other rules I found on the forum archive but they do not work either. I'm not sure, but I thing the problem is in this code and somehow it depends on the string format. Am I correct? And if yes, how to alter the code properly? 

rule "Initialise"
salience
10
then

  execute
.command("TargetTemp1",_ReadFromFile("TargetTemp1","20.0"));
end


function void _WriteToFile(String fn, Object o){
 
String vl = o.toString();
 
PrintWriter writer = new PrintWriter(fn+".txt", "UTF-8");
  writer
.println(vl);
  writer
.close();
}


function String _ReadFromFile(String fn, String dft){
 
String result = dft;
 
try{
   
BufferedReader fr = new BufferedReader(new InputStreamReader(new FileInputStream(fn+".txt"), "UTF-8"));
   
try{
      result
= fr.readLine();
   
} finally {
      fr
.close();
   
}
 
} catch (IOException e) {
   
// e.printStackTrace();
    log
("File read error: "+fn);
 
}
 
return(result);
}


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",t));
 
} catch (NumberFormatException e) {
   
return("0.0");

 
}
}




rule
"Target Temp Inc"
  timer
(int:300ms)
when

 
Event(source == "TargetTemp1Inc" , value == "on")
 
Event(source == "TargetTemp1", $v: value)
then
  execute
.command("TargetTemp1Inc","off");
  execute
.command("TargetTemp1", _ShiftTemp($v.toString(), 0.1));
end


rule
"Target Temp Dec"
  timer
(int:300ms)
when
 
Event(source == "TargetTemp1Dec" , value == "on")  
 
Event(source == "TargetTemp1", $v: value)
then
  execute
.command("TargetTemp1Dec","off");
  execute
.command("TargetTemp1", _ShiftTemp($v.toString(), -0.1));

And BTW, in modeler there should be buttons, not switches? Right?

Michal Rutka

unread,
Mar 16, 2017, 6:17:33 PM3/16/17
to OpenRemote
You need to define sensors in the designer for both TargetTemp1Dec an Inc. they can be of type custom and as command just use the same name, i.e. targetTemp1Dec and Inc.
Rules are triggered by sensors on LHS therefore you must to declare those sensors in the designer.

Igoris Binkis

unread,
Mar 17, 2017, 10:06:30 AM3/17/17
to OpenRemote
Finally I can change the value, but it changes kinda strange way - increases to value.1 only, and decreases by 1.0. Rules log says about error reading TargetTemp files.
drools.log
Message has been deleted
Message has been deleted

Igoris Binkis

unread,
Mar 17, 2017, 2:21:13 PM3/17/17
to OpenRemote
For some reason I think, that problem is in this code, as I haven't changed it from Example Home, and there the degree sign is being used:
On Thursday, 16 March 2017 22:17:33 UTC, Michal Rutka wrote:

Michal Rutka

unread,
Mar 17, 2017, 7:03:27 PM3/17/17
to OpenRemote
You've copied functions which work for temperatures including degree character while you are not using degree symbol. You need to adopt the code. In short you don't need to call _ShiftTemp() function because simple + and - will be enough.
Secondly, strange you are using mixed notations for floats, one as 17.9 and other as 17,9 (one with dot and one with comas). Seems like mixed coding. You need to rectify it.

Richard van der Wulp

unread,
Apr 12, 2017, 11:58:51 AM4/12/17
to OpenRemote
Hello

I'm back. The last thing Michal said about my problems, where that the error I had were not related to my specific problem. So I knew that was the time to get a more structural approach. So I re-did all of my rules, command, sensors, and so on, in a more structural way.
So that is done.
I also updated my Java Velbus version to 1.3. And that worked without a problem. Although my only benefit would that my outdoor temp sensor would now work, and it doesnt. But that is a hardware problem and not a software problem.

But back to the issue. I would like to read the temperature, recalculate it, and send the calculated number to a dimmer. The idea (Stuart asked me) is that the temperature of the water in my floorheating will be depended on the outdoor and inside temperature. That is kind of normal in the newest heating systems, but here we have to program it ourselves.

In one of the previous post it works to get a value via rules in my dimmer.
And I can also retrieve a number from my temperaturemeters.

But I am stuck to get the one to the other.

My current rule is:

rule "Huidige temperatuur"
when
   CustomState(source=="010_00_SE_TST_WnkmrSchuifpui", $v: value)
 then
     double correctedValue1 = Double.parseDouble($v.toString());
//     double correctedValue = (correctedValue1/1) * 5;
//     execute.command("STC", String.format("%.1f ", correctedValue));
end

And it is this line that gives the first error:
     double correctedValue1 = Double.parseDouble($v.toString());

Attached you can find the error in the log of the rules.

(2)
An unknown related problem In the velbus logs it says:
"
WARN 2017-04-12 15:09:19,511 (Velbus): Unkown command '246' will be ignored
WARN 2017-04-12 15:09:24,261 (Velbus): Unkown command '245' will be ignored
"
How do I know which command is which?


Thanks for

Richard







Op zaterdag 18 maart 2017 00:03:27 UTC+1 schreef Michal Rutka:
Drools error.txt

Stuart Hanlon

unread,
Apr 12, 2017, 4:48:40 PM4/12/17
to OpenRemote
Hello Richard,


I've spoken in depth to the programmer who takes care of the Velbus implementation in OpenRemote.

He message is that the error / warning messages in the Velbus log aren't Antony to worry about.

In short, any Velbus packets that aren't understood / needed by OpenRemote will appear in that log as a warning, not an error, just a warning.

I've been seeing those exact same warnings in a few installations and I'm sure they aren't anything to worry about.


So I suspect your issue lays in the rules somewhere.


May I ask which bit of Velbus hardware you're using to pick up the outside temperature?


Cheers,

Stuart

Richard van der Wulp

unread,
Apr 13, 2017, 2:14:36 PM4/13/17
to OpenRemote
Hi Stuart

Thank you for the quick reply.

Just to be clear. The problem after (2) in the previous message is different from the problem before the (2). You go into detail about problem after the (2)

To answer that one. I use the VMB1TS which can now be used, now I used the update 1.3 of velbus. So thank you for the reply that I do not have to worry about the two errors ( mentioned after the (2)) .
It is a hardware problem, because when I read the temperature from the software of velbus itself, it says 0,0 degrees. Which is not correct. I have to fix that separately. Maybe a wire is faulty.

If you have also an idea about the problem before the (2), I would be very interesting. It is a problem in the rules I think. Is it maybe a problem about the comma "," and the dot "." ?

Hope to hear from you

Richard

Stuart Hanlon

unread,
Apr 13, 2017, 7:46:56 PM4/13/17
to OpenRemote
Hi Richard,

Thanks for the update.


I'm not the man to help with rules stuff,, there are far better people than me ;-)

I can collate and alter, but you're asking for something I haven't seen before :-(


However, the issue with the lack of data from the VMB1TS ( and similar errors ) might be a really easy fix.


Have you checked the bus voltage at the VMB1TS?

You might find that it's too low.


Just a thought, have you considered using the thermostat alarm triggers within the VMB1TS to set the underfloor flow temperatures?

Two users on the Velbus forum posed a similar question, instead they​ wanted to set fan speeds.

https://forum.velbus.eu/t/0-10v-sturing-verwarming/14473/5


The trick is to setup multiple thermostat alarms, each with a set point and an atmospheric dim value.


I hope this helps.


Good luck,

Stuart

Stuart Hanlon

unread,
Apr 13, 2017, 7:49:29 PM4/13/17
to OpenRemote
This example VLP file might help you
Pump to dimmer V4 - My prefered solution.vlp

Michal Rutka

unread,
Apr 14, 2017, 5:53:58 AM4/14/17
to OpenRemote
Hi Richard,

the error is indeed caused by a wrong decimal number format. It should be with a dot, not a coma. Usually you can change it by country setting in your OS. I personally select country code as US which gives me less headache ;)

Richard van der Wulp

unread,
Jul 7, 2017, 11:41:22 AM7/7/17
to OpenRemote
Hi Michal

I am back.

I changed the OS to US version. Good thinking.

The result was a new error, which I could not seem to solve.

Rule:

rule "Huidige temperatuur" 
when
   CustomState(source=="010_00_SE_TST_WnkmrSchuifpui",$v: value)

 then
     double correctedValue1 = Double.parseDouble($v.toString());
     double correctedValue = (correctedValue1/1) * 1;

     execute.command("STC", String.format("%.1f ", correctedValue));
end

And the problems is:

ERROR 2017-07-07 17:15:08,123 : [ERR 101] Line 18:1 no viable alternative at input ''
ERROR 2017-07-07 17:15:08,154 : [ERR 101] Line 18:3 no viable alternative at input ''
ERROR 2017-07-07 17:15:08,154 : [ERR 101] Line 19:1 no viable alternative at input ''
ERROR 2017-07-07 17:15:08,154 : [ERR 101] Line 20:1 no viable alternative at input ''
ERROR 2017-07-07 17:15:08,154 : [ERR 101] Line 20:3 no viable alternative at input ''
ERROR 2017-07-07 17:15:08,169 : [ERR 101] Line 20:5 no viable alternative at input ''
ERROR 2017-07-07 17:15:08,201 : [ERR 101] Line 20:7 no viable alternative at input ''
ERROR 2017-07-07 17:15:08,232 : [ERR 101] Line 21:1 no viable alternative at input ''
ERROR 2017-07-07 17:15:08,232 : [ERR 101] Line 21:3 no viable alternative at input ''
ERROR 2017-07-07 17:15:08,232 : [ERR 101] Line 21:5 no viable alternative at input ''
ERROR 2017-07-07 17:15:08,232 : [ERR 101] Line 21:7 no viable alternative at input ''
ERROR 2017-07-07 17:15:08,248 : [ERR 101] Line 22:1 no viable alternative at input ''
ERROR 2017-07-07 17:15:08,263 : [ERR 101] Line 22:3 no viable alternative at input ''
ERROR 2017-07-07 17:15:08,279 : [ERR 101] Line 22:5 no viable alternative at input ''
ERROR 2017-07-07 17:15:08,279 : [ERR 101] Line 22:7 no viable alternative at input ''
ERROR 2017-07-07 17:15:08,310 : [ERR 102] Line 18:2 mismatched input 'Â' in rule "Huidige temperatuur"

Where the special A in the last line in the PC screen is a lower case letter T.

Any suggestions

Richard

Op vrijdag 14 april 2017 11:53:58 UTC+2 schreef Michal Rutka:
boot.log

Michal Rutka

unread,
Jul 7, 2017, 11:55:35 AM7/7/17
to OpenRemote
It seems that coding of your 'drl' file got screwed. The best way to proceed it to make sure that it is indeed pure ASCII text, without any strange codepages.

Richard van der Wulp

unread,
Jul 9, 2017, 6:53:46 AM7/9/17
to OpenRemote
Hi Michal

I started clean, but I found out that wasnt the problem. With the change it is somehow very critical on spaces in the rules. In all the older rules it still does not have a problem. But for this rule I am working, it does have problems. So for I know I deleted as much spaces as possible.
And that works fine.

Now I have to get the output from the temperaturesensor:  24.0
To a number without decimals. So a number between 0 en 100. Thus   24   instead of   24.0


For now, this rule works:

rule "AAA"
when
 CustomState (source == "010_00_SE_TST_WnkmrSchuifpui", $v : value);

then
 double correctedValue1 = Double.parseDouble($v.toString());
 double correctedValue = (correctedValue1/1) * 1;
// execute.command("250_02_C_DL_PM",String.format("%.1f",correctedValue));
 System.out.println(correctedValue);
end

The print result is 
24.0

But if also use this command in the rule:
 execute.command("250_02_C_DL_PM",String.format("%.1f",correctedValue));

Whereas "250_02_C_DL_PM" is a command for a dimmer. ( Earlier in this discussion I already found out how to alter the dimmer via this rule.)

With that extra line in the rule,  I get errors, with this:
ERROR 2017-07-09 12:40:47,046 : Invalid dynamic value supplied
java.lang.NumberFormatException: For input string: "24.0"

So, I should change the format. But somehow I don't get to round off the number to a number without a decimal in a way that the system works.

Any suggestions?

Richard


Op vrijdag 7 juli 2017 17:55:35 UTC+2 schreef Michal Rutka:

Stuart Hanlon

unread,
Jul 9, 2017, 8:16:20 AM7/9/17
to OpenRemote
Hi Richard.

If you're using a Velbus sensor, it's as simple as using a level sensor, rather than a custom one.

From my experience, the level sensor can only handle round numbers.


I hope this helps you.

Best wishes,

Stuart

Richard van der Wulp

unread,
Jul 9, 2017, 1:42:24 PM7/9/17
to OpenRemote
Hi Stuart

It is a command and no sensor. So that isn't part of the problem. I just lack the skills to format 24.3 into a 24, without the decimal.
Thanks anyway

Richard

Op zondag 9 juli 2017 14:16:20 UTC+2 schreef Stuart Hanlon:

Michal Rutka

unread,
Jul 9, 2017, 2:21:10 PM7/9/17
to OpenRemote
There are few ways of doing this. Pehaps the simplest would be to write:
execute.command("250_02_C_DL_PM",String.format("%.0f",correctedValue));

Or

execute.command("250_02_C_DL_PM",String.format("%d",int(correctedValue)));

Richard van der Wulp

unread,
Jul 10, 2017, 1:50:12 PM7/10/17
to OpenRemote
Yeah.

The first one worked! 
Thank you very much

For reference, this works:

rule "AAA"
when
 CustomState (source == "010_00_SE_TST_WnkmrSchuifpui", $v : value);
then
 double correctedValue1 = Double.parseDouble($v.toString());
 double correctedValue = (correctedValue1/1) * 1;
 execute.command("250_02_C_DL_PM",String.format("%.0f",correctedValue));
 System.out.println(correctedValue);
end

where:
010_00_SE_TST_WnkmrSchuifpui       is a sensor of temperaturesensor of a velbus button
250_02_C_DL_PM                                is a dimmer_level command

I will continue to adjust it to really use it, but this is method to work with it.

Richard


Op zondag 9 juli 2017 20:21:10 UTC+2 schreef Michal Rutka:
Reply all
Reply to author
Forward
0 new messages